Logo Search packages:      
Sourcecode: blender version File versions

btScalar btRaycastVehicle::rayCast ( btWheelInfo wheel  ) 

Todo:
for driving on dynamic/movable objects!;

Definition at line 158 of file btRaycastVehicle.cpp.

References btVehicleRaycaster::castRay(), btRigidBody::getCenterOfMassPosition(), btWheelInfo::getSuspensionRestLength(), btRigidBody::getVelocityInLocalPoint(), btWheelInfo::m_clippedInvContactDotSuspension, btWheelInfo::m_maxSuspensionTravelCm, btWheelInfo::m_raycastInfo, btWheelInfo::m_suspensionRelativeVelocity, and btWheelInfo::m_wheelsRadius.

{
      updateWheelTransformsWS( wheel,false);

      
      btScalar depth = -1;
      
      btScalar raylen = wheel.getSuspensionRestLength()+wheel.m_wheelsRadius;

      btVector3 rayvector = wheel.m_raycastInfo.m_wheelDirectionWS * (raylen);
      const btVector3& source = wheel.m_raycastInfo.m_hardPointWS;
      wheel.m_raycastInfo.m_contactPointWS = source + rayvector;
      const btVector3& target = wheel.m_raycastInfo.m_contactPointWS;

      btScalar param = btScalar(0.);
      
      btVehicleRaycaster::btVehicleRaycasterResult    rayResults;

      btAssert(m_vehicleRaycaster);

      void* object = m_vehicleRaycaster->castRay(source,target,rayResults);

      wheel.m_raycastInfo.m_groundObject = 0;

      if (object)
      {
            param = rayResults.m_distFraction;
            depth = raylen * rayResults.m_distFraction;
            wheel.m_raycastInfo.m_contactNormalWS  = rayResults.m_hitNormalInWorld;
            wheel.m_raycastInfo.m_isInContact = true;
            
            wheel.m_raycastInfo.m_groundObject = &s_fixedObject;///@todo for driving on dynamic/movable objects!;
            //wheel.m_raycastInfo.m_groundObject = object;


            btScalar hitDistance = param*raylen;
            wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelsRadius;
            //clamp on max suspension travel

            btScalar  minSuspensionLength = wheel.getSuspensionRestLength() - wheel.m_maxSuspensionTravelCm*btScalar(0.01);
            btScalar maxSuspensionLength = wheel.getSuspensionRestLength()+ wheel.m_maxSuspensionTravelCm*btScalar(0.01);
            if (wheel.m_raycastInfo.m_suspensionLength < minSuspensionLength)
            {
                  wheel.m_raycastInfo.m_suspensionLength = minSuspensionLength;
            }
            if (wheel.m_raycastInfo.m_suspensionLength > maxSuspensionLength)
            {
                  wheel.m_raycastInfo.m_suspensionLength = maxSuspensionLength;
            }

            wheel.m_raycastInfo.m_contactPointWS = rayResults.m_hitPointInWorld;

            btScalar denominator= wheel.m_raycastInfo.m_contactNormalWS.dot( wheel.m_raycastInfo.m_wheelDirectionWS );

            btVector3 chassis_velocity_at_contactPoint;
            btVector3 relpos = wheel.m_raycastInfo.m_contactPointWS-getRigidBody()->getCenterOfMassPosition();

            chassis_velocity_at_contactPoint = getRigidBody()->getVelocityInLocalPoint(relpos);

            btScalar projVel = wheel.m_raycastInfo.m_contactNormalWS.dot( chassis_velocity_at_contactPoint );

            if ( denominator >= btScalar(-0.1))
            {
                  wheel.m_suspensionRelativeVelocity = btScalar(0.0);
                  wheel.m_clippedInvContactDotSuspension = btScalar(1.0) / btScalar(0.1);
            }
            else
            {
                  btScalar inv = btScalar(-1.) / denominator;
                  wheel.m_suspensionRelativeVelocity = projVel * inv;
                  wheel.m_clippedInvContactDotSuspension = inv;
            }
                  
      } else
      {
            //put wheel info as in rest position
            wheel.m_raycastInfo.m_suspensionLength = wheel.getSuspensionRestLength();
            wheel.m_suspensionRelativeVelocity = btScalar(0.0);
            wheel.m_raycastInfo.m_contactNormalWS = - wheel.m_raycastInfo.m_wheelDirectionWS;
            wheel.m_clippedInvContactDotSuspension = btScalar(1.0);
      }

      return depth;
}


Generated by  Doxygen 1.6.0   Back to index