MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / xEntApplyPhysics

Function xEntApplyPhysics

src/SB/Core/x/xEnt.cpp:1183–1226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1181} // namespace
1182
1183void 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
1228void xEntCollide(xEnt* ent, xScene* sc, F32 dt)
1229{

Callers 3

ProcessMethod · 0.70
update_stacked_entityFunction · 0.70
xEntUpdateFunction · 0.70

Calls 4

xVec3SMulByFunction · 0.85
xVec3AddFunction · 0.85
xsqrtFunction · 0.85
xEntAddToPosFunction · 0.85

Tested by

no test coverage detected