Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/flt/fltTransformRotateAboutPoint.cxx

Go to the documentation of this file.
00001 // Filename: fltTransformRotateAboutPoint.cxx
00002 // Created by:  drose (30Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "fltTransformRotateAboutPoint.h"
00020 #include "fltRecordReader.h"
00021 #include "fltRecordWriter.h"
00022 
00023 TypeHandle FltTransformRotateAboutPoint::_type_handle;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: FltTransformRotateAboutPoint::Constructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 FltTransformRotateAboutPoint::
00031 FltTransformRotateAboutPoint(FltHeader *header) : FltTransformRecord(header) {
00032   _center.set(0.0, 0.0, 0.0);
00033   _axis.set(1.0, 0.0, 0.0);
00034   _angle = 0.0;
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: FltTransformRotateAboutPoint::set
00039 //       Access: Public
00040 //  Description: Defines the rotation.  The angle is given in degrees,
00041 //               counterclockwise about the axis as seen from point a.
00042 ////////////////////////////////////////////////////////////////////
00043 void FltTransformRotateAboutPoint::
00044 set(const LPoint3d &center, const LVector3f &axis, float angle) {
00045   _center = center;
00046   _axis = axis;
00047   _angle = angle;
00048 
00049   recompute_matrix();
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: FltTransformRotateAboutPoint::get_center
00054 //       Access: Public
00055 //  Description:
00056 ////////////////////////////////////////////////////////////////////
00057 const LPoint3d &FltTransformRotateAboutPoint::
00058 get_center() const {
00059   return _center;
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: FltTransformRotateAboutPoint::get_axis
00064 //       Access: Public
00065 //  Description:
00066 ////////////////////////////////////////////////////////////////////
00067 const LVector3f &FltTransformRotateAboutPoint::
00068 get_axis() const {
00069   return _axis;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: FltTransformRotateAboutPoint::get_angle
00074 //       Access: Public
00075 //  Description: Returns the angle of rotation, in degrees
00076 //               counterclockwise about the axis.
00077 ////////////////////////////////////////////////////////////////////
00078 float FltTransformRotateAboutPoint::
00079 get_angle() const {
00080   return _angle;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: FltTransformRotateAboutPoint::recompute_matrix
00085 //       Access: Private
00086 //  Description:
00087 ////////////////////////////////////////////////////////////////////
00088 void FltTransformRotateAboutPoint::
00089 recompute_matrix() {
00090   if (_axis == LVector3f::zero()) {
00091     // Degenerate case.
00092     _matrix = LMatrix4d::ident_mat();
00093   } else {
00094     LVector3d axis = LCAST(double, _axis);
00095 
00096     _matrix =
00097       LMatrix4d::translate_mat(-_center) *
00098       LMatrix4d::rotate_mat(_angle, axis, CS_zup_right) *
00099       LMatrix4d::translate_mat(_center);
00100   }
00101 }
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: FltTransformRotateAboutPoint::extract_record
00105 //       Access: Protected, Virtual
00106 //  Description: Fills in the information in this record based on the
00107 //               information given in the indicated datagram, whose
00108 //               opcode has already been read.  Returns true on
00109 //               success, false if the datagram is invalid.
00110 ////////////////////////////////////////////////////////////////////
00111 bool FltTransformRotateAboutPoint::
00112 extract_record(FltRecordReader &reader) {
00113   if (!FltTransformRecord::extract_record(reader)) {
00114     return false;
00115   }
00116 
00117   nassertr(reader.get_opcode() == FO_rotate_about_point, false);
00118   DatagramIterator &iterator = reader.get_iterator();
00119 
00120   iterator.skip_bytes(4);   // Undocumented additional padding.
00121 
00122   _center[0] = iterator.get_be_float64();
00123   _center[1] = iterator.get_be_float64();
00124   _center[2] = iterator.get_be_float64();
00125   _axis[0] = iterator.get_be_float32();
00126   _axis[1] = iterator.get_be_float32();
00127   _axis[2] = iterator.get_be_float32();
00128   _angle = iterator.get_be_float32();
00129 
00130   recompute_matrix();
00131 
00132   check_remaining_size(iterator);
00133   return true;
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: FltTransformRotateAboutPoint::build_record
00138 //       Access: Protected, Virtual
00139 //  Description: Fills up the current record on the FltRecordWriter with
00140 //               data for this record, but does not advance the
00141 //               writer.  Returns true on success, false if there is
00142 //               some error.
00143 ////////////////////////////////////////////////////////////////////
00144 bool FltTransformRotateAboutPoint::
00145 build_record(FltRecordWriter &writer) const {
00146   if (!FltTransformRecord::build_record(writer)) {
00147     return false;
00148   }
00149 
00150   writer.set_opcode(FO_rotate_about_point);
00151   Datagram &datagram = writer.update_datagram();
00152 
00153   datagram.pad_bytes(4);   // Undocumented additional padding.
00154 
00155   datagram.add_be_float64(_center[0]);
00156   datagram.add_be_float64(_center[1]);
00157   datagram.add_be_float64(_center[2]);
00158   datagram.add_be_float32(_axis[0]);
00159   datagram.add_be_float32(_axis[1]);
00160   datagram.add_be_float32(_axis[2]);
00161   datagram.add_be_float32(_angle);
00162 
00163   return true;
00164 }
00165 

Generated on Fri May 2 03:19:42 2003 for Panda-Tool by doxygen1.3