Skip to content

Commit

Permalink
Made XNA Physics alternative that has the same effect but better.
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed Mar 24, 2024
1 parent e58df68 commit 548a432
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
21 changes: 12 additions & 9 deletions engine/source/game/marble/marble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2262,22 +2262,25 @@ ConsoleMethod(Marble, setMode, void, 3, 3, "(mode)")
ConsoleMethod(Marble, setPhysics, void, 3, 3, "(physics)")
{
const char* physics = argv[2];
U32 physicsFlags[3];
const char* physicsStrings[3];
U32 physicsFlags[Marble::MBPhysics_Count];
const char* physicsStrings[Marble::MBPhysics_Count];

physicsStrings[0] = "MBU";
physicsFlags[0] = Marble::MBU;
physicsStrings[Marble::MBU] = "MBU";
physicsFlags[Marble::MBU] = Marble::MBU;

physicsStrings[1] = "MBG";
physicsFlags[1] = Marble::MBG;
physicsStrings[Marble::MBG] = "MBG";
physicsFlags[Marble::MBG] = Marble::MBG;

physicsStrings[2] = "XNA";
physicsFlags[2] = Marble::XNA;
physicsStrings[Marble::XNA] = "XNA";
physicsFlags[Marble::XNA] = Marble::XNA;

physicsStrings[Marble::XNASlopes] = "XNASlopes";
physicsFlags[Marble::XNASlopes] = Marble::XNASlopes;

S32 i = 0;
while (dStricmp(physicsStrings[i], physics))
{
if (++i >= 3)
if (++i >= Marble::MBPhysics_Count)
{
Con::errorf("Marble:: Unknown physics mode: %s", physics);
return;
Expand Down
4 changes: 3 additions & 1 deletion engine/source/game/marble/marble.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class Marble : public ShapeBase
{
MBU,
MBG,
XNA
XNA,
XNASlopes,
MBPhysics_Count
};

enum UpdateMaskBits
Expand Down
29 changes: 16 additions & 13 deletions engine/source/game/marble/marblephysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,21 @@ void Marble::applyContactForces(const Move* move, bool isCentered, Point3D& aCon
}
}

for (S32 i = 0; i < mContacts.size(); i++)
if (mPhysics != XNASlopes)
{
Contact* contact = &mContacts[i];
for (S32 i = 0; i < mContacts.size(); i++)
{
Contact *contact = &mContacts[i];

F64 normalForce = -mDot(contact->normal, A);
F64 normalForce = -mDot(contact->normal, A);

if (normalForce > 0.0 &&
(mVelocity.x - contact->surfaceVelocity.x) * contact->normal.x
+ (mVelocity.y - contact->surfaceVelocity.y) * contact->normal.y
+ (mVelocity.z - contact->surfaceVelocity.z) * contact->normal.z <= 0.0001)
{
A += contact->normal * normalForce;
if (normalForce > 0.0 &&
(mVelocity.x - contact->surfaceVelocity.x) * contact->normal.x
+ (mVelocity.y - contact->surfaceVelocity.y) * contact->normal.y
+ (mVelocity.z - contact->surfaceVelocity.z) * contact->normal.z <= 0.0001)
{
A += contact->normal * normalForce;
}
}
}

Expand Down Expand Up @@ -634,10 +637,10 @@ void Marble::advancePhysics(const Move* move, U32 timeDelta)

F64 moveTime = timeStep;
computeFirstPlatformIntersect(moveTime, smPathItrVec);
//if (mPhysics == XNA)
// mPosition += mVelocity * moveTime; // XNA
//else
testMove(mVelocity, mPosition, moveTime, mRadius, sCollisionMask, false); // MBU
if (mPhysics == XNA)
mPosition += mVelocity * moveTime; // XNA
else
testMove(mVelocity, mPosition, moveTime, mRadius, sCollisionMask, false); // MBU

if (!mMovePathSize && timeStep * 0.99 > moveTime && moveTime > 0.001000000047497451)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = $Text::LevelNameMP26;
difficulty = "4";
gameType = "MultiPlayer";
gameMode = "Scrum";
physics = "XNA";
physics = "XNASlopes";
time = "300000";
maxGemsPerGroup = "9";
desc = "A preview mission";
Expand Down

0 comments on commit 548a432

Please sign in to comment.