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

pandatool/src/flt/fltTransformScale.cxx

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

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