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

pandatool/src/flt/fltTransformPut.cxx

Go to the documentation of this file.
00001 // Filename: fltTransformPut.cxx
00002 // Created by:  drose (29Aug00)
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 "fltTransformPut.h"
00020 #include "fltRecordReader.h"
00021 #include "fltRecordWriter.h"
00022 
00023 #include <look_at.h>
00024 
00025 TypeHandle FltTransformPut::_type_handle;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: FltTransformPut::Constructor
00029 //       Access: Public
00030 //  Description:
00031 ////////////////////////////////////////////////////////////////////
00032 FltTransformPut::
00033 FltTransformPut(FltHeader *header) : FltTransformRecord(header) {
00034   _from_origin.set(0.0, 0.0, 0.0);
00035   _from_align.set(1.0, 0.0, 0.0);
00036   _from_track.set(1.0, 0.0, 0.0);
00037   _to_origin.set(0.0, 0.0, 0.0);
00038   _to_align.set(1.0, 0.0, 0.0);
00039   _to_track.set(1.0, 0.0, 0.0);
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: FltTransformPut::set
00044 //       Access: Public
00045 //  Description: Defines the put explicitly.  The transformation will
00046 //               map the three "from" points to the corresponding
00047 //               three "to" points.
00048 ////////////////////////////////////////////////////////////////////
00049 void FltTransformPut::
00050 set(const LPoint3d &from_origin, const LPoint3d &from_align,
00051     const LPoint3d &from_track,
00052     const LPoint3d &to_origin, const LPoint3d &to_align,
00053     const LPoint3d &to_track) {
00054   _from_origin = from_origin;
00055   _from_align = from_align;
00056   _from_track = from_track;
00057   _to_origin = to_origin;
00058   _to_align = to_align;
00059   _to_track = to_track;
00060 
00061   recompute_matrix();
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: FltTransformPut::get_from_origin
00066 //       Access: Public
00067 //  Description:
00068 ////////////////////////////////////////////////////////////////////
00069 const LPoint3d &FltTransformPut::
00070 get_from_origin() const {
00071   return _from_origin;
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: FltTransformPut::get_from_align
00076 //       Access: Public
00077 //  Description:
00078 ////////////////////////////////////////////////////////////////////
00079 const LPoint3d &FltTransformPut::
00080 get_from_align() const {
00081   return _from_align;
00082 }
00083 
00084 ////////////////////////////////////////////////////////////////////
00085 //     Function: FltTransformPut::get_from_track
00086 //       Access: Public
00087 //  Description:
00088 ////////////////////////////////////////////////////////////////////
00089 const LPoint3d &FltTransformPut::
00090 get_from_track() const {
00091   return _from_track;
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: FltTransformPut::get_to_origin
00096 //       Access: Public
00097 //  Description:
00098 ////////////////////////////////////////////////////////////////////
00099 const LPoint3d &FltTransformPut::
00100 get_to_origin() const {
00101   return _to_origin;
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //     Function: FltTransformPut::get_to_align
00106 //       Access: Public
00107 //  Description:
00108 ////////////////////////////////////////////////////////////////////
00109 const LPoint3d &FltTransformPut::
00110 get_to_align() const {
00111   return _to_align;
00112 }
00113 
00114 ////////////////////////////////////////////////////////////////////
00115 //     Function: FltTransformPut::get_to_track
00116 //       Access: Public
00117 //  Description:
00118 ////////////////////////////////////////////////////////////////////
00119 const LPoint3d &FltTransformPut::
00120 get_to_track() const {
00121   return _to_track;
00122 }
00123 
00124 ////////////////////////////////////////////////////////////////////
00125 //     Function: FltTransformPut::recompute_matrix
00126 //       Access: Private
00127 //  Description:
00128 ////////////////////////////////////////////////////////////////////
00129 void FltTransformPut::
00130 recompute_matrix() {
00131   LMatrix4d r1, r2;
00132   look_at(r1, _from_align - _from_origin, _from_track - _from_origin, CS_zup_right);
00133   look_at(r2, _to_align - _to_origin, _to_track - _to_origin, CS_zup_right);
00134 
00135   _matrix =
00136     LMatrix4d::translate_mat(-_from_origin) *
00137     invert(r1) *
00138     r2 *
00139     LMatrix4d::translate_mat(_to_origin);
00140 }
00141 
00142 ////////////////////////////////////////////////////////////////////
00143 //     Function: FltTransformPut::extract_record
00144 //       Access: Protected, Virtual
00145 //  Description: Fills in the information in this record based on the
00146 //               information given in the indicated datagram, whose
00147 //               opcode has already been read.  Returns true on
00148 //               success, false if the datagram is invalid.
00149 ////////////////////////////////////////////////////////////////////
00150 bool FltTransformPut::
00151 extract_record(FltRecordReader &reader) {
00152   if (!FltTransformRecord::extract_record(reader)) {
00153     return false;
00154   }
00155 
00156   nassertr(reader.get_opcode() == FO_put, false);
00157   DatagramIterator &iterator = reader.get_iterator();
00158 
00159   iterator.skip_bytes(4);   // Undocumented additional padding.
00160 
00161   _from_origin[0] = iterator.get_be_float64();
00162   _from_origin[1] = iterator.get_be_float64();
00163   _from_origin[2] = iterator.get_be_float64();
00164   _from_align[0] = iterator.get_be_float64();
00165   _from_align[1] = iterator.get_be_float64();
00166   _from_align[2] = iterator.get_be_float64();
00167   _from_track[0] = iterator.get_be_float64();
00168   _from_track[1] = iterator.get_be_float64();
00169   _from_track[2] = iterator.get_be_float64();
00170   _to_origin[0] = iterator.get_be_float64();
00171   _to_origin[1] = iterator.get_be_float64();
00172   _to_origin[2] = iterator.get_be_float64();
00173   _to_align[0] = iterator.get_be_float64();
00174   _to_align[1] = iterator.get_be_float64();
00175   _to_align[2] = iterator.get_be_float64();
00176   _to_track[0] = iterator.get_be_float64();
00177   _to_track[1] = iterator.get_be_float64();
00178   _to_track[2] = iterator.get_be_float64();
00179 
00180   recompute_matrix();
00181 
00182   check_remaining_size(iterator);
00183   return true;
00184 }
00185 
00186 ////////////////////////////////////////////////////////////////////
00187 //     Function: FltTransformPut::build_record
00188 //       Access: Protected, Virtual
00189 //  Description: Fills up the current record on the FltRecordWriter with
00190 //               data for this record, but does not advance the
00191 //               writer.  Returns true on success, false if there is
00192 //               some error.
00193 ////////////////////////////////////////////////////////////////////
00194 bool FltTransformPut::
00195 build_record(FltRecordWriter &writer) const {
00196   if (!FltTransformRecord::build_record(writer)) {
00197     return false;
00198   }
00199 
00200   writer.set_opcode(FO_put);
00201   Datagram &datagram = writer.update_datagram();
00202 
00203   datagram.pad_bytes(4);   // Undocumented additional padding.
00204 
00205   datagram.add_be_float64(_from_origin[0]);
00206   datagram.add_be_float64(_from_origin[1]);
00207   datagram.add_be_float64(_from_origin[2]);
00208   datagram.add_be_float64(_from_align[0]);
00209   datagram.add_be_float64(_from_align[1]);
00210   datagram.add_be_float64(_from_align[2]);
00211   datagram.add_be_float64(_from_track[0]);
00212   datagram.add_be_float64(_from_track[1]);
00213   datagram.add_be_float64(_from_track[2]);
00214   datagram.add_be_float64(_to_origin[0]);
00215   datagram.add_be_float64(_to_origin[1]);
00216   datagram.add_be_float64(_to_origin[2]);
00217   datagram.add_be_float64(_to_align[0]);
00218   datagram.add_be_float64(_to_align[1]);
00219   datagram.add_be_float64(_to_align[2]);
00220   datagram.add_be_float64(_to_track[0]);
00221   datagram.add_be_float64(_to_track[1]);
00222   datagram.add_be_float64(_to_track[2]);
00223 
00224   return true;
00225 }
00226 

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