Panda3D
|
00001 // Filename: cLwoSurfaceBlockTMap.cxx 00002 // Created by: drose (30Apr01) 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 "cLwoSurfaceBlockTMap.h" 00016 #include "lwoToEggConverter.h" 00017 00018 #include "lwoSurfaceBlockTransform.h" 00019 #include "lwoSurfaceBlockRefObj.h" 00020 #include "compose_matrix.h" 00021 #include "dcast.h" 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: CLwoSurfaceBlockTMap::Constructor 00025 // Access: Public 00026 // Description: 00027 //////////////////////////////////////////////////////////////////// 00028 CLwoSurfaceBlockTMap:: 00029 CLwoSurfaceBlockTMap(LwoToEggConverter *converter, const LwoSurfaceBlockTMap *tmap) : 00030 _converter(converter), 00031 _tmap(tmap) 00032 { 00033 _center.set(0.0, 0.0, 0.0); 00034 _size.set(1.0, 1.0, 1.0); 00035 _rotation.set(0.0, 0.0, 0.0); 00036 _csys = LwoSurfaceBlockCoordSys::T_object; 00037 _reference_object = "(none)"; 00038 00039 // Scan the chunks in the body. 00040 int num_chunks = _tmap->get_num_chunks(); 00041 for (int i = 0; i < num_chunks; i++) { 00042 const IffChunk *chunk = _tmap->get_chunk(i); 00043 00044 if (chunk->is_of_type(LwoSurfaceBlockTransform::get_class_type())) { 00045 const LwoSurfaceBlockTransform *trans = DCAST(LwoSurfaceBlockTransform, chunk); 00046 if (trans->get_id() == IffId("CNTR")) { 00047 _center = trans->_vec; 00048 } else if (trans->get_id() == IffId("SIZE")) { 00049 _size = trans->_vec; 00050 } else if (trans->get_id() == IffId("ROTA")) { 00051 _rotation = trans->_vec; 00052 } 00053 00054 } else if (chunk->is_of_type(LwoSurfaceBlockRefObj::get_class_type())) { 00055 const LwoSurfaceBlockRefObj *ref = DCAST(LwoSurfaceBlockRefObj, chunk); 00056 _reference_object = ref->_name; 00057 00058 } else if (chunk->is_of_type(LwoSurfaceBlockCoordSys::get_class_type())) { 00059 const LwoSurfaceBlockCoordSys *csys = DCAST(LwoSurfaceBlockCoordSys, chunk); 00060 _csys = csys->_type; 00061 } 00062 } 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: CLwoSurfaceBlockTMap::get_transform 00067 // Access: Public 00068 // Description: Fills up the indicated matrix with the net transform 00069 // indicated by the TMAP chunk, accounting for scale, 00070 // rotate, and translate. 00071 //////////////////////////////////////////////////////////////////// 00072 void CLwoSurfaceBlockTMap:: 00073 get_transform(LMatrix4d &mat) const { 00074 LPoint3d hpr(rad_2_deg(_rotation[0]), 00075 rad_2_deg(-_rotation[1]), 00076 rad_2_deg(-_rotation[2])); 00077 compose_matrix(mat, LCAST(double, _size), hpr, 00078 LCAST(double, _center), CS_yup_left); 00079 }