Panda3D

fltTransformGeneralMatrix.cxx

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