Panda3D
Loading...
Searching...
No Matches
physxJointDesc.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 physxJointDesc.cxx
10 * @author enn0x
11 * @date 2009-09-28
12 */
13
14#include "physxJointDesc.h"
15#include "physxManager.h"
16
17/**
18 * Sets a possible debug name.
19 */
21set_name(const char *name) {
22
23 _name = name ? name : "";
24 ptr()->name = _name.c_str();
25}
26
27/**
28 * Set a possible debug name.
29 */
31set_max_force(float force) {
32
33 ptr()->maxForce = force;
34}
35
36/**
37 * Set the maximum angular force (torque) that the joint can withstand before
38 * breaking, must be positive.
39 */
41set_max_torque(float torque) {
42
43 ptr()->maxTorque = torque;
44}
45
46/**
47 * Set the extrapolation factor for solving joint constraints.
48 */
51
52 ptr()->solverExtrapolationFactor = factor;
53}
54
55/**
56 * Set the two actors connected by the joint. idx must be either 0 or 1.
57 */
59set_actor(unsigned int idx, const PhysxActor &actor) {
60
61 nassertv_always(idx < 2);
62 ptr()->actor[idx] = actor.ptr();
63}
64
65/**
66 * Set the X axis of joint space, in actor[i]'s space, orthogonal to
67 * localAxis[i]. idx must be either 0 or 1.
68 */
70set_local_normal(unsigned int idx, const LVector3f &normal) {
71
72 nassertv_always(idx < 2);
73 ptr()->localNormal[idx] = PhysxManager::vec3_to_nxVec3(normal);
74}
75
76/**
77 * Set the Z axis of joint space, in actor[i]'s space. This is the primary
78 * axis of the joint. idx must be either 0 or 1.
79 */
81set_local_axis(unsigned int idx, const LVector3f &axis) {
82
83 nassertv_always(idx < 2);
84 ptr()->localAxis[idx] = PhysxManager::vec3_to_nxVec3(axis);
85}
86
87/**
88 * Set the attachment point of joint in actor[i]'s space. idx must be either
89 * 0 or 1.
90 */
92set_local_anchor(unsigned int idx, const LPoint3f &anchor) {
93
94 nassertv_always(idx < 2);
95 ptr()->localAnchor[idx] = PhysxManager::point3_to_nxVec3(anchor);
96}
97
98/**
99 * Set or clear a single JointFlag.
100 */
102set_joint_flag(PhysxJointFlag flag, bool value) {
103
104 if (value == true) {
105 ptr()->jointFlags |= flag;
106 }
107 else {
108 ptr()->jointFlags &= ~(flag);
109 }
110}
111
112/**
113 * Set the local axis/normal using a world space axis.
114 */
116set_global_axis(const LVector3f &axis) {
117
118 ptr()->setGlobalAxis(PhysxManager::vec3_to_nxVec3(axis));
119}
120
121/**
122 * Set the anchor using a world space point.
123 */
125set_global_anchor(const LPoint3f &anchor) {
126
127 ptr()->setGlobalAnchor(PhysxManager::point3_to_nxVec3(anchor));
128}
129
130/**
131 *
132 */
133const char *PhysxJointDesc::
134get_name() const {
135
136 return ptr()->name;
137}
138
139/**
140 *
141 */
142float PhysxJointDesc::
143get_max_force() const {
144
145 return ptr()->maxForce;
146}
147
148/**
149 *
150 */
151float PhysxJointDesc::
152get_max_torque() const {
153
154 return ptr()->maxTorque;
155}
156
157/**
158 *
159 */
160float PhysxJointDesc::
161get_solver_extrapolation_factor() const {
162
163 return ptr()->solverExtrapolationFactor;
164}
165
166/**
167 *
168 */
169LVector3f PhysxJointDesc::
170get_local_normal(unsigned int idx) const {
171
172 nassertr_always(idx < 2, LVector3f::zero());
173 return PhysxManager::nxVec3_to_vec3(ptr()->localNormal[idx]);
174}
175
176/**
177 *
178 */
179LVector3f PhysxJointDesc::
180get_local_axis(unsigned int idx) const {
181
182 nassertr_always(idx < 2, LVector3f::zero());
183 return PhysxManager::nxVec3_to_vec3(ptr()->localAxis[idx]);
184}
185
186/**
187 *
188 */
189LPoint3f PhysxJointDesc::
190get_local_anchor(unsigned int idx) const {
191
192 nassertr_always(idx < 2, LPoint3f::zero());
193 return PhysxManager::nxVec3_to_point3(ptr()->localAnchor[idx]);
194}
195
196/**
197 *
198 */
199bool PhysxJointDesc::
200get_joint_flag(const PhysxJointFlag flag) const {
201
202 return (ptr()->jointFlags & flag) ? true : false;
203}
204
205/**
206 *
207 */
208PhysxActor *PhysxJointDesc::
209get_actor(unsigned int idx) const {
210
211 nassertr_always(idx < 2, nullptr);
212
213 NxActor *actorPtr = ptr()->actor[idx];
214 if (actorPtr == nullptr) {
215 return nullptr;
216 }
217 else {
218 return (PhysxActor *)(actorPtr->userData);
219 }
220}
Actors are the main simulation objects.
Definition physxActor.h:44
void set_global_anchor(const LPoint3f &anchor)
Set the anchor using a world space point.
void set_solver_extrapolation_factor(float factor)
Set the extrapolation factor for solving joint constraints.
void set_local_normal(unsigned int idx, const LVector3f &normal)
Set the X axis of joint space, in actor[i]'s space, orthogonal to localAxis[i].
void set_local_anchor(unsigned int idx, const LPoint3f &anchor)
Set the attachment point of joint in actor[i]'s space.
void set_global_axis(const LVector3f &axis)
Set the local axis/normal using a world space axis.
void set_name(const char *name)
Sets a possible debug name.
void set_joint_flag(PhysxJointFlag flag, bool value)
Set or clear a single JointFlag.
void set_local_axis(unsigned int idx, const LVector3f &axis)
Set the Z axis of joint space, in actor[i]'s space.
void set_max_force(float force)
Set a possible debug name.
void set_actor(unsigned int idx, const PhysxActor &actor)
Set the two actors connected by the joint.
void set_max_torque(float torque)
Set the maximum angular force (torque) that the joint can withstand before breaking,...
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.