SHOW:
|
|
- or go back to the newest paste.
1 | void obj_Vehicle::HelicopterPhysx() // controls of helicopter | |
2 | { | |
3 | static float LastUpdateP = r3dGetTime(); | |
4 | if (isHelicopter == true && (LastUpdateP + 0.02f <= r3dGetTime())) | |
5 | { | |
6 | PlayTractionLoopSound(false); | |
7 | ||
8 | LastUpdateP = r3dGetTime(); | |
9 | const float fTimePassed = r3dGetFrameTime(); | |
10 | PxTransform pose = vd->vehicle->getRigidDynamicActor()->getGlobalPose(); | |
11 | r3dVector angles; | |
12 | r3dPoint3D position(0, 0, 0); | |
13 | ||
14 | static float ThisTime = r3dGetTime(); | |
15 | ||
16 | float DeltaTime = r3dGetTime() - ThisTime; | |
17 | ||
18 | if (HasDriver() && HSpeed > 70) | |
19 | { | |
20 | PxVec3 HeliSpeed = vd->vehicle->getRigidDynamicActor()->getLinearVelocity(); | |
21 | ||
22 | float lerp_vec = 0.0f; | |
23 | static float lerp_to = 0.0f; | |
24 | ||
25 | if (Keyboard->IsPressed(kbsD)) // Rotate Left | |
26 | vd->vehicle->getRigidDynamicActor()->addTorque(PxVec3(0, 30 * DeltaTime, 0), PxForceMode::eACCELERATION, true); | |
27 | else if (Keyboard->IsPressed(kbsS)) // rotate Right | |
28 | vd->vehicle->getRigidDynamicActor()->addTorque(PxVec3(0, -30 * DeltaTime, 0), PxForceMode::eACCELERATION, true); | |
29 | else | |
30 | vd->vehicle->getRigidDynamicActor()->setAngularDamping(PxReal(1.0f)); | |
31 | ||
32 | vd->vehicle->getRigidDynamicActor()->setMaxAngularVelocity(PxReal(15.0f)); | |
33 | ||
34 | if (Keyboard->IsPressed(kbsUp)) // move front | |
35 | { | |
36 | if (vd->vehicle->getRigidDynamicActor()->getAngularVelocity().x < 15) | |
37 | vd->vehicle->getRigidDynamicActor()->addTorque(PxVec3(GetvForw().x * DeltaTime *10, 0, 0), PxForceMode::eACCELERATION, true); | |
38 | //HelyY += 0.5f; | |
39 | else | |
40 | vd->vehicle->getRigidDynamicActor()->setAngularDamping(PxReal(1.0f)); | |
41 | ||
42 | if (HelyFB>1 && FB >= 0) | |
43 | FB = HelyFB -= 0.25f; | |
44 | ||
45 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvForw().x * 0.5f, 0, GetvForw().z * 0.5f), PxForceMode::eVELOCITY_CHANGE, true); | |
46 | } | |
47 | else | |
48 | { | |
49 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvUp().x, GetvUp().y, GetvUp().z), PxForceMode::eVELOCITY_CHANGE); | |
50 | ||
51 | if (FB >0 && HelyFB<20) | |
52 | FB = HelyFB += 0.05f; | |
53 | ||
54 | if (HelyY>0) | |
55 | { | |
56 | HelyY -= 0.5f; | |
57 | if (HelyY<0) HelyY = 0; | |
58 | } | |
59 | } | |
60 | if (Keyboard->IsPressed(kbsDown)) // Move back | |
61 | { | |
62 | if (HelyY>-15.0f) | |
63 | HelyY -= 0.5f; | |
64 | ||
65 | if (HelyFB>5 && FB <= 0) | |
66 | FB = abs(HelyFB -= 0.5f)*-1; | |
67 | ||
68 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvForw().x * 0.5f * -1, 0, GetvForw().z * 0.5f * -1), PxForceMode::eVELOCITY_CHANGE, true); | |
69 | } | |
70 | else { | |
71 | if (FB <0 && HelyFB<20) | |
72 | FB = abs(HelyFB += 0.05f)*-1; | |
73 | if (HelyY<0) | |
74 | { | |
75 | HelyY += 0.5f; | |
76 | } | |
77 | ||
78 | } | |
79 | if (Keyboard->IsPressed(kbsRight)) // move Right | |
80 | { | |
81 | if (HelyZ>-30.0) | |
82 | HelyZ -= 0.5f; | |
83 | ||
84 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvRight().x * 0.2f, 0, GetvRight().z * 0.2f), PxForceMode::eVELOCITY_CHANGE, true); | |
85 | ||
86 | if ((Keyboard->IsPressed(kbsUp) || Keyboard->IsPressed(kbsDown))) | |
87 | { | |
88 | HelyX += 0.5f; | |
89 | } | |
90 | else { | |
91 | if (HelyLR>5 && LR >= 0) | |
92 | LR = HelyLR -= 0.5f; | |
93 | } | |
94 | } | |
95 | else { | |
96 | if (LR >0 && HelyLR<20) | |
97 | LR = HelyLR += 0.1f; | |
98 | if (HelyZ<0) | |
99 | { | |
100 | HelyZ += 0.5f; | |
101 | } | |
102 | } | |
103 | ||
104 | if (Keyboard->IsPressed(kbsLeft)) // move Left | |
105 | { | |
106 | ||
107 | if (HelyZ<30.0) | |
108 | HelyZ += 0.5f; | |
109 | ||
110 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(GetvRight().x * 0.2f * -1, 0, GetvRight().z * 0.2f * -1), PxForceMode::eVELOCITY_CHANGE, true); | |
111 | ||
112 | if ((Keyboard->IsPressed(kbsUp) || Keyboard->IsPressed(kbsDown))) | |
113 | { | |
114 | HelyX -= 0.5f; | |
115 | } | |
116 | else { | |
117 | if (HelyLR>5 && LR <= 0) | |
118 | LR = abs(HelyLR -= 0.5f)*-1; | |
119 | } | |
120 | ||
121 | } | |
122 | else { | |
123 | if (LR <0 && HelyLR<20) | |
124 | LR = abs(HelyLR += 0.1f)*-1; | |
125 | ||
126 | if (HelyZ>0) | |
127 | { | |
128 | HelyZ -= 0.5f; | |
129 | if (HelyZ<0) HelyZ = 0; | |
130 | } | |
131 | } | |
132 | ||
133 | if (!Keyboard->IsPressed(kbsUp) && !Keyboard->IsPressed(kbsDown) && !Keyboard->IsPressed(kbsRight) && !Keyboard->IsPressed(kbsLeft)) | |
134 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(HeliSpeed.x * 0.02f * -1, HeliSpeed.y * 0.01f * -1, HeliSpeed.z * 0.02f * -1), PxForceMode::eVELOCITY_CHANGE, true); | |
135 | ||
136 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, 9.8f * DeltaTime, 0), PxForceMode::eVELOCITY_CHANGE, true); | |
137 | ||
138 | if (Keyboard->IsPressed(kbsA)) // move up | |
139 | { | |
140 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, 10 * DeltaTime, 0), PxForceMode::eVELOCITY_CHANGE, true); | |
141 | } | |
142 | else if (Keyboard->IsPressed(kbsZ)) // Move down | |
143 | { | |
144 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, -10 * DeltaTime, 0), PxForceMode::eVELOCITY_CHANGE, true); | |
145 | } | |
146 | ||
147 | PxVec3 MaxSpeedVec(40, 8, 40); | |
148 | PxVec3 MaxSpeedVecReverse = MaxSpeedVec * -1; | |
149 | ||
150 | // forward | |
151 | if (HeliSpeed.x > MaxSpeedVec.x) | |
152 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(MaxSpeedVec.x - HeliSpeed.x, 0, 0), PxForceMode::eVELOCITY_CHANGE, true); | |
153 | if (HeliSpeed.y > MaxSpeedVec.y) | |
154 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, MaxSpeedVec.y - HeliSpeed.y, 0), PxForceMode::eVELOCITY_CHANGE, true); | |
155 | if (HeliSpeed.z > MaxSpeedVec.z) | |
156 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, 0, MaxSpeedVec.z - HeliSpeed.z), PxForceMode::eVELOCITY_CHANGE, true); | |
157 | ||
158 | // reverse | |
159 | if (HeliSpeed.x < MaxSpeedVecReverse.x) | |
160 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(MaxSpeedVecReverse.x - HeliSpeed.x, 0, 0), PxForceMode::eVELOCITY_CHANGE, true); | |
161 | if (HeliSpeed.y < MaxSpeedVecReverse.y) | |
162 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, MaxSpeedVecReverse.y - HeliSpeed.y, 0), PxForceMode::eVELOCITY_CHANGE, true); | |
163 | if (HeliSpeed.z < MaxSpeedVecReverse.z) | |
164 | vd->vehicle->getRigidDynamicActor()->addForce(PxVec3(0, 0, MaxSpeedVecReverse.z - HeliSpeed.z), PxForceMode::eVELOCITY_CHANGE, true); | |
165 | ||
166 | ThisTime = r3dGetTime(); | |
167 | } | |
168 | else | |
169 | { | |
170 | ||
171 | ThisTime = r3dGetTime(); | |
172 | ||
173 | if (distanceFromGround>0) | |
174 | { | |
175 | if (HSpeed < 50 || !CheckFuel()) | |
176 | { | |
177 | if (HelyUp>0) | |
178 | HelyUp = -0.1f; | |
179 | } | |
180 | } | |
181 | } | |
182 | pose.p.y += HelyUp; | |
183 | if (HelyFB >= 20) | |
184 | FB = 0; | |
185 | if (HelyLR >= 20) | |
186 | LR = 0; | |
187 | //r3dOutToLog("######## HelyFB: %f FB: %f\n",HelyFB,FB); | |
188 | position = r3dPoint3D(pose.p.x, pose.p.y, pose.p.z) + (GetvForw() / FB) + (GetvRight() / LR); | |
189 | if (HelyUp<0) | |
190 | { | |
191 | HelyUp += 0.001f; | |
192 | } | |
193 | else if (HelyUp>0) | |
194 | { | |
195 | HelyUp -= 0.001f; | |
196 | if (HelyUp<0) HelyUp = 0; | |
197 | } | |
198 | ||
199 | //static float HelyX_Lerp = HelyX; | |
200 | static float HelyY_Lerp = HelyY; | |
201 | static float HelyZ_Lerp = HelyZ; | |
202 | ||
203 | //HelyX_Lerp = R3D_LERP(HelyX_Lerp, HelyX, 0.05); | |
204 | HelyY_Lerp = R3D_LERP(HelyY_Lerp, HelyY, 0.05); | |
205 | HelyZ_Lerp = R3D_LERP(HelyZ_Lerp, HelyZ, 0.08); | |
206 | ||
207 | /*D3DXMATRIX RotateMatrix, RotateMatrix2, toOrigin, fromOrigin, boneTransform; | |
208 | D3DXMatrixTranslation(&toOrigin, -GetPosition().x, -GetPosition().y, -GetPosition().z); | |
209 | D3DXMatrixTranslation(&fromOrigin, pose.p.x, pose.p.y, pose.p.z); | |
210 | ||
211 | D3DXMatrixRotationYawPitchRoll(&RotateMatrix, R3D_DEG2RAD(0), R3D_DEG2RAD(HelyY_Lerp), R3D_DEG2RAD(HelyZ_Lerp)); | |
212 | D3DXMatrixMultiply(&boneTransform, &fromOrigin, &RotateMatrix); | |
213 | ||
214 | D3DXMatrixMultiply(&boneTransform, &boneTransform, &toOrigin); | |
215 | ||
216 | PxMat33 orientation(PxVec3(boneTransform._11, boneTransform._12, boneTransform._13), | |
217 | PxVec3(boneTransform._21, boneTransform._22, boneTransform._23), | |
218 | PxVec3(boneTransform._31, boneTransform._32, boneTransform._33)); | |
219 | pose.q = PxQuat(orientation);*/ | |
220 | ||
221 | /*D3DMATRIX m = GetRotationMatrix();*/ | |
222 | //pose.p.x=position.x;//HelyFB; | |
223 | //pose.p.z=position.z;//HelyLR; | |
224 | ||
225 | /*HelyLR=position.z; | |
226 | HelyFB=position.x;*/ | |
227 | vd->vehicle->getRigidDynamicActor()->setGlobalPose(pose); | |
228 | //SetPosition(r3dPoint3D(position.x,pose.p.y,position.z)); | |
229 | r3dPoint3D vel = GetVelocity(); | |
230 | vel.x *= pose.p.x; | |
231 | vel.y *= pose.p.y; | |
232 | vel.z *= pose.p.y; | |
233 | if (vel.Length() < 0.001f) vel = r3dPoint3D(0, 0, 0); | |
234 | SetVelocity(vel); | |
235 | } | |
236 | } |