| 1181 | } // namespace |
| 1182 | |
| 1183 | void xEntApplyPhysics(xEnt* ent, xScene* sc, F32 dt) |
| 1184 | { |
| 1185 | xVec3 dposvel = { 0, 0, 0 }; |
| 1186 | |
| 1187 | if (ent->pflags & 0x4 && sc->flags & 0x1) |
| 1188 | { |
| 1189 | ent->frame->vel.y += sc->gravity * dt; |
| 1190 | } |
| 1191 | |
| 1192 | if (ent->pflags & 0x10 && sc->flags & 0x2) |
| 1193 | { |
| 1194 | F32 tfric = -(sc->friction * dt - 1.0f); |
| 1195 | xVec3SMulBy(&ent->frame->vel, tfric); |
| 1196 | } |
| 1197 | |
| 1198 | if (ent->pflags & 0x8 && sc->flags & 0x4) |
| 1199 | { |
| 1200 | F32 tdrag = -(sc->drag * dt - 1.0f); |
| 1201 | xVec3SMulBy(&ent->frame->vel, tdrag); |
| 1202 | } |
| 1203 | |
| 1204 | xVec3Add(&dposvel, &ent->frame->vel, &ent->frame->oldvel); |
| 1205 | xVec3SMulBy(&dposvel, 0.5f * dt); |
| 1206 | |
| 1207 | if (dposvel.y < 0.0f) |
| 1208 | { |
| 1209 | F32 dposXZ = xsqrt(SQR(dposvel.x) + SQR(dposvel.z)); |
| 1210 | F32 scaleXZ = (dposXZ > 0.00001f) ? ((0.63f * (30.0f * dt)) / dposXZ) : 0.0f; |
| 1211 | F32 scaleY = (0.63f * (30.0f * dt)) / (F32)iabs(dposvel.y); |
| 1212 | |
| 1213 | if (scaleXZ < 1.0f) |
| 1214 | { |
| 1215 | dposvel.x *= scaleXZ; |
| 1216 | dposvel.z *= scaleXZ; |
| 1217 | } |
| 1218 | |
| 1219 | if (scaleY < 1.0f) |
| 1220 | { |
| 1221 | dposvel.y *= scaleY; |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | xEntAddToPos(ent, &dposvel); |
| 1226 | } |
| 1227 | |
| 1228 | void xEntCollide(xEnt* ent, xScene* sc, F32 dt) |
| 1229 | { |
no test coverage detected