Panda3D
xFileNormal.cxx
1 // Filename: xFileNormal.cxx
2 // Created by: drose (19Jun01)
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 "xFileNormal.h"
16 #include "eggVertex.h"
17 #include "eggPrimitive.h"
18 #include "config_xfile.h"
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: XFileNormal::Constructor
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 XFileNormal::
26 XFileNormal() {
27  _normal.set(0.0, 0.0, 0.0);
28  _has_normal = false;
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: XFileNormal::set_from_egg
33 // Access: Public
34 // Description: Sets the structure up from the indicated egg data.
35 ////////////////////////////////////////////////////////////////////
36 void XFileNormal::
37 set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
38  if (egg_vertex->has_normal() || egg_prim->has_normal()) {
39  LNormald norm;
40  if (egg_vertex->has_normal()) {
41  norm = egg_vertex->get_normal();
42  } else {
43  norm = egg_prim->get_normal();
44  }
45 
46  if (xfile_one_mesh) {
47  // If this is going into one big mesh, we must ensure every
48  // vertex is in world coordinates.
49  norm = norm * egg_prim->get_vertex_frame();
50  } else {
51  // Otherwise, we ensure the vertex is in local coordinates.
52  norm = norm * egg_prim->get_vertex_to_node();
53  }
54 
55  _normal = norm;
56  _has_normal = true;
57  }
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: XFileNormal::compare_to
62 // Access: Public
63 // Description:
64 ////////////////////////////////////////////////////////////////////
65 int XFileNormal::
66 compare_to(const XFileNormal &other) const {
67  int ct;
68  ct = _normal.compare_to(other._normal);
69  return ct;
70 }
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
const LMatrix4d & get_vertex_frame() const
Returns the coordinate frame of the vertices referenced by primitives at or under this node...
Definition: eggNode.I:135
This represents a single normal associated with an XFileFace.
Definition: xFileNormal.h:31
void set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_prim)
Sets the structure up from the indicated egg data.
Definition: xFileNormal.cxx:37
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:760
int compare_to(const LVecBase3d &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
Definition: lvecBase3.h:2306
const LMatrix4d & get_vertex_to_node() const
Returns the transformation matrix suitable for converting the vertices as read from the egg file into...
Definition: eggNode.I:203