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
18TypeHandle PhysxWheelShape::_type_handle;
19
20/**
21 *
22 */
23void 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 */
39void 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 */
53save_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 */
63set_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 */
73get_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 */
84set_suspension_travel(float travel) {
85
86 nassertv(_error_type == ET_ok);
87 _ptr->setSuspensionTravel(travel);
88}
89
90/**
91 * Returns the suspension travel
92 */
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 */
105set_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 */
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 */
127set_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 */
138get_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 */
149set_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 */
160get_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 */
171set_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 */
182get_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 */
193set_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 */
204get_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 */
215set_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 */
225get_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 */
235set_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 */
253get_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 */
263set_suspension(const PhysxSpringDesc &spring) {
264
265 nassertv(_error_type == ET_ok);
266 return _ptr->setSuspension(spring._desc);
267}
Actors are the main simulation objects.
Definition physxActor.h:44
void set_name(const char *name)
Sets a name string for this object.
Describes a joint spring.
Descriptor class for PhysxWheelShape.
float get_axle_speed() const
Retrieves the current axle rotation speed.
float get_radius() const
Returns the radius of the sphere.
float get_suspension_travel() const
Returns the suspension travel.
void set_brake_torque(float torque)
Must be nonnegative.
void set_motor_torque(float torque)
Set the sum engine torque on the wheel axle.
float get_motor_torque() const
Retrieves the sum engine torque on the wheel axle.
void set_inverse_wheel_mass(float invMass)
Set the inverse mass of the wheel.
void save_to_desc(PhysxWheelShapeDesc &shapeDesc) const
Saves the state of the shape object to a descriptor.
float get_steer_angle() const
Retrieves the steering angle, around shape Y axis.
float get_brake_torque() const
Must be nonnegative.
bool get_wheel_flag(PhysxWheelShapeFlag flag) const
Returns the value of the specified wheel shape flag.
float get_steer_angle_rad() const
Retrieves the steering angle, around shape Y axis.
void set_steer_angle_rad(float angle)
Set the steering angle, around shape Y axis.
void set_wheel_flag(PhysxWheelShapeFlag flag, bool value)
Turns the specified wheel shape flag on or off.
float get_inverse_wheel_mass() const
Returns the inverse mass of the wheel.
void set_axle_speed(float speed)
Set the current axle rotation speed.
void set_steer_angle(float angle)
Set the steering angle, around shape Y axis.
void set_suspension(const PhysxSpringDesc &spring)
Set the data intended for car wheel suspension effects.
void set_radius(float radius)
Sets the sphere radius.
void set_suspension_travel(float travel)
Set the maximum extension distance of suspension along shape's -Y axis.
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.