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