Panda3D
 All Classes Functions Variables Enumerations
physxForceField.cxx
1 // Filename: physxForceField.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 "physxForceField.h"
16 #include "physxForceFieldDesc.h"
17 #include "physxForceFieldShapeGroup.h"
18 #include "physxScene.h"
19 
20 TypeHandle PhysxForceField::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: PhysxForceField::link
24 // Access: Public
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 void PhysxForceField::
28 link(NxForceField *fieldPtr) {
29 
30  // Link self
31  _ptr = fieldPtr;
32  _ptr->userData = this;
33  _error_type = ET_ok;
34 
35  set_name(fieldPtr->getName());
36 
37  PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
38  scene->_forcefields.add(this);
39 
40  // Link include shape group
42  group->link(&(_ptr->getIncludeShapeGroup()));
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: PhysxForceField::unlink
47 // Access: Public
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 void PhysxForceField::
51 unlink() {
52 
53  // Unlink inlcude shape group
54  PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)(_ptr->getIncludeShapeGroup().userData);
55  group->unlink();
56 
57  // Unlink self
58  _ptr->userData = NULL;
59  _error_type = ET_released;
60 
61  PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
62  scene->_forcefields.remove(this);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: PhysxForceField::release
67 // Access: Published
68 // Description:
69 ////////////////////////////////////////////////////////////////////
70 void PhysxForceField::
71 release() {
72 
73  nassertv(_error_type == ET_ok);
74 
75  unlink();
76  _ptr->getScene().releaseForceField(*_ptr);
77  _ptr = NULL;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: PhysxForceField::set_name
82 // Access: Published
83 // Description:
84 ////////////////////////////////////////////////////////////////////
85 void PhysxForceField::
86 set_name(const char *name) {
87 
88  nassertv(_error_type == ET_ok);
89 
90  _name = name ? name : "";
91  _ptr->setName(_name.c_str());
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: PhysxForceField::get_name
96 // Access: Published
97 // Description:
98 ////////////////////////////////////////////////////////////////////
99 const char *PhysxForceField::
100 get_name() const {
101 
102  nassertr(_error_type == ET_ok, "");
103  return _ptr->getName();
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: PhysxForceField::get_scene
108 // Access: Published
109 // Description:
110 ////////////////////////////////////////////////////////////////////
111 PhysxScene *PhysxForceField::
112 get_scene() const {
113 
114  nassertr(_error_type == ET_ok, NULL);
115  return (PhysxScene *)(_ptr->getScene().userData);
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: PhysxForceField::get_include_shape_group
120 // Access: Published
121 // Description:
122 ////////////////////////////////////////////////////////////////////
123 PhysxForceFieldShapeGroup *PhysxForceField::
124 get_include_shape_group() const {
125 
126  nassertr(_error_type == ET_ok, NULL);
127  return (PhysxForceFieldShapeGroup *)(_ptr->getIncludeShapeGroup().userData);
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: PhysxForceField::get_num_shape_groups
132 // Access: Published
133 // Description:
134 ////////////////////////////////////////////////////////////////////
135 unsigned int PhysxForceField::
136 get_num_shape_groups() const {
137 
138  nassertr(_error_type == ET_ok, 0);
139  return _ptr->getNbShapeGroups();
140 }
141 
142 ////////////////////////////////////////////////////////////////////
143 // Function: PhysxForceField::get_shape_group
144 // Access: Published
145 // Description:
146 ////////////////////////////////////////////////////////////////////
147 PhysxForceFieldShapeGroup *PhysxForceField::
148 get_shape_group(unsigned int idx) const {
149 
150  nassertr(_error_type == ET_ok, NULL);
151  nassertr_always(idx < _ptr->getNbShapeGroups(), NULL);
152 
153  NxForceFieldShapeGroup *groupPtr;
154  NxU32 nGroups = _ptr->getNbShapeGroups();
155 
156  _ptr->resetShapeGroupsIterator();
157  for (NxU32 i=0; i <= idx; i++) {
158  groupPtr = _ptr->getNextShapeGroup();
159  }
160 
161  return (PhysxForceFieldShapeGroup *)(groupPtr->userData);
162 }
163 
A scene is a collection of bodies, constraints, and effectors which can interact. ...
Definition: physxScene.h:73
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85