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