Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void obj_Vehicle::HelicopterPhysx() // controls of helicopter
- {
- static float LastUpdateP = r3dGetTime();
- if (isHelicopter == true && (LastUpdateP + 0.02f <= r3dGetTime()))
- {
- PlayTractionLoopSound(false);
- LastUpdateP = r3dGetTime();
- const float fTimePassed = r3dGetFrameTime();
- PxTransform pose = vd->vehicle->getRigidDynamicActor()->getGlobalPose();
- r3dVector angles;
- r3dPoint3D position(0, 0, 0);
- static float ThisTime = r3dGetTime();
- float DeltaTime = r3dGetTime() - ThisTime;
- if (HasDriver() && HSpeed > 70)
- {
- PxVec3 HeliSpeed = vd->vehicle->getRigidDynamicActor()->getLinearVelocity();
- float lerp_vec = 0.0f;
- static float lerp_to = 0.0f;
- if (Keyboard->IsPressed(kbsD)) // Rotate Left
- vd->vehicle->getRigidDynamicActor()->addTorque(PxVec3(0, 30 * DeltaTime, 0), PxForceMode::eACCELERATION, true);
- else if (Keyboard->IsPressed(kbsS)) // rotate Right
- vd->vehicle->getRigidDynamicActor()->addTorque(PxVec3(0, -30 * DeltaTime, 0), PxForceMode::eACCELERATION, true);
- else
- vd->vehicle->getRigidDynamicActor()->setAngularDamping(PxReal(1.0f));
- vd->vehicle->getRigidDynamicActor()->setMaxAngularVelocity(PxReal(15.0f));
- if (Keyboard->IsPressed(kbsUp)) // move front
- {
- if (vd->vehicle->getRigidDynamicActor()->getAngularVelocity().x < 15)
- vd->vehicle->getRigidDynamicActor()->addTorque(PxVec3(GetvForw().x * DeltaTime *10, 0, 0), PxForceMode::eACCELERATION, true);
- //HelyY += 0.5f;
- else
- vd->vehicle->getRigidDynamicActor()->setAngularDamping(PxReal(1.0f));
- if (HelyFB>1 && FB >= 0)
- FB = HelyFB -= 0.25f;
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvForw().x * 0.5f, 0, GetvForw().z * 0.5f), PxForceMode::eVELOCITY_CHANGE, true);
- }
- else
- {
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvUp().x, GetvUp().y, GetvUp().z), PxForceMode::eVELOCITY_CHANGE);
- if (FB >0 && HelyFB<20)
- FB = HelyFB += 0.05f;
- if (HelyY>0)
- {
- HelyY -= 0.5f;
- if (HelyY<0) HelyY = 0;
- }
- }
- if (Keyboard->IsPressed(kbsDown)) // Move back
- {
- if (HelyY>-15.0f)
- HelyY -= 0.5f;
- if (HelyFB>5 && FB <= 0)
- FB = abs(HelyFB -= 0.5f)*-1;
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvForw().x * 0.5f * -1, 0, GetvForw().z * 0.5f * -1), PxForceMode::eVELOCITY_CHANGE, true);
- }
- else {
- if (FB <0 && HelyFB<20)
- FB = abs(HelyFB += 0.05f)*-1;
- if (HelyY<0)
- {
- HelyY += 0.5f;
- }
- }
- if (Keyboard->IsPressed(kbsRight)) // move Right
- {
- if (HelyZ>-30.0)
- HelyZ -= 0.5f;
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvRight().x * 0.2f, 0, GetvRight().z * 0.2f), PxForceMode::eVELOCITY_CHANGE, true);
- if ((Keyboard->IsPressed(kbsUp) || Keyboard->IsPressed(kbsDown)))
- {
- HelyX += 0.5f;
- }
- else {
- if (HelyLR>5 && LR >= 0)
- LR = HelyLR -= 0.5f;
- }
- }
- else {
- if (LR >0 && HelyLR<20)
- LR = HelyLR += 0.1f;
- if (HelyZ<0)
- {
- HelyZ += 0.5f;
- }
- }
- if (Keyboard->IsPressed(kbsLeft)) // move Left
- {
- if (HelyZ<30.0)
- HelyZ += 0.5f;
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvRight().x * 0.2f * -1, 0, GetvRight().z * 0.2f * -1), PxForceMode::eVELOCITY_CHANGE, true);
- if ((Keyboard->IsPressed(kbsUp) || Keyboard->IsPressed(kbsDown)))
- {
- HelyX -= 0.5f;
- }
- else {
- if (HelyLR>5 && LR <= 0)
- LR = abs(HelyLR -= 0.5f)*-1;
- }
- }
- else {
- if (LR <0 && HelyLR<20)
- LR = abs(HelyLR += 0.1f)*-1;
- if (HelyZ>0)
- {
- HelyZ -= 0.5f;
- if (HelyZ<0) HelyZ = 0;
- }
- }
- if (!Keyboard->IsPressed(kbsUp) && !Keyboard->IsPressed(kbsDown) && !Keyboard->IsPressed(kbsRight) && !Keyboard->IsPressed(kbsLeft))
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(HeliSpeed.x * 0.02f * -1, HeliSpeed.y * 0.01f * -1, HeliSpeed.z * 0.02f * -1), PxForceMode::eVELOCITY_CHANGE, true);
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, 9.8f * DeltaTime, 0), PxForceMode::eVELOCITY_CHANGE, true);
- if (Keyboard->IsPressed(kbsA)) // move up
- {
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, 10 * DeltaTime, 0), PxForceMode::eVELOCITY_CHANGE, true);
- }
- else if (Keyboard->IsPressed(kbsZ)) // Move down
- {
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, -10 * DeltaTime, 0), PxForceMode::eVELOCITY_CHANGE, true);
- }
- PxVec3 MaxSpeedVec(40, 8, 40);
- PxVec3 MaxSpeedVecReverse = MaxSpeedVec * -1;
- // forward
- if (HeliSpeed.x > MaxSpeedVec.x)
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(MaxSpeedVec.x - HeliSpeed.x, 0, 0), PxForceMode::eVELOCITY_CHANGE, true);
- if (HeliSpeed.y > MaxSpeedVec.y)
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, MaxSpeedVec.y - HeliSpeed.y, 0), PxForceMode::eVELOCITY_CHANGE, true);
- if (HeliSpeed.z > MaxSpeedVec.z)
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, 0, MaxSpeedVec.z - HeliSpeed.z), PxForceMode::eVELOCITY_CHANGE, true);
- // reverse
- if (HeliSpeed.x < MaxSpeedVecReverse.x)
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(MaxSpeedVecReverse.x - HeliSpeed.x, 0, 0), PxForceMode::eVELOCITY_CHANGE, true);
- if (HeliSpeed.y < MaxSpeedVecReverse.y)
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, MaxSpeedVecReverse.y - HeliSpeed.y, 0), PxForceMode::eVELOCITY_CHANGE, true);
- if (HeliSpeed.z < MaxSpeedVecReverse.z)
- vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, 0, MaxSpeedVecReverse.z - HeliSpeed.z), PxForceMode::eVELOCITY_CHANGE, true);
- ThisTime = r3dGetTime();
- }
- else
- {
- ThisTime = r3dGetTime();
- if (distanceFromGround>0)
- {
- if (HSpeed < 50 || !CheckFuel())
- {
- if (HelyUp>0)
- HelyUp = -0.1f;
- }
- }
- }
- pose.p.y += HelyUp;
- if (HelyFB >= 20)
- FB = 0;
- if (HelyLR >= 20)
- LR = 0;
- //r3dOutToLog("######## HelyFB: %f FB: %f\n",HelyFB,FB);
- position = r3dPoint3D(pose.p.x, pose.p.y, pose.p.z) + (GetvForw() / FB) + (GetvRight() / LR);
- if (HelyUp<0)
- {
- HelyUp += 0.001f;
- }
- else if (HelyUp>0)
- {
- HelyUp -= 0.001f;
- if (HelyUp<0) HelyUp = 0;
- }
- //static float HelyX_Lerp = HelyX;
- static float HelyY_Lerp = HelyY;
- static float HelyZ_Lerp = HelyZ;
- //HelyX_Lerp = R3D_LERP(HelyX_Lerp, HelyX, 0.05);
- HelyY_Lerp = R3D_LERP(HelyY_Lerp, HelyY, 0.05);
- HelyZ_Lerp = R3D_LERP(HelyZ_Lerp, HelyZ, 0.08);
- /*D3DXMATRIX RotateMatrix, RotateMatrix2, toOrigin, fromOrigin, boneTransform;
- D3DXMatrixTranslation(&toOrigin, -GetPosition().x, -GetPosition().y, -GetPosition().z);
- D3DXMatrixTranslation(&fromOrigin, pose.p.x, pose.p.y, pose.p.z);
- D3DXMatrixRotationYawPitchRoll(&RotateMatrix, R3D_DEG2RAD(0), R3D_DEG2RAD(HelyY_Lerp), R3D_DEG2RAD(HelyZ_Lerp));
- D3DXMatrixMultiply(&boneTransform, &fromOrigin, &RotateMatrix);
- D3DXMatrixMultiply(&boneTransform, &boneTransform, &toOrigin);
- PxMat33 orientation(PxVec3(boneTransform._11, boneTransform._12, boneTransform._13),
- PxVec3(boneTransform._21, boneTransform._22, boneTransform._23),
- PxVec3(boneTransform._31, boneTransform._32, boneTransform._33));
- pose.q = PxQuat(orientation);*/
- /*D3DMATRIX m = GetRotationMatrix();*/
- //pose.p.x=position.x;//HelyFB;
- //pose.p.z=position.z;//HelyLR;
- /*HelyLR=position.z;
- HelyFB=position.x;*/
- vd->vehicle->getRigidDynamicActor()->setGlobalPose(pose);
- //SetPosition(r3dPoint3D(position.x,pose.p.y,position.z));
- r3dPoint3D vel = GetVelocity();
- vel.x *= pose.p.x;
- vel.y *= pose.p.y;
- vel.z *= pose.p.y;
- if (vel.Length() < 0.001f) vel = r3dPoint3D(0, 0, 0);
- SetVelocity(vel);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement