Panda3D
physxForceFieldShape.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file physxForceFieldShape.cxx
10  * @author enn0x
11  * @date 2009-11-15
12  */
13 
14 #include "physxForceFieldShape.h"
16 #include "physxForceField.h"
21 #include "physxManager.h"
22 
23 TypeHandle PhysxForceFieldShape::_type_handle;
24 
25 /**
26  *
27  */
28 void PhysxForceFieldShape::
29 release() {
30 
31  nassertv(_error_type == ET_ok);
32 
33  unlink();
34  ptr()->getShapeGroup().releaseShape(*ptr());
35 }
36 
37 /**
38  *
39  */
40 PhysxForceFieldShape *PhysxForceFieldShape::
41 factory(NxShapeType shapeType) {
42 
43  switch (shapeType) {
44 
45  case NX_SHAPE_SPHERE:
46  return new PhysxSphereForceFieldShape();
47 
48  case NX_SHAPE_BOX:
49  return new PhysxBoxForceFieldShape();
50 
51  case NX_SHAPE_CAPSULE:
52  return new PhysxCapsuleForceFieldShape();
53 
54  case NX_SHAPE_CONVEX:
55  return new PhysxConvexForceFieldShape();
56  }
57 
58  physx_cat.error() << "Unknown shape type.\n";
59  return nullptr;
60 }
61 
62 /**
63  * Returns the owning force field if this is a shape of an include group, else
64  * NULL will be returned.
65  */
67 get_force_field() const {
68 
69  nassertr(_error_type == ET_ok, nullptr);
70 
71  NxForceField *fieldPtr = ptr()->getForceField();
72  if (fieldPtr == nullptr) {
73  return nullptr;
74  }
75  return (PhysxForceField *)(fieldPtr->userData);
76 }
77 
78 /**
79  * Returns the owning force field shape group.
80  */
82 get_shape_group() const {
83 
84  nassertr(_error_type == ET_ok, nullptr);
85  return (PhysxForceFieldShapeGroup *)(ptr()->getShapeGroup().userData);
86 }
87 
88 /**
89  * Sets a name string for this object. The name can be retrieved again with
90  * get_name().
91  */
93 set_name(const char *name) {
94 
95  nassertv(_error_type == ET_ok);
96 
97  _name = name ? name : "";
98  ptr()->setName(_name.c_str());
99 }
100 
101 /**
102  * Returns the name string.
103  */
105 get_name() const {
106 
107  nassertr(_error_type == ET_ok, "");
108  return ptr()->getName();
109 }
110 
111 /**
112  * Sets the force field shape's transform.
113  */
115 set_mat(const LMatrix4f &mat) {
116 
117  nassertv(_error_type == ET_ok);
118 
119  ptr()->setPose(PhysxManager::mat4_to_nxMat34(mat));
120 }
121 
122 /**
123  * Returns the force field shape's transform.
124  */
126 get_mat() const {
127 
128  nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat());
129 
130  return PhysxManager::nxMat34_to_mat4(ptr()->getPose());
131 }
132 
133 /**
134  * Sets the force field shape's translation.
135  */
137 set_pos(const LPoint3f &pos) {
138 
139  nassertv(_error_type == ET_ok);
140 
141  NxMat34 pose = ptr()->getPose();
142  pose.t = PhysxManager::point3_to_nxVec3(pos);
143  ptr()->setPose(pose);
144 }
145 
146 /**
147  * Returns the force field shape's translation.
148  */
150 get_pos() const {
151 
152  nassertr(_error_type == ET_ok, LPoint3f::zero());
153 
154  return PhysxManager::nxVec3_to_point3(ptr()->getPose().t);
155 }
A box shaped region used to define a force field.
A capsule shaped region used to define a force field.
A convex shaped region used to define force field.
Abstract base class for force field shapes.
void set_mat(const LMatrix4f &mat)
Sets the force field shape's transform.
LPoint3f get_pos() const
Returns the force field shape's translation.
PhysxForceField * get_force_field() const
Returns the owning force field if this is a shape of an include group, else NULL will be returned.
const char * get_name() const
Returns the name string.
PhysxForceFieldShapeGroup * get_shape_group() const
Returns the owning force field shape group.
void set_pos(const LPoint3f &pos)
Sets the force field shape's translation.
void set_name(const char *name)
Sets a name string for this object.
LMatrix4f get_mat() const
Returns the force field shape's transform.
A force field effector.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:63
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
Definition: physxManager.I:119
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:72
static LMatrix4f nxMat34_to_mat4(const NxMat34 &m)
Converts from NxMat34 to LMatrix4f.
Definition: physxManager.I:130
A spherical force field shape.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.