Panda3D

Loading...
Searching...
No Matches
physxWheelShape.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 physxWheelShape.cxx
10 * @author enn0x
11 * @date 2009-11-09
12 */
13
14#include "physxWheelShape.h"
15#include "physxWheelShapeDesc.h"
16#include "physxSpringDesc.h"
17
18 TypeHandle PhysxWheelShape::_type_handle;
19
20/**
21 *
22 */
23 void PhysxWheelShape::
24link(NxShape *shapePtr) {
25
26 _ptr = shapePtr->isWheel();
27 _ptr->userData = this;
28 _error_type = ET_ok;
29
30 set_name(shapePtr->getName());
31
32 PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData;
33 actor->_shapes.add(this);
34}
35
36/**
37 *
38 */
39 void PhysxWheelShape::
40unlink() {
41
42 _ptr->userData = nullptr;
43 _error_type = ET_released;
44
45 PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData;
46 actor->_shapes.remove(this);
47}
48
49/**
50 * Saves the state of the shape object to a descriptor.
51 */
52 void PhysxWheelShape::
53 save_to_desc(PhysxWheelShapeDesc &shapeDesc) const {
54
55 nassertv(_error_type == ET_ok);
56 _ptr->saveToDesc(shapeDesc._desc);
57}
58
59/**
60 * Sets the sphere radius.
61 */
62 void PhysxWheelShape::
63 set_radius(float radius) {
64
65 nassertv(_error_type == ET_ok);
66 _ptr->setRadius(radius);
67}
68
69/**
70 * Returns the radius of the sphere.
71 */
72 float PhysxWheelShape::
73 get_radius() const {
74
75 nassertr(_error_type == ET_ok, 0.0f);
76 return _ptr->getRadius();
77}
78
79/**
80 * Set the maximum extension distance of suspension along shape's -Y axis.
81 * The minimum extension is always 0.
82 */
83 void PhysxWheelShape::
84 set_suspension_travel(float travel) {
85
86 nassertv(_error_type == ET_ok);
87 _ptr->setSuspensionTravel(travel);
88}
89
90/**
91 * Returns the suspension travel
92 */
93 float PhysxWheelShape::
94 get_suspension_travel() const {
95
96 nassertr(_error_type == ET_ok, 0.0f);
97 return _ptr->getSuspensionTravel();
98}
99
100/**
101 * Set the inverse mass of the wheel. Determines the wheel velocity that
102 * wheel torques can achieve.
103 */
104 void PhysxWheelShape::
105 set_inverse_wheel_mass(float invMass) {
106
107 nassertv(_error_type == ET_ok);
108 _ptr->setInverseWheelMass(invMass);
109}
110
111/**
112 * Returns the inverse mass of the wheel. Determines the wheel velocity that
113 * wheel torques can achieve.
114 */
115 float PhysxWheelShape::
116 get_inverse_wheel_mass() const {
117
118 nassertr(_error_type == ET_ok, 0.0f);
119 return _ptr->getInverseWheelMass();
120}
121
122/**
123 * Set the sum engine torque on the wheel axle. Positive or negative
124 * depending on direction
125 */
126 void PhysxWheelShape::
127 set_motor_torque(float torque) {
128
129 nassertv(_error_type == ET_ok);
130 _ptr->setMotorTorque(torque);
131}
132
133/**
134 * Retrieves the sum engine torque on the wheel axle. Positive or negative
135 * depending on direction
136 */
137 float PhysxWheelShape::
138 get_motor_torque() const {
139
140 nassertr(_error_type == ET_ok, 0.0f);
141 return _ptr->getMotorTorque();
142}
143
144/**
145 * Must be nonnegative. Very large values should lock wheel but should be
146 * stable.
147 */
148 void PhysxWheelShape::
149 set_brake_torque(float torque) {
150
151 nassertv(_error_type == ET_ok);
152 _ptr->setBrakeTorque(torque);
153}
154
155/**
156 * Must be nonnegative. Very large values should lock wheel but should be
157 * stable.
158 */
159 float PhysxWheelShape::
160 get_brake_torque() const {
161
162 nassertr(_error_type == ET_ok, 0.0f);
163 return _ptr->getBrakeTorque();
164}
165
166/**
167 * Set the steering angle, around shape Y axis. The steering angle is
168 * measured in degrees.
169 */
170 void PhysxWheelShape::
171 set_steer_angle(float angle) {
172
173 nassertv(_error_type == ET_ok);
174 _ptr->setSteerAngle(NxMath::degToRad(-1.0f * angle));
175}
176
177/**
178 * Retrieves the steering angle, around shape Y axis. The steering angle is
179 * measured in degrees.
180 */
181 float PhysxWheelShape::
182 get_steer_angle() const {
183
184 nassertr(_error_type == ET_ok, 0.0f);
185 return -1.0f * NxMath::radToDeg(_ptr->getSteerAngle());
186}
187
188/**
189 * Set the steering angle, around shape Y axis. The steering angle is
190 * measured in radians.
191 */
192 void PhysxWheelShape::
193 set_steer_angle_rad(float angle) {
194
195 nassertv(_error_type == ET_ok);
196 _ptr->setSteerAngle(-1.0f * angle);
197}
198
199/**
200 * Retrieves the steering angle, around shape Y axis. The steering angle is
201 * measured in radians.
202 */
203 float PhysxWheelShape::
204 get_steer_angle_rad() const {
205
206 nassertr(_error_type == ET_ok, 0.0f);
207 return -1.0f * _ptr->getSteerAngle();
208}
209
210/**
211 * Set the current axle rotation speed. Note: WSF_axle_speed_override flag
212 * must be raised for this to have effect!
213 */
214 void PhysxWheelShape::
215 set_axle_speed(float speed) {
216
217 nassertv(_error_type == ET_ok);
218 _ptr->setAxleSpeed(speed);
219}
220
221/**
222 * Retrieves the current axle rotation speed.
223 */
224 float PhysxWheelShape::
225 get_axle_speed() const {
226
227 nassertr(_error_type == ET_ok, 0.0f);
228 return _ptr->getAxleSpeed();
229}
230
231/**
232 * Turns the specified wheel shape flag on or off.
233 */
234 void PhysxWheelShape::
235 set_wheel_flag(PhysxWheelShapeFlag flag, bool value) {
236
237 nassertv(_error_type == ET_ok);
238 NxU32 flags = _ptr->getWheelFlags();
239
240 if (value == true) {
241 flags |= flag;
242 } else {
243 flags &= ~(flag);
244 }
245
246 _ptr->setWheelFlags(flags);
247}
248
249/**
250 * Returns the value of the specified wheel shape flag.
251 */
252 bool PhysxWheelShape::
253 get_wheel_flag(PhysxWheelShapeFlag flag) const {
254
255 nassertr(_error_type == ET_ok, false);
256 return (_ptr->getWheelFlags() & flag) ? true : false;
257}
258
259/**
260 * Set the data intended for car wheel suspension effects.
261 */
262 void PhysxWheelShape::
263 set_suspension(const PhysxSpringDesc &spring) {
264
265 nassertv(_error_type == ET_ok);
266 return _ptr->setSuspension(spring._desc);
267}
PhysxShape::set_name
void set_name(const char *name)
Sets a name string for this object.
Definition physxShape.cxx:100
PhysxSpringDesc
Describes a joint spring.
Definition physxSpringDesc.h:25
PhysxWheelShapeDesc
Descriptor class for PhysxWheelShape.
Definition physxWheelShapeDesc.h:27
PhysxWheelShape::get_axle_speed
float get_axle_speed() const
Retrieves the current axle rotation speed.
Definition physxWheelShape.cxx:225
PhysxWheelShape::get_radius
float get_radius() const
Returns the radius of the sphere.
Definition physxWheelShape.cxx:73
PhysxWheelShape::get_suspension_travel
float get_suspension_travel() const
Returns the suspension travel.
Definition physxWheelShape.cxx:94
PhysxWheelShape::set_brake_torque
void set_brake_torque(float torque)
Must be nonnegative.
Definition physxWheelShape.cxx:149
PhysxWheelShape::set_motor_torque
void set_motor_torque(float torque)
Set the sum engine torque on the wheel axle.
Definition physxWheelShape.cxx:127
PhysxWheelShape::get_motor_torque
float get_motor_torque() const
Retrieves the sum engine torque on the wheel axle.
Definition physxWheelShape.cxx:138
PhysxWheelShape::set_inverse_wheel_mass
void set_inverse_wheel_mass(float invMass)
Set the inverse mass of the wheel.
Definition physxWheelShape.cxx:105
PhysxWheelShape::save_to_desc
void save_to_desc(PhysxWheelShapeDesc &shapeDesc) const
Saves the state of the shape object to a descriptor.
Definition physxWheelShape.cxx:53
PhysxWheelShape::get_steer_angle
float get_steer_angle() const
Retrieves the steering angle, around shape Y axis.
Definition physxWheelShape.cxx:182
PhysxWheelShape::get_brake_torque
float get_brake_torque() const
Must be nonnegative.
Definition physxWheelShape.cxx:160
PhysxWheelShape::get_wheel_flag
bool get_wheel_flag(PhysxWheelShapeFlag flag) const
Returns the value of the specified wheel shape flag.
Definition physxWheelShape.cxx:253
PhysxWheelShape::get_steer_angle_rad
float get_steer_angle_rad() const
Retrieves the steering angle, around shape Y axis.
Definition physxWheelShape.cxx:204
PhysxWheelShape::set_steer_angle_rad
void set_steer_angle_rad(float angle)
Set the steering angle, around shape Y axis.
Definition physxWheelShape.cxx:193
PhysxWheelShape::set_wheel_flag
void set_wheel_flag(PhysxWheelShapeFlag flag, bool value)
Turns the specified wheel shape flag on or off.
Definition physxWheelShape.cxx:235
PhysxWheelShape::get_inverse_wheel_mass
float get_inverse_wheel_mass() const
Returns the inverse mass of the wheel.
Definition physxWheelShape.cxx:116
PhysxWheelShape::set_axle_speed
void set_axle_speed(float speed)
Set the current axle rotation speed.
Definition physxWheelShape.cxx:215
PhysxWheelShape::set_steer_angle
void set_steer_angle(float angle)
Set the steering angle, around shape Y axis.
Definition physxWheelShape.cxx:171
PhysxWheelShape::set_suspension
void set_suspension(const PhysxSpringDesc &spring)
Set the data intended for car wheel suspension effects.
Definition physxWheelShape.cxx:263
PhysxWheelShape::set_radius
void set_radius(float radius)
Sets the sphere radius.
Definition physxWheelShape.cxx:63
PhysxWheelShape::set_suspension_travel
void set_suspension_travel(float travel)
Set the maximum extension distance of suspension along shape's -Y axis.
Definition physxWheelShape.cxx:84
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
physxSpringDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physxWheelShapeDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physxWheelShape.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.