Advertisement
Krisboss

only car data added

Feb 13th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.61 KB | None | 0 0
  1. #ifndef FRICTION_MAP_VEHICLE_RAYCAST_COLLIDE_H
  2. #define FRICTION_MAP_VEHICLE_RAYCAST_COLLIDE_H
  3.  
  4. #include <Physics/Vehicle/WheelCollide/RayCast/hkpVehicleRayCastWheelCollide.h>
  5. #include <Physics/Vehicle/hkpVehicleInstance.h>
  6. #include <Physics/Collide/Query/CastUtil/hkpWorldRayCastOutput.h>
  7.  
  8. extern const class hkClass FrictionMapVehicleRaycastWheelCollideClass;
  9.  
  10. #define VEHICLE_RAYCAST_ICY_FRICTION_PROPERTY 67341
  11.  
  12.     // This is the class which implements the calcSingleWheelGroundFriction, allowing you to override the
  13.     // ground friction calculation for raycast vehicles. Here, as a very simple example, we overwrite the friction to be
  14.     // 0.01 for all bodies (upon which we are driving) which have been tagged with a VEHICLE_RAYCAST_ICY_FRICTION_PROPERTY
  15.     // user property, otherwise we leave the friction as it is.
  16.     // In general of course, the friction value need not be constant over the body (or time), and any function can be used
  17.     // here, for example a lookup into your own full 2D 'friction map'.
  18.     // Other ways to store/retrieve friction values would be via:
  19.     //  hkpShape user data
  20.     //  A 'float' hkpProperty stored with a the rigid body
  21.     //  hkMeshMaterials for hkMeshShapes
  22.     //
  23.    
  24. class FrictionMapVehicleRaycastWheelCollide : public hkpVehicleRayCastWheelCollide
  25. {
  26.     public:
  27.         HK_DECLARE_CLASS_ALLOCATOR(HK_MEMORY_CLASS_BASE);
  28.  
  29.     private:
  30.         virtual void wheelCollideCallback( const hkpVehicleInstance* vehicle, hkUint8 wheelIndex, CollisionDetectionWheelOutput& cdInfo )
  31.         {
  32.             hkpRigidBody* rb = cdInfo.m_contactBody;
  33.             if ( rb )
  34.             {
  35.                 if ( rb->hasProperty(VEHICLE_RAYCAST_ICY_FRICTION_PROPERTY) )
  36.                 {
  37.                     cdInfo.m_contactFriction = 0.01f;
  38.                 }
  39.             }
  40.         }
  41.  
  42.     // Serialization.
  43.  
  44.     public:
  45.         // By adding HK_DECLARE_REFLECTION, we enable objects of this class to be serialized.
  46.         // However, the class does need to be registered with the type registry. The following code can be used:
  47.         // hkBuiltinTypeRegistry::getInstance().addType( &FrictionMapVehicleRaycastWheelCollideTypeInfo, &FrictionMapVehicleRaycastWheelCollideClass );
  48.         HK_DECLARE_REFLECTION();
  49.  
  50.         FrictionMapVehicleRaycastWheelCollide () { }
  51.  
  52.         FrictionMapVehicleRaycastWheelCollide ( hkFinishLoadedObjectFlag f ) : hkpVehicleRayCastWheelCollide( f ) { }
  53. };
  54.  
  55. #endif // FRICTION_MAP_VEHICLE_RAYCAST_COLLIDE_H
  56.  
  57.  
  58.  
  59. #ifndef HK_VEHICLE_SETUP_H
  60. #define HK_VEHICLE_SETUP_H
  61.  
  62. #include <Physics/Vehicle/hkpVehicleInstance.h>
  63.  
  64. #include <Physics/Vehicle/AeroDynamics/Default/hkpVehicleDefaultAerodynamics.h>
  65. #include <Physics/Vehicle/DriverInput/Default/hkpVehicleDefaultAnalogDriverInput.h>
  66. #include <Physics/Vehicle/Brake/Default/hkpVehicleDefaultBrake.h>
  67. #include <Physics/Vehicle/Engine/Default/hkpVehicleDefaultEngine.h>
  68. #include <Physics/Vehicle/VelocityDamper/Default/hkpVehicleDefaultVelocityDamper.h>
  69. #include <Physics/Vehicle/Steering/Default/hkpVehicleDefaultSteering.h>
  70. #include <Physics/Vehicle/Suspension/Default/hkpVehicleDefaultSuspension.h>
  71. #include <Physics/Vehicle/Transmission/Default/hkpVehicleDefaultTransmission.h>
  72. #include <Physics/Vehicle/WheelCollide/RayCast/hkpVehicleRayCastWheelCollide.h>
  73. #include <Physics/Vehicle/TyreMarks/hkpTyremarksInfo.h>
  74.  
  75.     /// This class just holds ALL the vehicle parameters (hardcoded) for an untuned, four
  76.     /// wheeled vehicle and facilitates construction via blueprints on a single call to
  77.     /// buildVehicle().
  78. class VehicleSetup : public hkReferencedObject
  79. {
  80.     public:
  81.  
  82.         HK_DECLARE_CLASS_ALLOCATOR( HK_MEMORY_CLASS_VEHICLE );
  83.  
  84.         VehicleSetup(){}
  85.  
  86.         virtual void buildVehicle( const hkpWorld* world, hkpVehicleInstance& vehicle );
  87.  
  88.     public:
  89.  
  90.         virtual void setupVehicleData( const hkpWorld* world, hkpVehicleData& data );
  91.         virtual void setupComponent( const hkpVehicleData& data, hkpVehicleDefaultAnalogDriverInput& driverInput );
  92.         virtual void setupComponent( const hkpVehicleData& data, hkpVehicleDefaultSteering& steering );
  93.         virtual void setupComponent( const hkpVehicleData& data, hkpVehicleDefaultEngine& engine );
  94.         virtual void setupComponent( const hkpVehicleData& data, hkpVehicleDefaultTransmission& transmission );
  95.         virtual void setupComponent( const hkpVehicleData& data, hkpVehicleDefaultBrake& brake );
  96.         virtual void setupComponent( const hkpVehicleData& data, hkpVehicleDefaultSuspension& suspension );
  97.         virtual void setupComponent( const hkpVehicleData& data, hkpVehicleDefaultAerodynamics& aerodynamics );
  98.         virtual void setupComponent( const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper );
  99.  
  100.         virtual void setupWheelCollide( const hkpWorld* world, const hkpVehicleInstance& vehicle, hkpVehicleRayCastWheelCollide& wheelCollide );
  101.         virtual void setupTyremarks( const hkpVehicleData& data, hkpTyremarksInfo& tyremarkscontroller );
  102. };
  103.  
  104. #endif // HK_VEHICLE_SETUP_H
  105.  
  106.  
  107.  
  108.  
  109.  
  110. void VehicleSetup::buildVehicle( const hkpWorld* world, hkpVehicleInstance& vehicle )
  111. {
  112.     //
  113.     // All memory allocations are made here.
  114.     //
  115.  
  116.     vehicle.m_data              = new hkpVehicleData;
  117.     vehicle.m_driverInput       = new hkpVehicleDefaultAnalogDriverInput;
  118.     vehicle.m_steering          = new hkpVehicleDefaultSteering;
  119.     vehicle.m_engine            = new hkpVehicleDefaultEngine;
  120.     vehicle.m_transmission      = new hkpVehicleDefaultTransmission;
  121.     vehicle.m_brake             = new hkpVehicleDefaultBrake;
  122.     vehicle.m_suspension        = new hkpVehicleDefaultSuspension;
  123.     vehicle.m_aerodynamics      = new hkpVehicleDefaultAerodynamics;
  124.     vehicle.m_velocityDamper    = new hkpVehicleDefaultVelocityDamper;
  125.  
  126.     // For illustrative purposes we use a custom hkpVehicleRayCastWheelCollide
  127.     // which implements varying 'ground' friction in a very simple way.
  128.     vehicle.m_wheelCollide      = new FrictionMapVehicleRaycastWheelCollide;
  129.  
  130.     setupVehicleData( world, *vehicle.m_data );
  131.  
  132.     // initialise the tyremarks controller with 128 tyremark points.
  133.     vehicle.m_tyreMarks     = new hkpTyremarksInfo( *vehicle.m_data, 128 );
  134.  
  135.     setupComponent( *vehicle.m_data, *static_cast< hkpVehicleDefaultAnalogDriverInput* >(vehicle.m_driverInput) );
  136.     setupComponent( *vehicle.m_data, *static_cast< hkpVehicleDefaultSteering*>(vehicle.m_steering));
  137.     setupComponent( *vehicle.m_data, *static_cast< hkpVehicleDefaultEngine*>(vehicle.m_engine) );
  138.     setupComponent( *vehicle.m_data, *static_cast< hkpVehicleDefaultTransmission*>(vehicle.m_transmission) );
  139.     setupComponent( *vehicle.m_data, *static_cast< hkpVehicleDefaultBrake*>(vehicle.m_brake) );
  140.     setupComponent( *vehicle.m_data, *static_cast< hkpVehicleDefaultSuspension*>(vehicle.m_suspension) );
  141.     setupComponent( *vehicle.m_data, *static_cast< hkpVehicleDefaultAerodynamics*>(vehicle.m_aerodynamics) );
  142.     setupComponent( *vehicle.m_data, *static_cast< hkpVehicleDefaultVelocityDamper*>(vehicle.m_velocityDamper) );
  143.  
  144.     setupWheelCollide( world, vehicle, *static_cast< hkpVehicleRayCastWheelCollide*>(vehicle.m_wheelCollide) );
  145.  
  146.     setupTyremarks( *vehicle.m_data, *static_cast< hkpTyremarksInfo*>(vehicle.m_tyreMarks) );
  147.  
  148.     //
  149.     // Check that all components are present.
  150.     //
  151.     HK_ASSERT(0x0, vehicle.m_data );
  152.     HK_ASSERT(0x7708674a,  vehicle.m_driverInput );
  153.     HK_ASSERT(0x5a324a2d,  vehicle.m_steering );
  154.     HK_ASSERT(0x7bcb2aff,  vehicle.m_engine );
  155.     HK_ASSERT(0x29bddb50,  vehicle.m_transmission );
  156.     HK_ASSERT(0x2b0323a2,  vehicle.m_brake );
  157.     HK_ASSERT(0x7a7ade23,  vehicle.m_suspension );
  158.     HK_ASSERT(0x6ec4d0ed,  vehicle.m_aerodynamics );
  159.     HK_ASSERT(0x67161206,  vehicle.m_wheelCollide );
  160.     HK_ASSERT(0x295015f1,  vehicle.m_tyreMarks );
  161.  
  162.     //
  163.     // Set up any variables that store cached data.
  164.     //
  165.  
  166.  
  167.     // Give driver input default values so that the vehicle (if this input is a default for non
  168.     // player cars) will drive, even if it is in circles!
  169.  
  170.     // Accelerate.
  171.     vehicle.m_deviceStatus = new hkpVehicleDriverInputAnalogStatus;
  172.     hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)vehicle.m_deviceStatus;
  173.     deviceStatus->m_positionY = -0.4f;
  174.  
  175.     // Turn.
  176.     deviceStatus->m_positionX = 0.3f;
  177.  
  178.     // Defaults
  179.     deviceStatus->m_handbrakeButtonPressed = false;
  180.     deviceStatus->m_reverseButtonPressed = false;
  181.  
  182.  
  183.     //
  184.     // Don't forget to call init! (This function is necessary to set up derived data)
  185.     //
  186.     vehicle.init();
  187. }
  188.  
  189. void VehicleSetup::setupVehicleData( const hkpWorld* world, hkpVehicleData& data )
  190. {
  191.     data.m_gravity = world->getGravity();
  192.  
  193.     //
  194.     // The vehicleData contains information about the chassis.
  195.     //
  196.  
  197.     // The coordinates of the chassis system, used for steering the vehicle.
  198.     //                                      up                  forward             right
  199.     data.m_chassisOrientation.setCols( hkVector4(0, 1, 0), hkVector4(1, 0, 0), hkVector4(0, 0, 1));
  200.  
  201.     data.m_frictionEqualizer = 0.5f;
  202.  
  203.  
  204.     // Inertia tensor for each axis is calculated by using :
  205.     // (1 / chassis_mass) * (torque(axis)Factor / chassisUnitInertia)
  206.     data.m_torqueRollFactor = 0.625f;
  207.     data.m_torquePitchFactor = 0.5f;
  208.     data.m_torqueYawFactor = 0.35f;
  209.  
  210.     data.m_chassisUnitInertiaYaw = 1.0f;
  211.     data.m_chassisUnitInertiaRoll = 1.0f;
  212.     data.m_chassisUnitInertiaPitch = 1.0f;
  213.  
  214.     // Adds or removes torque around the yaw axis
  215.     // based on the current steering angle.  This will
  216.     // affect steering.
  217.     data.m_extraTorqueFactor = -0.5f;
  218.     data.m_maxVelocityForPositionalFriction = 0.0f;
  219.  
  220.     //
  221.     // Wheel specifications
  222.     //
  223.     data.m_numWheels = 4;
  224.  
  225.     data.m_wheelParams.setSize( data.m_numWheels );
  226.  
  227.     data.m_wheelParams[0].m_axle = 0;
  228.     data.m_wheelParams[1].m_axle = 0;
  229.     data.m_wheelParams[2].m_axle = 1;
  230.     data.m_wheelParams[3].m_axle = 1;
  231.  
  232.     data.m_wheelParams[0].m_friction = 1.5f;
  233.     data.m_wheelParams[1].m_friction = 1.5f;
  234.     data.m_wheelParams[2].m_friction = 1.5f;
  235.     data.m_wheelParams[3].m_friction = 1.5f;
  236.  
  237.     data.m_wheelParams[0].m_slipAngle = 0.0f;
  238.     data.m_wheelParams[1].m_slipAngle = 0.0f;
  239.     data.m_wheelParams[2].m_slipAngle = 0.0f;
  240.     data.m_wheelParams[3].m_slipAngle = 0.0f;
  241.  
  242.     for ( int i = 0 ; i < data.m_numWheels ; i++ )
  243.     {
  244.         // This value is also used to calculate the m_primaryTransmissionRatio.
  245.         data.m_wheelParams[i].m_radius = 0.4f;
  246.         data.m_wheelParams[i].m_width = 0.2f;
  247.         data.m_wheelParams[i].m_mass = 10.0f;
  248.  
  249.         data.m_wheelParams[i].m_viscosityFriction = 0.25f;
  250.         data.m_wheelParams[i].m_maxFriction = 2.0f * data.m_wheelParams[i].m_friction;
  251.         data.m_wheelParams[i].m_forceFeedbackMultiplier = 0.1f;
  252.         data.m_wheelParams[i].m_maxContactBodyAcceleration = hkReal(data.m_gravity.length3()) * 2;
  253.     }
  254. }
  255.  
  256.  
  257. void VehicleSetup::setupComponent( const hkpVehicleData& data, hkpVehicleDefaultAnalogDriverInput& driverInput )
  258. {
  259.     // We also use an analog "driver input" class to help converting user input to vehicle behavior.
  260.  
  261.     driverInput.m_slopeChangePointX = 0.8f;
  262.     driverInput.m_initialSlope = 0.7f;
  263.     driverInput.m_deadZone = 0.0f;
  264.     driverInput.m_autoReverse = true;
  265. }
  266.  
  267. void VehicleSetup::setupComponent( const hkpVehicleData& data, hkpVehicleDefaultSteering& steering )
  268. {  
  269.     steering.m_doesWheelSteer.setSize( data.m_numWheels );
  270.  
  271.     // degrees
  272.     steering.m_maxSteeringAngle = 35 * ( HK_REAL_PI / 180 );
  273.  
  274.     // [mph/h] The steering angle decreases linearly
  275.     // based on your overall max speed of the vehicle.
  276.     steering.m_maxSpeedFullSteeringAngle = 70.0f * (1.605f / 3.6f);
  277.     steering.m_doesWheelSteer[0] = true;
  278.     steering.m_doesWheelSteer[1] = true;
  279.     steering.m_doesWheelSteer[2] = false;
  280.     steering.m_doesWheelSteer[3] = false;
  281. }
  282.  
  283. void VehicleSetup::setupComponent( const hkpVehicleData& data, hkpVehicleDefaultEngine& engine )
  284. {
  285.     engine.m_maxTorque = 500.0f;
  286.  
  287.     engine.m_minRPM = 1000.0f;
  288.     engine.m_optRPM = 5500.0f;
  289.  
  290.     // This value is also used to calculate the m_primaryTransmissionRatio.
  291.     engine.m_maxRPM = 7500.0f;
  292.  
  293.     engine.m_torqueFactorAtMinRPM = 0.8f;
  294.     engine.m_torqueFactorAtMaxRPM = 0.8f;
  295.  
  296.     engine.m_resistanceFactorAtMinRPM = 0.05f;
  297.     engine.m_resistanceFactorAtOptRPM = 0.1f;
  298.     engine.m_resistanceFactorAtMaxRPM = 0.3f;
  299. }
  300.  
  301. void VehicleSetup::setupComponent( const hkpVehicleData& data, hkpVehicleDefaultTransmission& transmission )
  302. {
  303.     int numGears = 4;
  304.  
  305.     transmission.m_gearsRatio.setSize( numGears );
  306.     transmission.m_wheelsTorqueRatio.setSize( data.m_numWheels );
  307.  
  308.     transmission.m_downshiftRPM = 3500.0f;
  309.     transmission.m_upshiftRPM = 6500.0f;
  310.  
  311.     transmission.m_clutchDelayTime = 0.0f;
  312.     transmission.m_reverseGearRatio = 1.0f;
  313.     transmission.m_gearsRatio[0] = 2.0f;
  314.     transmission.m_gearsRatio[1] = 1.5f;
  315.     transmission.m_gearsRatio[2] = 1.0f;
  316.     transmission.m_gearsRatio[3] = 0.75f;
  317.     transmission.m_wheelsTorqueRatio[0] = 0.2f;
  318.     transmission.m_wheelsTorqueRatio[1] = 0.2f;
  319.     transmission.m_wheelsTorqueRatio[2] = 0.3f;
  320.     transmission.m_wheelsTorqueRatio[3] = 0.3f;
  321.  
  322.     const hkReal vehicleTopSpeed = 130.0f;  
  323.     const hkReal wheelRadius = 0.4f;
  324.     const hkReal maxEngineRpm = 7500.0f;
  325.     transmission.m_primaryTransmissionRatio = hkpVehicleDefaultTransmission::calculatePrimaryTransmissionRatio( vehicleTopSpeed,
  326.                                                                                                                 wheelRadius,
  327.                                                                                                                 maxEngineRpm,
  328.                                                                                                                 transmission.m_gearsRatio[ numGears - 1 ] );
  329. }
  330.  
  331. void VehicleSetup::setupComponent( const hkpVehicleData& data, hkpVehicleDefaultBrake& brake )
  332. {
  333.     brake.m_wheelBrakingProperties.setSize( data.m_numWheels );
  334.  
  335.     const float bt = 1500.0f;
  336.     brake.m_wheelBrakingProperties[0].m_maxBreakingTorque = bt;
  337.     brake.m_wheelBrakingProperties[1].m_maxBreakingTorque = bt;
  338.     brake.m_wheelBrakingProperties[2].m_maxBreakingTorque = bt;
  339.     brake.m_wheelBrakingProperties[3].m_maxBreakingTorque = bt;
  340.  
  341.     // Handbrake is attached to rear wheels only.
  342.     brake.m_wheelBrakingProperties[0].m_isConnectedToHandbrake = false;
  343.     brake.m_wheelBrakingProperties[1].m_isConnectedToHandbrake = false;
  344.     brake.m_wheelBrakingProperties[2].m_isConnectedToHandbrake = true;
  345.     brake.m_wheelBrakingProperties[3].m_isConnectedToHandbrake = true;
  346.     brake.m_wheelBrakingProperties[0].m_minPedalInputToBlock = 0.9f;
  347.     brake.m_wheelBrakingProperties[1].m_minPedalInputToBlock = 0.9f;
  348.     brake.m_wheelBrakingProperties[2].m_minPedalInputToBlock = 0.9f;
  349.     brake.m_wheelBrakingProperties[3].m_minPedalInputToBlock = 0.9f;
  350.     brake.m_wheelsMinTimeToBlock = 1000.0f;
  351. }
  352.  
  353. void VehicleSetup::setupComponent( const hkpVehicleData& data, hkpVehicleDefaultSuspension& suspension )
  354. {
  355.     suspension.m_wheelParams.setSize( data.m_numWheels );
  356.     suspension.m_wheelSpringParams.setSize( data.m_numWheels );
  357.  
  358.     suspension.m_wheelParams[0].m_length = 0.35f;
  359.     suspension.m_wheelParams[1].m_length = 0.35f;
  360.     suspension.m_wheelParams[2].m_length = 0.35f;
  361.     suspension.m_wheelParams[3].m_length = 0.35f;
  362.  
  363.     const float str = 50.0f;
  364.     suspension.m_wheelSpringParams[0].m_strength = str;
  365.     suspension.m_wheelSpringParams[1].m_strength = str;
  366.     suspension.m_wheelSpringParams[2].m_strength = str;
  367.     suspension.m_wheelSpringParams[3].m_strength = str;
  368.  
  369.     const float wd = 3.0f;
  370.     suspension.m_wheelSpringParams[0].m_dampingCompression = wd;
  371.     suspension.m_wheelSpringParams[1].m_dampingCompression = wd;
  372.     suspension.m_wheelSpringParams[2].m_dampingCompression = wd;
  373.     suspension.m_wheelSpringParams[3].m_dampingCompression = wd;
  374.  
  375.     suspension.m_wheelSpringParams[0].m_dampingRelaxation = wd;
  376.     suspension.m_wheelSpringParams[1].m_dampingRelaxation = wd;
  377.     suspension.m_wheelSpringParams[2].m_dampingRelaxation = wd;
  378.     suspension.m_wheelSpringParams[3].m_dampingRelaxation = wd;
  379.    
  380.     //
  381.     // NB: The hardpoints MUST be positioned INSIDE the chassis.
  382.     //
  383.     {
  384.         const hkReal hardPointFrontX = 1.3f;
  385.         const hkReal hardPointBackX = -1.1f;
  386.         const hkReal hardPointY = -0.05f;
  387.         const hkReal hardPointZ = 1.1f;
  388.  
  389.         suspension.m_wheelParams[0].m_hardpointChassisSpace.set ( hardPointFrontX, hardPointY, -hardPointZ);
  390.         suspension.m_wheelParams[1].m_hardpointChassisSpace.set ( hardPointFrontX, hardPointY,  hardPointZ);
  391.         suspension.m_wheelParams[2].m_hardpointChassisSpace.set ( hardPointBackX, hardPointY, -hardPointZ);
  392.         suspension.m_wheelParams[3].m_hardpointChassisSpace.set ( hardPointBackX, hardPointY,  hardPointZ);
  393.     }
  394.  
  395.     const hkVector4 downDirection( 0.0f, -1.0f, 0.0f );
  396.     suspension.m_wheelParams[0].m_directionChassisSpace = downDirection;
  397.     suspension.m_wheelParams[1].m_directionChassisSpace = downDirection;
  398.     suspension.m_wheelParams[2].m_directionChassisSpace = downDirection;
  399.     suspension.m_wheelParams[3].m_directionChassisSpace = downDirection;
  400. }
  401.  
  402. void VehicleSetup::setupComponent( const hkpVehicleData& data, hkpVehicleDefaultAerodynamics& aerodynamics )
  403. {
  404.     aerodynamics.m_airDensity = 1.3f;
  405.     // In m^2.
  406.     aerodynamics.m_frontalArea = 1.0f; 
  407.  
  408.     aerodynamics.m_dragCoefficient = 0.7f;
  409.     aerodynamics.m_liftCoefficient = -0.3f;
  410.  
  411.     // Extra gavity applies in world space (independent of m_chassisCoordinateSystem).
  412.     aerodynamics.m_extraGravityws.set( 0.0f, -5.0f, 0.0f);
  413. }
  414.  
  415. void VehicleSetup::setupComponent( const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper )
  416. {
  417.     // Caution: setting negative damping values will add energy to system.
  418.     // Setting the value to 0 will not affect the angular velocity.
  419.  
  420.     // Damping the change of the chassis angular velocity when below m_collisionThreshold.
  421.     // This will affect turning radius and steering.
  422.     velocityDamper.m_normalSpinDamping    = 0.0f;
  423.  
  424.     // Positive numbers dampen the rotation of the chassis and
  425.     // reduce the reaction of the chassis in a collision.
  426.     velocityDamper.m_collisionSpinDamping = 4.0f;
  427.  
  428.     // The threshold in m/s at which the algorithm switches from
  429.     // using the normalSpinDamping to the collisionSpinDamping.    
  430.     velocityDamper.m_collisionThreshold   = 1.0f;
  431. }
  432.  
  433. void VehicleSetup::setupWheelCollide( const hkpWorld* world, const hkpVehicleInstance& vehicle, hkpVehicleRayCastWheelCollide& wheelCollide )
  434. {
  435.     // Set the wheels to have the same collision filter info as the chassis.
  436.     wheelCollide.m_wheelCollisionFilterInfo = vehicle.getChassis()->getCollisionFilterInfo();
  437. }
  438.  
  439. void VehicleSetup::setupTyremarks( const hkpVehicleData& data, hkpTyremarksInfo& tyreMarks )
  440. {
  441.     tyreMarks.m_minTyremarkEnergy = 100.0f;
  442.     tyreMarks.m_maxTyremarkEnergy  = 1000.0f;
  443. }
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455. hkpConvexVerticesShape* createCarChassisShape()
  456. {
  457.     hkReal xSize = 1.75f;
  458.     hkReal ySize = 0.25f;
  459.     hkReal zSize = 1.1f;
  460.  
  461.     hkReal xBumper = 1.9f;
  462.     hkReal yBumper = 0.15f;
  463.     hkReal zBumper = 1.0f;
  464.  
  465.     hkReal xRoofFront = 0.4f;
  466.     hkReal xRoofBack = -1.0f;
  467.     hkReal yRoof = ySize + 0.45f;
  468.     hkReal zRoof = 0.7f;
  469.  
  470.     hkReal xDoorFront = xRoofFront;
  471.     hkReal xDoorBack = xRoofBack;
  472.     hkReal yDoor = ySize;
  473.     hkReal zDoor = zSize + 0.1f;
  474.  
  475.     int numVertices = 22;
  476.  
  477.     // 16 = 4 (size of "each float group", 3 for x,y,z, 1 for padding) * 4 (size of float).
  478.     int stride = sizeof(hkReal) * 4;
  479.  
  480.     HK_ALIGN16(hkReal vertices[] )= {
  481.         xSize, ySize, zSize, 0.0f,      // v0
  482.         xSize, ySize, -zSize, 0.0f,     // v1
  483.         xSize, -ySize, zSize, 0.0f,     // v2
  484.         xSize, -ySize, -zSize, 0.0f,    // v3
  485.         -xSize, -ySize, zSize, 0.0f,    // v4
  486.         -xSize, -ySize, -zSize, 0.0f,   // v5
  487.  
  488.         xBumper, yBumper, zBumper, 0.0f,    // v6
  489.         xBumper, yBumper, -zBumper, 0.0f,   // v7
  490.         -xBumper, yBumper, zBumper, 0.0f,   // v8
  491.         -xBumper, yBumper, -zBumper, 0.0f// v9
  492.  
  493.         xRoofFront, yRoof, zRoof, 0.0f,     // v10
  494.         xRoofFront, yRoof, -zRoof, 0.0f,    // v11
  495.         xRoofBack, yRoof, zRoof, 0.0f,      // v12
  496.         xRoofBack, yRoof, -zRoof, 0.0f,     // v13
  497.  
  498.         xDoorFront, yDoor, zDoor, 0.0f,     // v14
  499.         xDoorFront, yDoor, -zDoor, 0.0f,    // v15
  500.         xDoorFront, -yDoor, zDoor, 0.0f,    // v16
  501.         xDoorFront, -yDoor, -zDoor, 0.0f,   // v17
  502.  
  503.         xDoorBack, yDoor, zDoor, 0.0f,      // v18
  504.         xDoorBack, yDoor, -zDoor, 0.0f,     // v19
  505.         xDoorBack, -yDoor, zDoor, 0.0f,     // v20
  506.         xDoorBack, -yDoor, -zDoor, 0.0f,    // v21
  507.     };
  508.    
  509.     //
  510.     // SHAPE CONSTRUCTION.
  511.     //
  512.    
  513.     hkStridedVertices       stridedVerts;
  514.     stridedVerts.m_numVertices  =   numVertices;
  515.     stridedVerts.m_striding     =   stride;
  516.     stridedVerts.m_vertices     =   vertices;
  517.    
  518.     return new hkpConvexVerticesShape(stridedVerts);
  519. }
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.     hkpVehicleInstance* m_vehicle;
  537.     hkpConvexVerticesShape* chassisShape = createCarChassisShape();
  538.     //          hkpSphereShape* chassisShape = new hkpSphereShape(0.15f);
  539. //  hkpRigidBody* chassis;
  540.     hkpRigidBody* chassisRigidBody;
  541.  
  542. void Pojazd()
  543. {
  544.  
  545.         {
  546.         hkpRigidBodyCinfo chassisInfo;
  547.  
  548.         chassisInfo.m_mass = 750.0f;   
  549.         chassisInfo.m_shape = chassisShape;
  550.         chassisInfo.m_friction = 0.4f;
  551.  
  552.         chassisInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
  553.         chassisInfo.m_position.set(0.0f, 1.0f, 0.0f);
  554.         hkpInertiaTensorComputer::setShapeVolumeMassProperties(chassisInfo.m_shape,
  555.                                         chassisInfo.m_mass,
  556.                                         chassisInfo);
  557.  
  558.         chassisRigidBody = new hkpRigidBody(chassisInfo);
  559.  
  560.         // No longer need reference to shape as the hkpRigidBody holds one.
  561.         chassisShape->removeReference();
  562.  
  563.         m_world->addEntity(chassisRigidBody);
  564.     }
  565.  
  566.         //  createVehicle( chassisRigidBody );
  567.    
  568.  
  569.  
  570.     m_vehicle = new hkpVehicleInstance( chassisRigidBody );
  571.  
  572.  
  573.     VehicleSetup setup;
  574.     setup.buildVehicle( m_world, *m_vehicle );
  575.  
  576.     m_vehicle->addToWorld( m_world );
  577.  
  578.     m_world->addAction(m_vehicle);
  579.  
  580.  
  581.     chassisRigidBody->removeReference();
  582.  
  583. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement