Beispiel #1
0
void CProjectile::OnHit( const NewtonBody* body, vector3df vImpactVel, f32 fImpactMass )
{
    dFloat mass;
    dFloat Ixx;
    dFloat Iyy;
    dFloat Izz;

    NewtonBodyGetMassMatrix( body, &mass, &Ixx, &Iyy, &Izz );

    if ( mass != 0.0f )
    {
      CNewtonNode* newtonNode = 0;
      newtonNode = ( CNewtonNode * )NewtonBodyGetUserData( body );
      if ( newtonNode )
      {
        OnHitNewtonNode( newtonNode, vImpactVel, fImpactMass );
      }

      vector3df vImpulse = vImpactVel* fImpactMass* fImpactMass* fImpactMass * 0.00001f; //TEMP: 0.00

      NewtonAddBodyImpulse( body, &vImpulse.X, &Pos.X );
    }
    else
    {
      OnHitLevel( vImpactVel, fImpactMass );
    }
}
void PhysicMap::playerForceAndTorque(const NewtonBody* nBody)
{
    int id = (int)(NewtonBodyGetUserData(nBody));
    CompLocation* loc = CKernel::data()->getGameObjectLocation(id);
    float fMasse, ixx, iyy, izz;
    NewtonBodyGetMassMatrix(nBody, &fMasse, &ixx, &iyy, &izz);

    // Apply gravity force
    Triplet_f gravity(0, -fMasse * 9.81f, 0);
    NewtonBodyAddForce(nBody, &gravity.x);

    // Apply movment force
    Triplet_f desiredVel = loc->desiredVel() * 20;
    Triplet_f currentVel;
    NewtonBodyGetVelocity(nBody,&currentVel.x);
	Triplet_f forceApply = (desiredVel - currentVel) * fMasse * 10;
	forceApply.y = 0;
    NewtonBodyAddForce(nBody, &forceApply.x);

    // Apply rotation
    Matrix_f mat;
    NewtonBodyGetMatrix(nBody, mat.raw());
    mat.setRotationY(loc->desiredAngle());
    NewtonBodySetMatrix(nBody, mat.raw());

    // Apply shot recoil
    if (loc->isImpact())
    {
        Triplet_f impact = loc->getNormal() * -3;
        NewtonAddBodyImpulse(nBody, &impact.x, &mat.position().x);
    }

    // Update the game object
    loc->setPosition(mat.position());
    loc->setDirection(Triplet_f(loc->desiredAngle()));
    loc->setVelocity(currentVel);
}
Beispiel #3
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
PhysicsActor::applyImpulse(const Math::Vector3& _force, const Math::Vector3& _worldPos)
{
    //todo: bullet needs it's force fed to it in local space coords
     NewtonAddBodyImpulse(m_pActor, _force.m_array, _worldPos.m_array);
}