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

pandatool/src/flt/fltTransformRotateAboutEdge.cxx

Go to the documentation of this file.
00001 // Filename: fltTransformRotateAboutEdge.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 "fltTransformRotateAboutEdge.h"
00020 #include "fltRecordReader.h"
00021 #include "fltRecordWriter.h"
00022 
00023 TypeHandle FltTransformRotateAboutEdge::_type_handle;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: FltTransformRotateAboutEdge::Constructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 FltTransformRotateAboutEdge::
00031 FltTransformRotateAboutEdge(FltHeader *header) : FltTransformRecord(header) {
00032   _point_a.set(0.0, 0.0, 0.0);
00033   _point_b.set(1.0, 0.0, 0.0);
00034   _angle = 0.0;
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: FltTransformRotateAboutEdge::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 FltTransformRotateAboutEdge::
00044 set(const LPoint3d &point_a, const LPoint3d &point_b, float angle) {
00045   _point_a = point_a;
00046   _point_b = point_b;
00047   _angle = angle;
00048 
00049   recompute_matrix();
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: FltTransformRotateAboutEdge::get_point_a
00054 //       Access: Public
00055 //  Description:
00056 ////////////////////////////////////////////////////////////////////
00057 const LPoint3d &FltTransformRotateAboutEdge::
00058 get_point_a() const {
00059   return _point_a;
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: FltTransformRotateAboutEdge::get_point_b
00064 //       Access: Public
00065 //  Description:
00066 ////////////////////////////////////////////////////////////////////
00067 const LPoint3d &FltTransformRotateAboutEdge::
00068 get_point_b() const {
00069   return _point_b;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: FltTransformRotateAboutEdge::get_angle
00074 //       Access: Public
00075 //  Description: Returns the angle of rotation, in degrees
00076 //               counterclockwise about the axis as seen from point a.
00077 ////////////////////////////////////////////////////////////////////
00078 float FltTransformRotateAboutEdge::
00079 get_angle() const {
00080   return _angle;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: FltTransformRotateAboutEdge::recompute_matrix
00085 //       Access: Private
00086 //  Description:
00087 ////////////////////////////////////////////////////////////////////
00088 void FltTransformRotateAboutEdge::
00089 recompute_matrix() {
00090   if (_point_a == _point_b) {
00091     // Degenerate case.
00092     _matrix = LMatrix4d::ident_mat();
00093   } else {
00094     LVector3d axis = _point_b - _point_a;
00095     _matrix =
00096       LMatrix4d::translate_mat(-_point_a) *
00097       LMatrix4d::rotate_mat(_angle, normalize(axis), CS_zup_right) *
00098       LMatrix4d::translate_mat(_point_a);
00099   }
00100 }
00101 
00102 ////////////////////////////////////////////////////////////////////
00103 //     Function: FltTransformRotateAboutEdge::extract_record
00104 //       Access: Protected, Virtual
00105 //  Description: Fills in the information in this record based on the
00106 //               information given in the indicated datagram, whose
00107 //               opcode has already been read.  Returns true on
00108 //               success, false if the datagram is invalid.
00109 ////////////////////////////////////////////////////////////////////
00110 bool FltTransformRotateAboutEdge::
00111 extract_record(FltRecordReader &reader) {
00112   if (!FltTransformRecord::extract_record(reader)) {
00113     return false;
00114   }
00115 
00116   nassertr(reader.get_opcode() == FO_rotate_about_edge, false);
00117   DatagramIterator &iterator = reader.get_iterator();
00118 
00119   iterator.skip_bytes(4);   // Undocumented additional padding.
00120 
00121   _point_a[0] = iterator.get_be_float64();
00122   _point_a[1] = iterator.get_be_float64();
00123   _point_a[2] = iterator.get_be_float64();
00124   _point_b[0] = iterator.get_be_float64();
00125   _point_b[1] = iterator.get_be_float64();
00126   _point_b[2] = iterator.get_be_float64();
00127   _angle = iterator.get_be_float32();
00128 
00129   iterator.skip_bytes(4);   // Undocumented additional padding.
00130 
00131   recompute_matrix();
00132 
00133   check_remaining_size(iterator);
00134   return true;
00135 }
00136 
00137 ////////////////////////////////////////////////////////////////////
00138 //     Function: FltTransformRotateAboutEdge::build_record
00139 //       Access: Protected, Virtual
00140 //  Description: Fills up the current record on the FltRecordWriter with
00141 //               data for this record, but does not advance the
00142 //               writer.  Returns true on success, false if there is
00143 //               some error.
00144 ////////////////////////////////////////////////////////////////////
00145 bool FltTransformRotateAboutEdge::
00146 build_record(FltRecordWriter &writer) const {
00147   if (!FltTransformRecord::build_record(writer)) {
00148     return false;
00149   }
00150 
00151   writer.set_opcode(FO_rotate_about_edge);
00152   Datagram &datagram = writer.update_datagram();
00153 
00154   datagram.pad_bytes(4);   // Undocumented additional padding.
00155 
00156   datagram.add_be_float64(_point_a[0]);
00157   datagram.add_be_float64(_point_a[1]);
00158   datagram.add_be_float64(_point_a[2]);
00159   datagram.add_be_float64(_point_b[0]);
00160   datagram.add_be_float64(_point_b[1]);
00161   datagram.add_be_float64(_point_b[2]);
00162   datagram.add_be_float32(_angle);
00163 
00164   datagram.pad_bytes(4);   // Undocumented additional padding.
00165 
00166   return true;
00167 }
00168 

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