Panda3D
physxForceFieldShape.cxx
1 // Filename: physxForceFieldShape.cxx
2 // Created by: enn0x (15Nov09)
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 "physxForceFieldShape.h"
16 #include "physxForceFieldShapeGroup.h"
17 #include "physxForceField.h"
18 #include "physxBoxForceFieldShape.h"
19 #include "physxCapsuleForceFieldShape.h"
20 #include "physxSphereForceFieldShape.h"
21 #include "physxConvexForceFieldShape.h"
22 #include "physxManager.h"
23 
24 TypeHandle PhysxForceFieldShape::_type_handle;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: PhysxForceFieldShape::release
28 // Access: Published
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 void PhysxForceFieldShape::
32 release() {
33 
34  nassertv(_error_type == ET_ok);
35 
36  unlink();
37  ptr()->getShapeGroup().releaseShape(*ptr());
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: PhysxForceFieldShape::factory
42 // Access: Public
43 // Description:
44 ////////////////////////////////////////////////////////////////////
45 PhysxForceFieldShape *PhysxForceFieldShape::
46 factory(NxShapeType shapeType) {
47 
48  switch (shapeType) {
49 
50  case NX_SHAPE_SPHERE:
51  return new PhysxSphereForceFieldShape();
52 
53  case NX_SHAPE_BOX:
54  return new PhysxBoxForceFieldShape();
55 
56  case NX_SHAPE_CAPSULE:
57  return new PhysxCapsuleForceFieldShape();
58 
59  case NX_SHAPE_CONVEX:
60  return new PhysxConvexForceFieldShape();
61  }
62 
63  physx_cat.error() << "Unknown shape type.\n";
64  return NULL;
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: PhysxForceFieldShape::get_force_field
69 // Access: Published
70 // Description: Returns the owning force field if this is a shape
71 // of an include group, else NULL will be returned.
72 ////////////////////////////////////////////////////////////////////
74 get_force_field() const {
75 
76  nassertr(_error_type == ET_ok, NULL);
77 
78  NxForceField *fieldPtr = ptr()->getForceField();
79  if (fieldPtr == NULL) {
80  return NULL;
81  }
82  return (PhysxForceField *)(fieldPtr->userData);
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: PhysxForceFieldShape::get_shape_group
87 // Access: Published
88 // Description: Returns the owning force field shape group.
89 ////////////////////////////////////////////////////////////////////
91 get_shape_group() const {
92 
93  nassertr(_error_type == ET_ok, NULL);
94  return (PhysxForceFieldShapeGroup *)(ptr()->getShapeGroup().userData);
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: PhysxForceFieldShape::set_name
99 // Access: Published
100 // Description: Sets a name string for this object. The name can
101 // be retrieved again with get_name().
102 ////////////////////////////////////////////////////////////////////
104 set_name(const char *name) {
105 
106  nassertv(_error_type == ET_ok);
107 
108  _name = name ? name : "";
109  ptr()->setName(_name.c_str());
110 }
111 
112 ////////////////////////////////////////////////////////////////////
113 // Function: PhysxForceFieldShape::get_name
114 // Access: Published
115 // Description: Returns the name string.
116 ////////////////////////////////////////////////////////////////////
117 const char *PhysxForceFieldShape::
118 get_name() const {
119 
120  nassertr(_error_type == ET_ok, "");
121  return ptr()->getName();
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: PhysxForceFieldShape::set_mat
126 // Access: Published
127 // Description: Sets the force field shape's transform.
128 ////////////////////////////////////////////////////////////////////
130 set_mat(const LMatrix4f &mat) {
131 
132  nassertv(_error_type == ET_ok);
133 
134  ptr()->setPose(PhysxManager::mat4_to_nxMat34(mat));
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: PhysxForceFieldShape::get_mat
139 // Access: Published
140 // Description: Returns the force field shape's transform.
141 ////////////////////////////////////////////////////////////////////
143 get_mat() const {
144 
145  nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat());
146 
147  return PhysxManager::nxMat34_to_mat4(ptr()->getPose());
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: PhysxForceFieldShape::set_pos
152 // Access: Published
153 // Description: Sets the force field shape's translation.
154 ////////////////////////////////////////////////////////////////////
156 set_pos(const LPoint3f &pos) {
157 
158  nassertv(_error_type == ET_ok);
159 
160  NxMat34 pose = ptr()->getPose();
161  pose.t = PhysxManager::point3_to_nxVec3(pos);
162  ptr()->setPose(pose);
163 }
164 
165 ////////////////////////////////////////////////////////////////////
166 // Function: PhysxForceFieldShape::get_pos
167 // Access: Published
168 // Description: Returns the force field shape's translation.
169 ////////////////////////////////////////////////////////////////////
171 get_pos() const {
172 
173  nassertr(_error_type == ET_ok, LPoint3f::zero());
174 
175  return PhysxManager::nxVec3_to_point3(ptr()->getPose().t);
176 }
177 
LMatrix4f get_mat() const
Returns the force field shape&#39;s transform.
void set_mat(const LMatrix4f &mat)
Sets the force field shape&#39;s transform.
A convex shaped region used to define force field.
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 point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
PhysxForceFieldShapeGroup * get_shape_group() const
Returns the owning force field shape group.
const char * get_name() const
Returns the name string.
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
Definition: physxManager.I:145
PhysxForceField * get_force_field() const
Returns the owning force field if this is a shape of an include group, else NULL will be returned...
void set_name(const char *name)
Sets a name string for this object.
Abstract base class for force field shapes.
void set_pos(const LPoint3f &pos)
Sets the force field shape&#39;s translation.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
static const LMatrix4f & zeros_mat()
Returns an matrix filled with zeros.
Definition: lmatrix.h:923
A force field effector.
A box shaped region used to define a force field.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88
A spherical force field shape.
A capsule shaped region used to define a force field.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
static LMatrix4f nxMat34_to_mat4(const NxMat34 &m)
Converts from NxMat34 to LMatrix4f.
Definition: physxManager.I:158
LPoint3f get_pos() const
Returns the force field shape&#39;s translation.