Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
| Show First 20 Lines • Show All 691 Lines • ▼ Show 20 Lines | CcdPhysicsController::~CcdPhysicsController() | ||||
| DeleteControllerShape(); | DeleteControllerShape(); | ||||
| if (m_shapeInfo) | if (m_shapeInfo) | ||||
| { | { | ||||
| m_shapeInfo->Release(); | m_shapeInfo->Release(); | ||||
| } | } | ||||
| } | } | ||||
| void CcdPhysicsController::SimulationTick(float timestep) | |||||
| { | |||||
| btRigidBody *body = GetRigidBody(); | |||||
| if (!body || body->isStaticObject()) | |||||
| return; | |||||
| // Clamp linear velocity | |||||
| if (m_cci.m_clamp_vel_max > 0.0f || m_cci.m_clamp_vel_min > 0.0f) { | |||||
| const btVector3 &linvel = body->getLinearVelocity(); | |||||
| btScalar len = linvel.length(); | |||||
| if (m_cci.m_clamp_vel_max > 0.0f && len > m_cci.m_clamp_vel_max) | |||||
| body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_max / len)); | |||||
| else if (m_cci.m_clamp_vel_min > 0.0f && !btFuzzyZero(len) && len < m_cci.m_clamp_vel_min) | |||||
| body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_min / len)); | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding') | * SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding') | ||||
| */ | */ | ||||
| bool CcdPhysicsController::SynchronizeMotionStates(float time) | bool CcdPhysicsController::SynchronizeMotionStates(float time) | ||||
| { | { | ||||
| //sync non-static to motionstate, and static from motionstate (todo: add kinematic etc.) | //sync non-static to motionstate, and static from motionstate (todo: add kinematic etc.) | ||||
| Show All 19 Lines | if (sb) | ||||
| m_MotionState->CalculateWorldTransformations(); | m_MotionState->CalculateWorldTransformations(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| btRigidBody* body = GetRigidBody(); | btRigidBody* body = GetRigidBody(); | ||||
| if (body && !body->isStaticObject()) | if (body && !body->isStaticObject()) | ||||
| { | { | ||||
| if ((m_cci.m_clamp_vel_max>0.0) || (m_cci.m_clamp_vel_min>0.0)) | |||||
| { | |||||
| const btVector3& linvel = body->getLinearVelocity(); | |||||
| float len= linvel.length(); | |||||
| if ((m_cci.m_clamp_vel_max>0.0) && (len > m_cci.m_clamp_vel_max)) | |||||
| body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_max / len)); | |||||
| else if ((m_cci.m_clamp_vel_min>0.0) && btFuzzyZero(len)==0 && (len < m_cci.m_clamp_vel_min)) | |||||
| body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_min / len)); | |||||
| } | |||||
| const btTransform& xform = body->getCenterOfMassTransform(); | const btTransform& xform = body->getCenterOfMassTransform(); | ||||
| const btMatrix3x3& worldOri = xform.getBasis(); | const btMatrix3x3& worldOri = xform.getBasis(); | ||||
| const btVector3& worldPos = xform.getOrigin(); | const btVector3& worldPos = xform.getOrigin(); | ||||
| float ori[12]; | float ori[12]; | ||||
| worldOri.getOpenGLSubMatrix(ori); | worldOri.getOpenGLSubMatrix(ori); | ||||
| m_MotionState->SetWorldOrientation(ori); | m_MotionState->SetWorldOrientation(ori); | ||||
| m_MotionState->SetWorldPosition(worldPos[0],worldPos[1],worldPos[2]); | m_MotionState->SetWorldPosition(worldPos[0],worldPos[1],worldPos[2]); | ||||
| m_MotionState->CalculateWorldTransformations(); | m_MotionState->CalculateWorldTransformations(); | ||||
| ▲ Show 20 Lines • Show All 1,886 Lines • Show Last 20 Lines | |||||