Panda3D
cLwoSurfaceBlockTMap.cxx
1 // Filename: cLwoSurfaceBlockTMap.cxx
2 // Created by: drose (30Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "cLwoSurfaceBlockTMap.h"
16 #include "lwoToEggConverter.h"
17 
18 #include "lwoSurfaceBlockTransform.h"
19 #include "lwoSurfaceBlockRefObj.h"
20 #include "compose_matrix.h"
21 #include "dcast.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: CLwoSurfaceBlockTMap::Constructor
25 // Access: Public
26 // Description:
27 ////////////////////////////////////////////////////////////////////
28 CLwoSurfaceBlockTMap::
29 CLwoSurfaceBlockTMap(LwoToEggConverter *converter, const LwoSurfaceBlockTMap *tmap) :
30  _converter(converter),
31  _tmap(tmap)
32 {
33  _center.set(0.0, 0.0, 0.0);
34  _size.set(1.0, 1.0, 1.0);
35  _rotation.set(0.0, 0.0, 0.0);
36  _csys = LwoSurfaceBlockCoordSys::T_object;
37  _reference_object = "(none)";
38 
39  // Scan the chunks in the body.
40  int num_chunks = _tmap->get_num_chunks();
41  for (int i = 0; i < num_chunks; i++) {
42  const IffChunk *chunk = _tmap->get_chunk(i);
43 
44  if (chunk->is_of_type(LwoSurfaceBlockTransform::get_class_type())) {
45  const LwoSurfaceBlockTransform *trans = DCAST(LwoSurfaceBlockTransform, chunk);
46  if (trans->get_id() == IffId("CNTR")) {
47  _center = trans->_vec;
48  } else if (trans->get_id() == IffId("SIZE")) {
49  _size = trans->_vec;
50  } else if (trans->get_id() == IffId("ROTA")) {
51  _rotation = trans->_vec;
52  }
53 
54  } else if (chunk->is_of_type(LwoSurfaceBlockRefObj::get_class_type())) {
55  const LwoSurfaceBlockRefObj *ref = DCAST(LwoSurfaceBlockRefObj, chunk);
56  _reference_object = ref->_name;
57 
58  } else if (chunk->is_of_type(LwoSurfaceBlockCoordSys::get_class_type())) {
59  const LwoSurfaceBlockCoordSys *csys = DCAST(LwoSurfaceBlockCoordSys, chunk);
60  _csys = csys->_type;
61  }
62  }
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: CLwoSurfaceBlockTMap::get_transform
67 // Access: Public
68 // Description: Fills up the indicated matrix with the net transform
69 // indicated by the TMAP chunk, accounting for scale,
70 // rotate, and translate.
71 ////////////////////////////////////////////////////////////////////
73 get_transform(LMatrix4d &mat) const {
74  LPoint3d hpr(rad_2_deg(_rotation[0]),
75  rad_2_deg(-_rotation[1]),
76  rad_2_deg(-_rotation[2]));
77  compose_matrix(mat, LCAST(double, _size), hpr,
78  LCAST(double, _center), CS_yup_left);
79 }
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
The tMap chunk within a LwoSurfaceBlock chunk.
void get_transform(LMatrix4d &mat) const
Fills up the indicated matrix with the net transform indicated by the TMAP chunk, accounting for scal...
Specifies whether texture coordinates are computed based on the vertices&#39; world coordinates or local ...
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on...
Definition: iffChunk.h:32
This class supervises the construction of an EggData structure from the data represented by the LwoHe...
Specifies a center point, scale, or rotation for the texture coordinates in this shader&#39;s texture map...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:544
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:63
Specifies a reference object that the texture UV&#39;s are to be computed relative to.
A four-byte chunk ID appearing in an "IFF" file.
Definition: iffId.h:29
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:31