1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
float fMasse;
float InertieX,InertieY,InertieZ;
NewtonBodyGetMassMatrix (m_pBody, &fMasse, &InertieX, &InertieY, &InertieZ);
float force[3]={0.0f,-fMasse*9.81,0.0f};
GSEPOINT3D Direction=GSECamera->GetVectorDirection();
//Gestion des deplacement à terre
if(GSEKeyboard->IsPressed(KeyboardUp))
{
force[0]+=Direction.x*WalkingSpeed;
//force[1]=Direction.y*1000000.0;
force[2]+=Direction.z*WalkingSpeed;
}
if(GSEKeyboard->IsPressed(KeyboardDown))
{
force[0]+=Direction.x*(-1*WalkingSpeed);
//force[1]=Direction.y*(-1000000.0);
force[2]+=Direction.z*(-1*WalkingSpeed);
}
GSEPOINT3D tmp;
tmp.CrossProduct(Direction,GSEPOINT3D(0.0,1.0,0.0));
if(GSEKeyboard->IsPressed(KeyboardLeft))
{
tmp*=-1;
force[0]+=tmp.x*(WalkingSpeed);
//force[1]=tmp.y*(1000000.0);
force[2]+=tmp.z*(WalkingSpeed);
}
if(GSEKeyboard->IsPressed(KeyboardRight))
{
force[0]+=tmp.x*(WalkingSpeed);
//force[1]=tmp.y*(1000000.0);
force[2]+=tmp.z*(WalkingSpeed);
}
//Gestion du saut
float vel[3];
vel[0]=0.0;
vel[1]=0.0;
vel[2]=0.0;
GSEMATRIX4X4 matrice;
NewtonBodyGetMatrix(m_pBody,&matrice.entries[0]);
if(matrice.entries[13]>=JumpHeightMax)
{
Wait=true;
}
if(matrice.entries[13]<=MinHeight)
{
HasJumped=false;
Wait=false;
}
if((GSEKeyboard->IsPressed(KeyboardJump))&&(matrice.entries[13]<JumpHeightMax)&&(!Wait))
{
force[0]+=JumpForce.x;
force[1]+=JumpForce.y;
force[2]+=JumpForce.z;
HasJumped=true;
}
if(HasJumped)
{
vel[0]=GravityForce.x;
vel[1]=GravityForce.y;
vel[2]=GravityForce.z;
}
//Gestion du crounch
if((GSEKeyboard->IsPressed(KeyboardCrounch))&&(matrice.entries[13]>=CrounchHeightMin))
{
force[0]+=CrounchForce.x;
force[1]+=CrounchForce.y;
force[2]+=CrounchForce.z;
IsCrounch=true;
}
if((!GSEKeyboard->IsPressed(KeyboardCrounch))&&(IsCrounch))
{
vel[0]=GravityForce.x;
vel[1]=-1.0*GravityForce.y;
vel[2]=GravityForce.z;
}
if(matrice.entries[13]>=MinHeight)
{
IsCrounch=false;
}
if((!GSEKeyboard->IsPressed(KeyboardUp))||
(!GSEKeyboard->IsPressed(KeyboardDown))||
(GSEKeyboard->IsPressed(KeyboardLeft))||
(GSEKeyboard->IsPressed(KeyboardRight)))
{
NewtonBodySetVelocity(m_pBody,&vel[0]);
}
NewtonBodySetForce (m_pBody, force); |
Partager