virtual void do_simulation_controller(IVP_Event_Sim *event,IVP_U_Vector<IVP_Core> *core_list) { int i; for( i = core_list->len()-1; i >=0; i--) { IVP_Core *pCore = core_list->element_at(i); IVP_Real_Object *pivp = pCore->objects.element_at(0); CPhysicsObject *pPhys = static_cast<CPhysicsObject *>(pivp->client_data); float dragForce = -0.5 * pPhys->GetDragInDirection( pCore->speed ) * m_airDensity * event->delta_time; if ( dragForce < -1.0f ) dragForce = -1.0f; if ( dragForce < 0 ) { IVP_U_Float_Point dragVelocity; dragVelocity.set_multiple( &pCore->speed, dragForce ); pCore->speed.add( &dragVelocity ); } float angDragForce = -pPhys->GetAngularDragInDirection( pCore->rot_speed ) * m_airDensity * event->delta_time; if ( angDragForce < -1.0f ) angDragForce = -1.0f; if ( angDragForce < 0 ) { IVP_U_Float_Point angDragVelocity; angDragVelocity.set_multiple( &pCore->rot_speed, angDragForce ); pCore->rot_speed.add( &angDragVelocity ); } } }
void CPhysicsDragController::Tick(btScalar dt) { for(int i = 0; i < m_ents.Size(); i++) { CPhysicsObject * object = (CPhysicsObject *)m_ents[i]; Vector dragLinearFinal(0,0,0); AngularImpulse dragAngularFinal(0,0,0); Vector vel; AngularImpulse ang; object->GetVelocity(&vel, &ang); btVector3 bull_vel; ConvertPosToBull(vel, bull_vel); float dragForce = -0.5 * object->GetDragInDirection( &bull_vel ) * m_airDensity * dt; if ( dragForce < -1.0f ) { dragForce = -1.0f; } if ( dragForce < 0 ) { Vector dragLinearFinal = vel * dragForce; } btVector3 bull_angimpulse; ConvertAngularImpulseToBull(ang, bull_angimpulse); float angDragForce = -object->GetAngularDragInDirection(&bull_angimpulse) * m_airDensity * dt; if ( angDragForce < -1.0f ) { angDragForce = -1.0f; } if( angDragForce < 0) { dragAngularFinal = ang * angDragForce; } object->AddVelocity(&dragLinearFinal, &dragAngularFinal); } }