Panda3D
physxForceFieldDesc.cxx
1 // Filename: physxForceFieldDesc.cxx
2 // Created by: enn0x (06Nov09)
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 "physxForceFieldDesc.h"
16 #include "physxForceFieldShapeDesc.h"
17 #include "physxForceFieldShapeGroup.h"
18 #include "physxManager.h"
19 #include "physxActor.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: PhysxForceFieldDesc::set_name
23 // Access: Published
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 void PhysxForceFieldDesc::
27 set_name(const char *name) {
28 
29  _name = name ? name : "";
30  _desc.name = _name.c_str();
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: PhysxForceFieldDesc::set_pos
35 // Access: Published
36 // Description:
37 ////////////////////////////////////////////////////////////////////
38 void PhysxForceFieldDesc::
39 set_pos(const LPoint3f &pos) {
40 
41  _desc.pose.t = PhysxManager::point3_to_nxVec3(pos);
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: PhysxForceFieldDesc::set_mat
46 // Access: Published
47 // Description:
48 ////////////////////////////////////////////////////////////////////
49 void PhysxForceFieldDesc::
50 set_mat(const LMatrix4f &mat) {
51 
52  _desc.pose = PhysxManager::mat4_to_nxMat34(mat);
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: PhysxForceFieldDesc::set_hpr
57 // Access: Published
58 // Description:
59 ////////////////////////////////////////////////////////////////////
60 void PhysxForceFieldDesc::
61 set_hpr(float h, float p, float r) {
62 
63  LQuaternionf q;
64  LMatrix3f rot;
65  NxMat34 m;
66 
67  q.set_hpr(LVector3f(h, p, r));
68  q.extract_to_matrix(rot);
69 
70  _desc.pose.M = PhysxManager::mat3_to_nxMat33(rot);
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: PhysxForceFieldDesc::set_kernel_constant
75 // Access: Published
76 // Description:
77 ////////////////////////////////////////////////////////////////////
78 void PhysxForceFieldDesc::
79 set_kernel_constant(const LVector3f &constant) {
80 
81  _kernel.constant = PhysxManager::vec3_to_nxVec3(constant);
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: PhysxForceFieldDesc::set_kernel_position_target
86 // Access: Published
87 // Description:
88 ////////////////////////////////////////////////////////////////////
89 void PhysxForceFieldDesc::
90 set_kernel_position_target(const LPoint3f &target) {
91 
92  _kernel.positionTarget = PhysxManager::point3_to_nxVec3(target);
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: PhysxForceFieldDesc::set_kernel_velocity_target
97 // Access: Published
98 // Description:
99 ////////////////////////////////////////////////////////////////////
100 void PhysxForceFieldDesc::
101 set_kernel_velocity_target(const LVector3f &target) {
102 
103  _kernel.velocityTarget = PhysxManager::vec3_to_nxVec3(target);
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: PhysxForceFieldDesc::set_kernel_torus_radius
108 // Access: Published
109 // Description:
110 ////////////////////////////////////////////////////////////////////
111 void PhysxForceFieldDesc::
112 set_kernel_torus_radius(float radius) {
113 
114  _kernel.torusRadius = radius;
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: PhysxForceFieldDesc::set_kernel_falloff_linear
119 // Access: Published
120 // Description:
121 ////////////////////////////////////////////////////////////////////
122 void PhysxForceFieldDesc::
123 set_kernel_falloff_linear(const LVector3f &falloff) {
124 
125  _kernel.falloffLinear = PhysxManager::vec3_to_nxVec3(falloff);
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: PhysxForceFieldDesc::set_kernel_falloff_quadratic
130 // Access: Published
131 // Description:
132 ////////////////////////////////////////////////////////////////////
133 void PhysxForceFieldDesc::
134 set_kernel_falloff_quadratic(const LVector3f &falloff) {
135 
136  _kernel.falloffQuadratic = PhysxManager::vec3_to_nxVec3(falloff);
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: PhysxForceFieldDesc::set_kernel_noise
141 // Access: Published
142 // Description:
143 ////////////////////////////////////////////////////////////////////
144 void PhysxForceFieldDesc::
145 set_kernel_noise(const LVector3f &noise) {
146 
147  _kernel.noise = PhysxManager::vec3_to_nxVec3(noise);
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: PhysxForceFieldDesc::set_kernel_position_multiplier
152 // Access: Published
153 // Description:
154 ////////////////////////////////////////////////////////////////////
155 void PhysxForceFieldDesc::
156 set_kernel_position_multiplier(const LMatrix3f &multiplier) {
157 
158  _kernel.positionMultiplier = PhysxManager::mat3_to_nxMat33(multiplier);
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: PhysxForceFieldDesc::set_kernel_velocity_multiplier
163 // Access: Published
164 // Description:
165 ////////////////////////////////////////////////////////////////////
166 void PhysxForceFieldDesc::
167 set_kernel_velocity_multiplier(const LMatrix3f &multiplier) {
168 
169  _kernel.velocityMultiplier = PhysxManager::mat3_to_nxMat33(multiplier);
170 }
171 
172 ////////////////////////////////////////////////////////////////////
173 // Function: PhysxForceFieldDesc::create_kernel
174 // Access: Public
175 // Description:
176 ////////////////////////////////////////////////////////////////////
177 void PhysxForceFieldDesc::
178 create_kernel(NxScene *scenePtr) {
179 
180  _desc.kernel = scenePtr->createForceFieldLinearKernel(_kernel);
181 }
182 
183 ////////////////////////////////////////////////////////////////////
184 // Function: PhysxForceFieldDesc::set_coordinates
185 // Access: Published
186 // Description:
187 ////////////////////////////////////////////////////////////////////
188 void PhysxForceFieldDesc::
189 set_coordinates(PhysxForceFieldCoordinates coordinates) {
190 
191  _desc.coordinates = (NxForceFieldCoordinates) coordinates;
192 }
193 
194 ////////////////////////////////////////////////////////////////////
195 // Function: PhysxForceFieldDesc::add_include_group_shape
196 // Access: Published
197 // Description:
198 ////////////////////////////////////////////////////////////////////
199 void PhysxForceFieldDesc::
200 add_include_group_shape(PhysxForceFieldShapeDesc &desc) {
201 
202  _desc.includeGroupShapes.push_back(desc.ptr());
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: PhysxForceFieldDesc::add_shape_group
207 // Access: Published
208 // Description:
209 ////////////////////////////////////////////////////////////////////
210 void PhysxForceFieldDesc::
211 add_shape_group(PhysxForceFieldShapeGroup *group) {
212 
213  _desc.shapeGroups.push_back(group->ptr());
214 }
215 
216 ////////////////////////////////////////////////////////////////////
217 // Function: PhysxForceFieldDesc::set_actor
218 // Access: Published
219 // Description:
220 ////////////////////////////////////////////////////////////////////
221 void PhysxForceFieldDesc::
222 set_actor(PhysxActor *actor) {
223 
224  _desc.actor = actor->ptr();
225 }
226 
Abstract base class for descriptors for force field shapes descriptors.
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
void extract_to_matrix(LMatrix3f &m) const
Based on the quat lib from VRPN.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
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 NxMat33 mat3_to_nxMat33(const LMatrix3f &m)
Converts from LMatrix3f to NxMat33.
Definition: physxManager.I:169
Actors are the main simulation objects.
Definition: physxActor.h:48
void set_hpr(const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
This is the base quaternion class.
Definition: lquaternion.h:96
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110