Panda3D
physxPlane.cxx
1 // Filename: physxPlane.cxx
2 // Created by: enn0x (31Oct09)
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 "physxPlane.h"
16 #include "physxManager.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PhysxPlane::distance
20 // Access: Published
21 // Description:
22 ////////////////////////////////////////////////////////////////////
23 float PhysxPlane::
24 distance(const LPoint3f &p) const {
25 
26  nassertr(!p.is_nan(), 0.0f);
27 
28  return _plane.distance(PhysxManager::point3_to_nxVec3(p));
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: PhysxPlane::belongs
33 // Access: Published
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 bool PhysxPlane::
37 belongs(const LPoint3f &p) const {
38 
39  nassertr(!p.is_nan(), false);
40 
41  return _plane.belongs(PhysxManager::point3_to_nxVec3(p));
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: PhysxPlane::point_in_plane
46 // Access: Published
47 // Description:
48 ////////////////////////////////////////////////////////////////////
49 LPoint3f PhysxPlane::
50 point_in_plane() const {
51 
52  return PhysxManager::nxVec3_to_point3(_plane.pointInPlane());
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: PhysxPlane::project
57 // Access: Published
58 // Description:
59 ////////////////////////////////////////////////////////////////////
60 LPoint3f PhysxPlane::
61 project(const LPoint3f &p) const {
62 
63  nassertr(!p.is_nan(), LPoint3f::zero());
64 
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: PhysxPlane::inverse_transform
70 // Access: Published
71 // Description:
72 ////////////////////////////////////////////////////////////////////
73 void PhysxPlane::
74 inverse_transform(const LMatrix4f &transform, PhysxPlane &transformed) const {
75 
76  nassertv(!transform.is_nan());
77 
78  _plane.inverseTransform(PhysxManager::mat4_to_nxMat34(transform), transformed._plane);
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: PhysxPlane::normalize
83 // Access: Published
84 // Description:
85 ////////////////////////////////////////////////////////////////////
86 void PhysxPlane::
87 normalize() {
88 
89  _plane.normalize();
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: PhysxPlane::transform
94 // Access: Published
95 // Description:
96 ////////////////////////////////////////////////////////////////////
97 void PhysxPlane::
98 transform(const LMatrix4f &transform, PhysxPlane &transformed) const {
99 
100  nassertv(!transform.is_nan());
101 
102  _plane.transform(PhysxManager::mat4_to_nxMat34(transform), transformed._plane);
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: PhysxPlane::get_d
107 // Access: Published
108 // Description:
109 ////////////////////////////////////////////////////////////////////
110 float PhysxPlane::
111 get_d() const {
112 
113  return _plane.d;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: PhysxPlane::set_d
118 // Access: Published
119 // Description:
120 ////////////////////////////////////////////////////////////////////
121 void PhysxPlane::
122 set_d(float value) {
123 
124  _plane.d = value;
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: PhysxPlane::get_normal
129 // Access: Published
130 // Description:
131 ////////////////////////////////////////////////////////////////////
132 LVector3f PhysxPlane::
133 get_normal() const {
134 
135  return PhysxManager::nxVec3_to_vec3(_plane.normal);
136 }
137 
138 ////////////////////////////////////////////////////////////////////
139 // Function: PhysxPlane::set_normal
140 // Access: Published
141 // Description:
142 ////////////////////////////////////////////////////////////////////
143 void PhysxPlane::
144 set_normal(LVector3f normal) {
145 
146  nassertv(!normal.is_nan());
147 
148  _plane.normal = PhysxManager::vec3_to_nxVec3(normal);
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: PhysxPlane::set
153 // Access: Published
154 // Description:
155 ////////////////////////////////////////////////////////////////////
156 PhysxPlane PhysxPlane::
157 set(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &p2) {
158 
159  PhysxPlane plane;
160 
161  nassertr(!p0.is_nan(), plane);
162  nassertr(!p1.is_nan(), plane);
163  nassertr(!p2.is_nan(), plane);
164 
165  plane._plane = _plane.set(PhysxManager::point3_to_nxVec3(p0),
168  return plane;
169 }
170 
171 ////////////////////////////////////////////////////////////////////
172 // Function: PhysxPlane::zero
173 // Access: Published
174 // Description:
175 ////////////////////////////////////////////////////////////////////
176 PhysxPlane PhysxPlane::
177 zero() {
178 
179  PhysxPlane plane;
180  plane._plane = _plane.zero();
181  return plane;
182 }
183 
static const LPoint3f & zero()
Returns a zero-length point.
Definition: lpoint3.h:259
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:77
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:464
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
Definition: lmatrix.h:1417
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
Definition: physxManager.I:145
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:33
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:44
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88