Panda3D

physxWheelShape.cxx

00001 // Filename: physxWheelShape.cxx
00002 // Created by:  enn0x (09Nov09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "physxWheelShape.h"
00016 #include "physxWheelShapeDesc.h"
00017 #include "physxSpringDesc.h"
00018 
00019 TypeHandle PhysxWheelShape::_type_handle;
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: PhysxWheelShape::link
00023 //       Access: Public
00024 //  Description: 
00025 ////////////////////////////////////////////////////////////////////
00026 void PhysxWheelShape::
00027 link(NxShape *shapePtr) {
00028 
00029   _ptr = shapePtr->isWheel();
00030   _ptr->userData = this;
00031   _error_type = ET_ok;
00032 
00033   set_name(shapePtr->getName());
00034 
00035   PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData;
00036   actor->_shapes.add(this);
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: PhysxWheelShape::unlink
00041 //       Access: Public
00042 //  Description: 
00043 ////////////////////////////////////////////////////////////////////
00044 void PhysxWheelShape::
00045 unlink() {
00046 
00047   _ptr->userData = NULL;
00048   _error_type = ET_released;
00049 
00050   PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData;
00051   actor->_shapes.remove(this);
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function : PhysxWheelShape::save_to_desc
00056 //       Access : Published
00057 //  Description : Saves the state of the shape object to a 
00058 //                descriptor.
00059 ////////////////////////////////////////////////////////////////////
00060 void PhysxWheelShape::
00061 save_to_desc(PhysxWheelShapeDesc &shapeDesc) const {
00062 
00063   nassertv(_error_type == ET_ok);
00064   _ptr->saveToDesc(shapeDesc._desc);
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: PhysxWheelShape::set_radius
00069 //       Access: Published
00070 //  Description: Sets the sphere radius. 
00071 ////////////////////////////////////////////////////////////////////
00072 void PhysxWheelShape::
00073 set_radius(float radius) {
00074 
00075   nassertv(_error_type == ET_ok);
00076   _ptr->setRadius(radius);
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: PhysxWheelShape::get_radius
00081 //       Access: Published
00082 //  Description: Returns the radius of the sphere.
00083 ////////////////////////////////////////////////////////////////////
00084 float PhysxWheelShape::
00085 get_radius() const {
00086 
00087   nassertr(_error_type == ET_ok, 0.0f);
00088   return _ptr->getRadius();
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: PhysxWheelShape::set_suspension_travel
00093 //       Access: Published
00094 //  Description: Set the maximum extension distance of suspension
00095 //               along shape's -Y axis. The minimum extension is
00096 //               always 0.
00097 ////////////////////////////////////////////////////////////////////
00098 void PhysxWheelShape::
00099 set_suspension_travel(float travel) {
00100 
00101   nassertv(_error_type == ET_ok);
00102   _ptr->setSuspensionTravel(travel);
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: PhysxWheelShape::get_suspension_travel
00107 //       Access: Published
00108 //  Description: Returns the suspension travel
00109 ////////////////////////////////////////////////////////////////////
00110 float PhysxWheelShape::
00111 get_suspension_travel() const {
00112 
00113   nassertr(_error_type == ET_ok, 0.0f);
00114   return _ptr->getSuspensionTravel();
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: PhysxWheelShape::set_inverse_wheel_mass
00119 //       Access: Published
00120 //  Description: Set the inverse mass of the wheel. Determines the
00121 //               wheel velocity that wheel torques can achieve.
00122 ////////////////////////////////////////////////////////////////////
00123 void PhysxWheelShape::
00124 set_inverse_wheel_mass(float invMass) {
00125 
00126   nassertv(_error_type == ET_ok);
00127   _ptr->setInverseWheelMass(invMass);
00128 }
00129 
00130 ////////////////////////////////////////////////////////////////////
00131 //     Function: PhysxWheelShape::get_inverse_wheel_mass
00132 //       Access: Published
00133 //  Description: Returns the inverse mass of the wheel. Determines
00134 //               the wheel velocity that wheel torques can achieve.
00135 ////////////////////////////////////////////////////////////////////
00136 float PhysxWheelShape::
00137 get_inverse_wheel_mass() const {
00138 
00139   nassertr(_error_type == ET_ok, 0.0f);
00140   return _ptr->getInverseWheelMass();
00141 }
00142 
00143 ////////////////////////////////////////////////////////////////////
00144 //     Function: PhysxWheelShape::set_motor_torque
00145 //       Access: Published
00146 //  Description: Set the sum engine torque on the wheel axle.
00147 //               Positive or negative depending on direction 
00148 ////////////////////////////////////////////////////////////////////
00149 void PhysxWheelShape::
00150 set_motor_torque(float torque) {
00151 
00152   nassertv(_error_type == ET_ok);
00153   _ptr->setMotorTorque(torque);
00154 }
00155 
00156 ////////////////////////////////////////////////////////////////////
00157 //     Function: PhysxWheelShape::get_motor_torque
00158 //       Access: Published
00159 //  Description: Retrieves the sum engine torque on the wheel axle.
00160 //               Positive or negative depending on direction
00161 ////////////////////////////////////////////////////////////////////
00162 float PhysxWheelShape::
00163 get_motor_torque() const {
00164 
00165   nassertr(_error_type == ET_ok, 0.0f);
00166   return _ptr->getMotorTorque();
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: PhysxWheelShape::set_brake_torque
00171 //       Access: Published
00172 //  Description: Must be nonnegative. Very large values should lock
00173 //               wheel but should be stable.
00174 ////////////////////////////////////////////////////////////////////
00175 void PhysxWheelShape::
00176 set_brake_torque(float torque) {
00177 
00178   nassertv(_error_type == ET_ok);
00179   _ptr->setBrakeTorque(torque);
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: PhysxWheelShape::get_brake_torque
00184 //       Access: Published
00185 //  Description: Must be nonnegative. Very large values should lock
00186 //               wheel but should be stable.
00187 ////////////////////////////////////////////////////////////////////
00188 float PhysxWheelShape::
00189 get_brake_torque() const {
00190 
00191   nassertr(_error_type == ET_ok, 0.0f);
00192   return _ptr->getBrakeTorque();
00193 }
00194 
00195 ////////////////////////////////////////////////////////////////////
00196 //     Function: PhysxWheelShape::set_steer_angle
00197 //       Access: Published
00198 //  Description: Set the steering angle, around shape Y axis.
00199 //               The steering angle is measured in degrees.
00200 ////////////////////////////////////////////////////////////////////
00201 void PhysxWheelShape::
00202 set_steer_angle(float angle) {
00203 
00204   nassertv(_error_type == ET_ok);
00205   _ptr->setSteerAngle(NxMath::degToRad(-1.0f * angle));
00206 }
00207 
00208 ////////////////////////////////////////////////////////////////////
00209 //     Function: PhysxWheelShape::get_steer_angle
00210 //       Access: Published
00211 //  Description: Retrieves the steering angle, around shape Y axis.
00212 //               The steering angle is measured in degrees.
00213 ////////////////////////////////////////////////////////////////////
00214 float PhysxWheelShape::
00215 get_steer_angle() const {
00216 
00217   nassertr(_error_type == ET_ok, 0.0f);
00218   return -1.0f * NxMath::radToDeg(_ptr->getSteerAngle());
00219 }
00220 
00221 ////////////////////////////////////////////////////////////////////
00222 //     Function: PhysxWheelShape::set_steer_angle_rad
00223 //       Access: Published
00224 //  Description: Set the steering angle, around shape Y axis.
00225 //               The steering angle is measured in radians.
00226 ////////////////////////////////////////////////////////////////////
00227 void PhysxWheelShape::
00228 set_steer_angle_rad(float angle) {
00229 
00230   nassertv(_error_type == ET_ok);
00231   _ptr->setSteerAngle(-1.0f * angle);
00232 }
00233 
00234 ////////////////////////////////////////////////////////////////////
00235 //     Function: PhysxWheelShape::get_steer_angle_rad
00236 //       Access: Published
00237 //  Description: Retrieves the steering angle, around shape Y axis.
00238 //               The steering angle is measured in radians.
00239 ////////////////////////////////////////////////////////////////////
00240 float PhysxWheelShape::
00241 get_steer_angle_rad() const {
00242 
00243   nassertr(_error_type == ET_ok, 0.0f);
00244   return -1.0f * _ptr->getSteerAngle();
00245 }
00246 
00247 ////////////////////////////////////////////////////////////////////
00248 //     Function: PhysxWheelShape::set_axle_speed
00249 //       Access: Published
00250 //  Description: Set the current axle rotation speed.
00251 //               Note: WSF_axle_speed_override flag must be raised
00252 //               for this to have effect! 
00253 ////////////////////////////////////////////////////////////////////
00254 void PhysxWheelShape::
00255 set_axle_speed(float speed) {
00256 
00257   nassertv(_error_type == ET_ok);
00258   _ptr->setAxleSpeed(speed);
00259 }
00260 
00261 ////////////////////////////////////////////////////////////////////
00262 //     Function: PhysxWheelShape::get_axle_speed
00263 //       Access: Published
00264 //  Description: Retrieves the current axle rotation speed.
00265 ////////////////////////////////////////////////////////////////////
00266 float PhysxWheelShape::
00267 get_axle_speed() const {
00268 
00269   nassertr(_error_type == ET_ok, 0.0f);
00270   return _ptr->getAxleSpeed();
00271 }
00272 
00273 ////////////////////////////////////////////////////////////////////
00274 //     Function: PhysxWheelShape::set_wheel_flag
00275 //       Access: Published
00276 //  Description: Turns the specified wheel shape flag on or off.
00277 ////////////////////////////////////////////////////////////////////
00278 void PhysxWheelShape::
00279 set_wheel_flag(PhysxWheelShapeFlag flag, bool value) {
00280 
00281   nassertv(_error_type == ET_ok);
00282   NxU32 flags = _ptr->getWheelFlags();
00283 
00284   if (value == true) {
00285     flags |= flag;
00286   } else {
00287     flags &= ~(flag);
00288   }
00289 
00290   _ptr->setWheelFlags(flags);
00291 }
00292 
00293 ////////////////////////////////////////////////////////////////////
00294 //     Function: PhysxWheelShape::get_wheel_flag
00295 //       Access: Published
00296 //  Description: Returns the value of the specified wheel shape
00297 //               flag.
00298 ////////////////////////////////////////////////////////////////////
00299 bool PhysxWheelShape::
00300 get_wheel_flag(PhysxWheelShapeFlag flag) const {
00301 
00302   nassertr(_error_type == ET_ok, false);
00303   return (_ptr->getWheelFlags() & flag) ? true : false;
00304 }
00305 
00306 ////////////////////////////////////////////////////////////////////
00307 //     Function: PhysxWheelShape::set_suspension
00308 //       Access: Published
00309 //  Description: Set the data intended for car wheel suspension
00310 //               effects.
00311 ////////////////////////////////////////////////////////////////////
00312 void PhysxWheelShape::
00313 set_suspension(const PhysxSpringDesc &spring) {
00314 
00315   nassertv(_error_type == ET_ok);
00316   return _ptr->setSuspension(spring._desc);
00317 }
00318 
 All Classes Functions Variables Enumerations