00001 // Filename: fltTransformGeneralMatrix.cxx 00002 // Created by: drose (24Aug00) 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 "fltTransformGeneralMatrix.h" 00020 #include "fltRecordReader.h" 00021 #include "fltRecordWriter.h" 00022 00023 TypeHandle FltTransformGeneralMatrix::_type_handle; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: FltTransformGeneralMatrix::Constructor 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 FltTransformGeneralMatrix:: 00031 FltTransformGeneralMatrix(FltHeader *header) : FltTransformRecord(header) { 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function: FltTransformGeneralMatrix::set_matrix 00036 // Access: Public 00037 // Description: Directly sets the general matrix. 00038 //////////////////////////////////////////////////////////////////// 00039 void FltTransformGeneralMatrix:: 00040 set_matrix(const LMatrix4d &matrix) { 00041 _matrix = matrix; 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function: FltTransformGeneralMatrix::set_matrix 00046 // Access: Public 00047 // Description: Directly sets the general matrix. 00048 //////////////////////////////////////////////////////////////////// 00049 void FltTransformGeneralMatrix:: 00050 set_matrix(const LMatrix4f &matrix) { 00051 _matrix = LCAST(double, matrix); 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: FltTransformGeneralMatrix::extract_record 00056 // Access: Protected, Virtual 00057 // Description: Fills in the information in this record based on the 00058 // information given in the indicated datagram, whose 00059 // opcode has already been read. Returns true on 00060 // success, false if the datagram is invalid. 00061 //////////////////////////////////////////////////////////////////// 00062 bool FltTransformGeneralMatrix:: 00063 extract_record(FltRecordReader &reader) { 00064 if (!FltTransformRecord::extract_record(reader)) { 00065 return false; 00066 } 00067 00068 nassertr(reader.get_opcode() == FO_general_matrix, false); 00069 DatagramIterator &iterator = reader.get_iterator(); 00070 00071 for (int r = 0; r < 4; r++) { 00072 for (int c = 0; c < 4; c++) { 00073 _matrix(r, c) = iterator.get_be_float32(); 00074 } 00075 } 00076 00077 check_remaining_size(iterator); 00078 return true; 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: FltTransformGeneralMatrix::build_record 00083 // Access: Protected, Virtual 00084 // Description: Fills up the current record on the FltRecordWriter with 00085 // data for this record, but does not advance the 00086 // writer. Returns true on success, false if there is 00087 // some error. 00088 //////////////////////////////////////////////////////////////////// 00089 bool FltTransformGeneralMatrix:: 00090 build_record(FltRecordWriter &writer) const { 00091 if (!FltTransformRecord::build_record(writer)) { 00092 return false; 00093 } 00094 00095 writer.set_opcode(FO_general_matrix); 00096 Datagram &datagram = writer.update_datagram(); 00097 00098 for (int r = 0; r < 4; r++) { 00099 for (int c = 0; c < 4; c++) { 00100 datagram.add_be_float32(_matrix(r, c)); 00101 } 00102 } 00103 00104 return true; 00105 }