diff --git a/libsrc/bullet3-3.24/BulletCollision/BroadphaseCollision/btRSBroadphase.cpp b/libsrc/bullet3-3.24/BulletCollision/BroadphaseCollision/btRSBroadphase.cpp index c954880d..60c135d8 100644 --- a/libsrc/bullet3-3.24/BulletCollision/BroadphaseCollision/btRSBroadphase.cpp +++ b/libsrc/bullet3-3.24/BulletCollision/BroadphaseCollision/btRSBroadphase.cpp @@ -22,6 +22,8 @@ subject to the following restrictions: #include "../../LinearMath/btMatrix3x3.h" #include "../../LinearMath/btAabbUtil2.h" +#include "../CollisionShapes/btBvhTriangleMeshShape.h" + #include #include #include @@ -103,10 +105,48 @@ void _UpdateCellsStatic(btRSBroadphase* _this, btRSBroadphaseProxy* proxy) { _this->GetCellIndices(proxy->m_aabbMin, iMin, jMin, kMin); _this->GetCellIndices(aabbMax, iMax, jMax, kMax); + btCollisionObject* colObj = (btCollisionObject*)proxy->m_clientObject; + + // We should check if each cell actually collides with the object + bool isTriMesh = colObj && colObj->m_collisionShape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE; + + // For checking if an AABB has any containing triangles + struct BoolHitTriangleCallback : public btTriangleCallback { + + bool hit = false; + + BoolHitTriangleCallback() {} + virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex) { + hit = true; + } + }; + BoolHitTriangleCallback callbackInst = {}; + + int numSkipped = 0; for (int i = iMin; i <= iMax; i++) { for (int j = jMin; j <= jMax; j++) { for (int k = kMin; k <= kMax; k++) { auto& cell = _this->GetCell(i, j, k); + + if (isTriMesh) { + auto triMeshShape = (btTriangleMeshShape*)colObj->m_collisionShape; + btVector3 cellMin = _this->GetCellMinPos(i, j, k); + btVector3 cellMax = cellMin + btVector3(_this->cellSize, _this->cellSize, _this->cellSize); + + callbackInst.hit = false; + triMeshShape->processAllTriangles(&callbackInst, cellMin, cellMax); + + if (!callbackInst.hit) { + numSkipped++; + + if (ADD) { + continue; // No tris in this AABB, ignore + } else { + // Remove it anyway + } + } + } + if (ADD) { cell.staticHandles.push_back(proxy); } else { @@ -272,9 +312,11 @@ void btRSBroadphase::rayTest(const btVector3& rayFrom, const btVector3& rayTo, b Cell& cell = cells[GetCellIdx(rayFrom)]; for (auto& otherProxy : cell.staticHandles) - rayCallback.process(otherProxy); + if (otherProxy->m_clientObject) + rayCallback.process(otherProxy); for (auto& otherProxy : cell.dynHandles) - rayCallback.process(otherProxy); + if (otherProxy->m_clientObject) + rayCallback.process(otherProxy); } else { static std::once_flag onceFlag; std::call_once(onceFlag, @@ -302,9 +344,9 @@ void btRSBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax for (int i = 0; i <= m_LastHandleIndex; i++) { btRSBroadphaseProxy* proxy = &m_pHandles[i]; - if (!proxy->m_clientObject) { + if (!proxy->m_clientObject) continue; - } + if (TestAabbAgainstAabb2(aabbMin, aabbMax, proxy->m_aabbMin, proxy->m_aabbMax)) { callback.process(proxy); } @@ -312,9 +354,7 @@ void btRSBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax } bool btRSBroadphase::aabbOverlap(btRSBroadphaseProxy* proxy0, btRSBroadphaseProxy* proxy1) { - return proxy0->m_aabbMin[0] <= proxy1->m_aabbMax[0] && proxy1->m_aabbMin[0] <= proxy0->m_aabbMax[0] && - proxy0->m_aabbMin[1] <= proxy1->m_aabbMax[1] && proxy1->m_aabbMin[1] <= proxy0->m_aabbMax[1] && - proxy0->m_aabbMin[2] <= proxy1->m_aabbMax[2] && proxy1->m_aabbMin[2] <= proxy0->m_aabbMax[2]; + return TestAabbAgainstAabb2(proxy0->m_aabbMin, proxy0->m_aabbMax, proxy1->m_aabbMin, proxy1->m_aabbMax); } //then remove non-overlapping ones @@ -327,6 +367,7 @@ class CheckOverlapCallback : public btOverlapCallback }; void btRSBroadphase::calculateOverlappingPairs(btCollisionDispatcher* dispatcher) { + bool shouldRemove = !m_pairCache->hasDeferredRemoval(); if (m_numHandles >= 0) { int new_largest_index = -1; @@ -345,6 +386,9 @@ void btRSBroadphase::calculateOverlappingPairs(btCollisionDispatcher* dispatcher Cell& cell = cells[proxy->cellIdx]; for (auto& otherProxy : cell.staticHandles) { + if (!otherProxy->m_clientObject) + continue; + totalStaticPairs++; if (aabbOverlap(proxy, otherProxy)) { @@ -367,6 +411,9 @@ void btRSBroadphase::calculateOverlappingPairs(btCollisionDispatcher* dispatcher if (otherProxy == proxy) continue; + if (!otherProxy->m_clientObject) + continue; + totalDynPairs++; if (aabbOverlap(proxy, otherProxy)) { @@ -400,5 +447,5 @@ bool btRSBroadphase::testAabbOverlap(btBroadphaseProxy* proxy0, btBroadphaseProx } void btRSBroadphase::resetPool(btCollisionDispatcher* dispatcher) { - //not yet + // TODO: ? } diff --git a/libsrc/bullet3-3.24/BulletCollision/BroadphaseCollision/btRSBroadphase.h b/libsrc/bullet3-3.24/BulletCollision/BroadphaseCollision/btRSBroadphase.h index ff72aa66..a20fd28d 100644 --- a/libsrc/bullet3-3.24/BulletCollision/BroadphaseCollision/btRSBroadphase.h +++ b/libsrc/bullet3-3.24/BulletCollision/BroadphaseCollision/btRSBroadphase.h @@ -95,6 +95,10 @@ class btRSBroadphase : public btBroadphaseInterface btClamp(k, 0, cellsZ - 1); } + btVector3 GetCellMinPos(int i, int j, int k) const { + return minPos + btVector3(i, j, k) * cellSize; + } + int GetCellIdx(const btVector3& pos) const { int i, j, k; GetCellIndices(pos, i, j, k); diff --git a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp index 3bf99dce..d004e1c4 100644 --- a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp +++ b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp @@ -84,6 +84,50 @@ btScalar SegmentSqrDistance(const btVector3& from, const btVector3& to, const bt return diff.dot(diff); } +// From https://github.com/RenderKit/embree/blob/master/tutorials/common/math/closest_point.h (thanks VirxEC) +btVector3 closestPointTriangle(btVector3 const& p, btVector3 const& a, btVector3 const& b, btVector3 const& c) { + const btVector3 ab = b - a; + const btVector3 ac = c - a; + const btVector3 ap = p - a; + + const float d1 = ab.dot(ap); + const float d2 = ac.dot(ap); + if (d1 <= 0.f && d2 <= 0.f) return a; //#1 + + const btVector3 bp = p - b; + const float d3 = ab.dot(bp); + const float d4 = ac.dot(bp); + if (d3 >= 0.f && d4 <= d3) return b; //#2 + + const btVector3 cp = p - c; + const float d5 = ab.dot(cp); + const float d6 = ac.dot(cp); + if (d6 >= 0.f && d5 <= d6) return c; //#3 + + const float vc = d1 * d4 - d3 * d2; + if (vc <= 0.f && d1 >= 0.f && d3 <= 0.f) { + const float v = d1 / (d1 - d3); + return a + v * ab; //#4 + } + + const float vb = d5 * d2 - d1 * d6; + if (vb <= 0.f && d2 >= 0.f && d6 <= 0.f) { + const float v = d2 / (d2 - d6); + return a + v * ac; //#5 + } + + const float va = d3 * d6 - d5 * d4; + if (va <= 0.f && (d4 - d3) >= 0.f && (d5 - d6) >= 0.f) { + const float v = (d4 - d3) / ((d4 - d3) + (d5 - d6)); + return b + v * (c - b); //#6 + } + + const float denom = 1.f / (va + vb + vc); + const float v = vb * denom; + const float w = vc * denom; + return a + v * ab + w * ac; //#0 +} + bool SphereTriangleDetector::facecontains(const btVector3& p, const btVector3* vertices, btVector3& normal) { btVector3 lp(p); @@ -136,8 +180,10 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter, btVector3& p // Could be inside one of the contact capsules btScalar contactCapsuleRadiusSqr = radiusWithThreshold * radiusWithThreshold; btScalar minDistSqr = contactCapsuleRadiusSqr; + +#if 0 // Bullet's method btVector3 nearestOnEdge; - for (int i = 0; i < m_triangle->getNumEdges(); i++) + for (int i = 0; i < 3; i++) { btVector3 pa; btVector3 pb; @@ -153,8 +199,19 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter, btVector3& p contactPoint = nearestOnEdge; } } +#else // Faster method (thanks VirxEC) + // https://github.com/VirxEC/rl_ball_sym/blob/99b50b381cd529e567c9a33ab10464b89484227a/src/simulation/geometry.rs + btVector3 nearestOnEdge = closestPointTriangle(sphereCenter, vertices[0], vertices[1], vertices[2]); + btScalar distanceSqr = nearestOnEdge.distance2(sphereCenter); + if (distanceSqr < minDistSqr) { + minDistSqr = distanceSqr; + hasContact = true; + contactPoint = nearestOnEdge; + } +#endif } } + } if (hasContact) @@ -187,6 +244,8 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter, btVector3& p bool SphereTriangleDetector::pointInTriangle(const btVector3 vertices[], const btVector3& normal, btVector3* p) { + +#if 0 // Bullet's method const btVector3* p1 = &vertices[0]; const btVector3* p2 = &vertices[1]; const btVector3* p3 = &vertices[2]; @@ -211,4 +270,27 @@ bool SphereTriangleDetector::pointInTriangle(const btVector3 vertices[], const b (r1 <= 0 && r2 <= 0 && r3 <= 0)) return true; return false; +#else // A faster method from https://gamedev.stackexchange.com/questions/28781/easy-way-to-project-point-onto-triangle-or-plane/152476#152476 (thanks VirxEC) + + const btVector3& + p0 = vertices[0], + p1 = vertices[1], + p2 = vertices[2]; + + btVector3 u = p1 - p0; + btVector3 v = p2 - p0; + btVector3 n = u.cross(v); + float nLenSq = n.dot(n); + + btVector3 w = *p - p0; + + float gamma = u.cross(w).dot(n) / nLenSq; + + float beta = w.cross(v).dot(n) / nLenSq; + float alpha = 1 - gamma - beta; + + return ((0 <= alpha) && (alpha <= 1) && + (0 <= beta) && (beta <= 1) && + (0 <= gamma) && (gamma <= 1)); +#endif } diff --git a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionObject.cpp b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionObject.cpp index e49fac58..e9d58c35 100644 --- a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionObject.cpp +++ b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionObject.cpp @@ -16,6 +16,8 @@ subject to the following restrictions: #include "btCollisionObject.h" #include "../BroadphaseCollision/btBroadphaseProxy.h" +#include "../CollisionShapes/btCollisionShape.h" + btCollisionObject::btCollisionObject() : m_interpolationLinearVelocity(0.f, 0.f, 0.f), m_interpolationAngularVelocity(0.f, 0.f, 0.f), @@ -75,4 +77,11 @@ void btCollisionObject::activate(bool forceActivation) const setActivationState(ACTIVE_TAG); m_deactivationTime = btScalar(0.); } +} + +void btCollisionObject::setWorldTransform(const btTransform& worldTrans) { + m_updateRevision++; + m_worldTransform = worldTrans; + if (m_collisionShape) + m_collisionShape->m_aabbCached = false; } \ No newline at end of file diff --git a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionObject.h b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionObject.h index 9780d0d5..b5c3df64 100644 --- a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionObject.h +++ b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionObject.h @@ -49,9 +49,10 @@ typedef btAlignedObjectArray btCollisionObjectArray; ATTRIBUTE_ALIGNED16(class) btCollisionObject { -public: +private: btTransform m_worldTransform; +public: ///m_interpolationWorldTransform is used for CCD and interpolation ///it can be either previous or future (predicted) transform btTransform m_interpolationWorldTransform; @@ -400,11 +401,7 @@ btCollisionObject return m_worldTransform; } - void setWorldTransform(const btTransform& worldTrans) - { - m_updateRevision++; - m_worldTransform = worldTrans; - } + void setWorldTransform(const btTransform& worldTrans); SIMD_FORCE_INLINE btBroadphaseProxy* getBroadphaseHandle() { diff --git a/libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.cpp b/libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.cpp index 7f28bcec..04da1817 100644 --- a/libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.cpp +++ b/libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.cpp @@ -63,14 +63,14 @@ void btRigidBody::setupRigidBody(const btRigidBody::btRigidBodyConstructionInfo& if (m_optionalMotionState) { - m_optionalMotionState->getWorldTransform(m_worldTransform); + m_optionalMotionState->getWorldTransform(getWorldTransform()); } else { - m_worldTransform = constructionInfo.m_startWorldTransform; + setWorldTransform(constructionInfo.m_startWorldTransform); } - m_interpolationWorldTransform = m_worldTransform; + m_interpolationWorldTransform = getWorldTransform(); m_interpolationLinearVelocity.setValue(0, 0, 0); m_interpolationAngularVelocity.setValue(0, 0, 0); @@ -100,9 +100,9 @@ void btRigidBody::predictIntegratedTransform(btScalar timeStep, btTransform& pre { if (m_noRot) { - btTransformUtil::integrateTransformNoRot(m_worldTransform, m_linearVelocity, m_angularVelocity, timeStep, predictedTransform); + btTransformUtil::integrateTransformNoRot(getWorldTransform(), m_linearVelocity, m_angularVelocity, timeStep, predictedTransform); } else { - btTransformUtil::integrateTransform(m_worldTransform, m_linearVelocity, m_angularVelocity, timeStep, predictedTransform); + btTransformUtil::integrateTransform(getWorldTransform(), m_linearVelocity, m_angularVelocity, timeStep, predictedTransform); } } @@ -113,20 +113,20 @@ void btRigidBody::saveKinematicState(btScalar timeStep) { //if we use motionstate to synchronize world transforms, get the new kinematic/animated world transform if (getMotionState()) - getMotionState()->getWorldTransform(m_worldTransform); + getMotionState()->getWorldTransform(getWorldTransform()); btVector3 linVel, angVel; - btTransformUtil::calculateVelocity(m_interpolationWorldTransform, m_worldTransform, timeStep, m_linearVelocity, m_angularVelocity); + btTransformUtil::calculateVelocity(m_interpolationWorldTransform, getWorldTransform(), timeStep, m_linearVelocity, m_angularVelocity); m_interpolationLinearVelocity = m_linearVelocity; m_interpolationAngularVelocity = m_angularVelocity; - m_interpolationWorldTransform = m_worldTransform; + m_interpolationWorldTransform = getWorldTransform(); //printf("angular = %f %f %f\n",m_angularVelocity.getX(),m_angularVelocity.getY(),m_angularVelocity.getZ()); } } void btRigidBody::getAabb(btVector3& aabbMin, btVector3& aabbMax) const { - getCollisionShape()->getAabb(m_worldTransform, aabbMin, aabbMax); + getCollisionShape()->getAabb(getWorldTransform(), aabbMin, aabbMax); } void btRigidBody::setGravity(const btVector3& acceleration) @@ -252,7 +252,7 @@ void btRigidBody::setMassProps(btScalar mass, const btVector3& inertia) void btRigidBody::updateInertiaTensor() { - m_invInertiaTensorWorld = m_worldTransform.getBasis().scaled(m_invInertiaLocal) * m_worldTransform.getBasis().transpose(); + m_invInertiaTensorWorld = getWorldTransform().getBasis().scaled(m_invInertiaLocal) * getWorldTransform().getBasis().transpose(); } btVector3 btRigidBody::getLocalInertia() const @@ -347,8 +347,8 @@ btVector3 btRigidBody::computeGyroscopicImpulseImplicit_World(btScalar step) con btMatrix3x3 I; - I = m_worldTransform.getBasis().scaled(inertiaLocal) * - m_worldTransform.getBasis().transpose(); + I = getWorldTransform().getBasis().scaled(inertiaLocal) * + getWorldTransform().getBasis().transpose(); // use newtons method to find implicit solution for new angular velocity (w') // f(w') = -(T*step + Iw) + Iw' + w' + w'xIw'*step = 0 @@ -396,7 +396,7 @@ void btRigidBody::integrateVelocities(btScalar step) btQuaternion btRigidBody::getOrientation() const { btQuaternion orn; - m_worldTransform.getBasis().getRotation(orn); + getWorldTransform().getBasis().getRotation(orn); return orn; } @@ -404,7 +404,7 @@ void btRigidBody::setCenterOfMassTransform(const btTransform& xform) { if (isKinematicObject()) { - m_interpolationWorldTransform = m_worldTransform; + m_interpolationWorldTransform = getWorldTransform(); } else { @@ -412,7 +412,7 @@ void btRigidBody::setCenterOfMassTransform(const btTransform& xform) } m_interpolationLinearVelocity = getLinearVelocity(); m_interpolationAngularVelocity = getAngularVelocity(); - m_worldTransform = xform; + setWorldTransform(xform); updateInertiaTensor(); } diff --git a/libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.h b/libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.h index 34980200..d6fec700 100644 --- a/libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.h +++ b/libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.h @@ -431,13 +431,13 @@ class btRigidBody : public btCollisionObject const btVector3& getCenterOfMassPosition() const { - return m_worldTransform.getOrigin(); + return getWorldTransform().getOrigin(); } btQuaternion getOrientation() const; const btTransform& getCenterOfMassTransform() const { - return m_worldTransform; + return getWorldTransform(); } const btVector3& getLinearVelocity() const { @@ -485,7 +485,9 @@ class btRigidBody : public btCollisionObject void translate(const btVector3& v) { - m_worldTransform.getOrigin() += v; + btTransform newWorldTransform = getWorldTransform(); + newWorldTransform.getOrigin() += v; + setWorldTransform(newWorldTransform); } void getAabb(btVector3& aabbMin, btVector3& aabbMax) const; @@ -569,7 +571,7 @@ class btRigidBody : public btCollisionObject { m_optionalMotionState = motionState; if (m_optionalMotionState) - motionState->getWorldTransform(m_worldTransform); + motionState->getWorldTransform(getWorldTransform()); } //for experimental overriding of friction/contact solver func diff --git a/libsrc/bullet3-3.24/LinearMath/btAabbUtil2.h b/libsrc/bullet3-3.24/LinearMath/btAabbUtil2.h index 67ff479c..29d28bf2 100644 --- a/libsrc/bullet3-3.24/LinearMath/btAabbUtil2.h +++ b/libsrc/bullet3-3.24/LinearMath/btAabbUtil2.h @@ -58,14 +58,14 @@ SIMD_FORCE_INLINE bool TestTriangleAgainstAabb2(const btVector3* vertices, const btVector3& p2 = vertices[1]; const btVector3& p3 = vertices[2]; - if (btMin(btMin(p1[0], p2[0]), p3[0]) > aabbMax[0]) return false; - if (btMax(btMax(p1[0], p2[0]), p3[0]) < aabbMin[0]) return false; + // First check Z, then X, then Y + constexpr int INDEX_ORDER[] = { 2, 0, 1 }; - if (btMin(btMin(p1[2], p2[2]), p3[2]) > aabbMax[2]) return false; - if (btMax(btMax(p1[2], p2[2]), p3[2]) < aabbMin[2]) return false; - - if (btMin(btMin(p1[1], p2[1]), p3[1]) > aabbMax[1]) return false; - if (btMax(btMax(p1[1], p2[1]), p3[1]) < aabbMin[1]) return false; + for (int i : INDEX_ORDER) { + if (btMin(btMin(p1[i], p2[i]), p3[i]) > aabbMax[i]) return false; + if (btMax(btMax(p1[i], p2[i]), p3[i]) < aabbMin[i]) return false; + } + return true; } diff --git a/libsrc/bullet3-3.24/LinearMath/btQuickprof.h b/libsrc/bullet3-3.24/LinearMath/btQuickprof.h index 990d401d..d3e84e70 100644 --- a/libsrc/bullet3-3.24/LinearMath/btQuickprof.h +++ b/libsrc/bullet3-3.24/LinearMath/btQuickprof.h @@ -195,6 +195,7 @@ class CProfileSample ~CProfileSample(void); }; -#define BT_PROFILE(name) CProfileSample __profile(name) +//#define BT_PROFILE(name) CProfileSample __profile(name) +#define BT_PROFILE(name) #endif //BT_QUICK_PROF_H diff --git a/python-mtheall/Makefile b/python-mtheall/Makefile index 017b1e5b..3b4585cd 100644 --- a/python-mtheall/Makefile +++ b/python-mtheall/Makefile @@ -11,7 +11,7 @@ wheel: build $(PYTHON) ../setup.py bdist_wheel --py-limited-api=cp34 install: wheel - $(PYTHON) -m pip install --force-reinstall --user ./dist/RocketSim-2.1.0-cp34-abi3-linux_x86_64.whl + $(PYTHON) -m pip install --force-reinstall --user ./dist/RocketSim-2.1.0.post1-cp34-abi3-linux_x86_64.whl clean: $(RM) -r build/ dist/ RocketSim.egg-info/ diff --git a/setup.py b/setup.py index 5ffc938f..4aecc0e1 100755 --- a/setup.py +++ b/setup.py @@ -88,7 +88,7 @@ def build_extension(self, ext): setup( name = "RocketSim", - version = "2.1.0", + version = "2.1.0.post1", description = "This is Rocket League!", cmdclass = {"build_ext": build_ext_ex}, ext_modules = [RocketSim], diff --git a/src/Sim/Arena/Arena.cpp b/src/Sim/Arena/Arena.cpp index 05d95a35..13544c09 100644 --- a/src/Sim/Arena/Arena.cpp +++ b/src/Sim/Arena/Arena.cpp @@ -815,7 +815,7 @@ void Arena::Step(int ticksToSimulate) { if (_goalScoreCallback.func != NULL) { // Potentially fire goal score callback if (IsBallScored()) { - _goalScoreCallback.func(this, RS_TEAM_FROM_Y(-ball->_rigidBody.m_worldTransform.m_origin.y()), _goalScoreCallback.userInfo); + _goalScoreCallback.func(this, RS_TEAM_FROM_Y(-ball->_rigidBody.getWorldTransform().m_origin.y()), _goalScoreCallback.userInfo); } } @@ -841,7 +841,7 @@ float BallWithinHoopsGoalXYMarginSq(float x, float y) { } bool Arena::IsBallProbablyGoingIn(float maxTime, float extraMargin, Team* goalTeamOut) const { - Vec ballPos = ball->_rigidBody.m_worldTransform.m_origin * BT_TO_UU; + Vec ballPos = ball->_rigidBody.getWorldTransform().m_origin * BT_TO_UU; Vec ballVel = ball->_rigidBody.m_linearVelocity * BT_TO_UU; if (gameMode == GameMode::SOCCAR || gameMode == GameMode::SNOWDAY) { @@ -968,18 +968,18 @@ RSAPI bool Arena::IsBallScored() const { case GameMode::HEATSEEKER: case GameMode::SNOWDAY: { - float ballPosY = ball->_rigidBody.m_worldTransform.m_origin.y() * BT_TO_UU; + float ballPosY = ball->_rigidBody.getWorldTransform().m_origin.y() * BT_TO_UU; return abs(ballPosY) > (RLConst::SOCCAR_GOAL_SCORE_BASE_THRESHOLD_Y + _mutatorConfig.ballRadius); } case GameMode::HOOPS: { - if (ball->_rigidBody.m_worldTransform.m_origin.z() < RLConst::HOOPS_GOAL_SCORE_THRESHOLD_Z * UU_TO_BT) { + if (ball->_rigidBody.getWorldTransform().m_origin.z() < RLConst::HOOPS_GOAL_SCORE_THRESHOLD_Z * UU_TO_BT) { constexpr float SCALE_Y = 0.9f, OFFSET_Y = 2770.f, RADIUS_SQ = 716 * 716; - Vec ballPos = ball->_rigidBody.m_worldTransform.m_origin * BT_TO_UU; + Vec ballPos = ball->_rigidBody.getWorldTransform().m_origin * BT_TO_UU; return BallWithinHoopsGoalXYMarginSq(ballPos.x, ballPos.y) < 0; } else { return false; diff --git a/src/Sim/Arena/ArenaConfig/ArenaConfig.h b/src/Sim/Arena/ArenaConfig/ArenaConfig.h index 82d1d662..240e2371 100644 --- a/src/Sim/Arena/ArenaConfig/ArenaConfig.h +++ b/src/Sim/Arena/ArenaConfig/ArenaConfig.h @@ -15,7 +15,7 @@ enum class ArenaMemWeightMode : byte { struct ArenaConfig { - ArenaMemWeightMode memWeightMode = ArenaMemWeightMode::LIGHT; + ArenaMemWeightMode memWeightMode = ArenaMemWeightMode::HEAVY; // Mininimum and maximum positions all physics objects Vec minPos = Vec(-4500, -6000, 0), diff --git a/src/Sim/BoostPad/BoostPad.cpp b/src/Sim/BoostPad/BoostPad.cpp index bbeae819..0cb272c8 100644 --- a/src/Sim/BoostPad/BoostPad.cpp +++ b/src/Sim/BoostPad/BoostPad.cpp @@ -39,7 +39,7 @@ void BoostPad::_PreTickUpdate(float tickTime) { void BoostPad::_CheckCollide(Car* car) { using namespace RLConst::BoostPads; - Vec carPosBT = car->_rigidBody.m_worldTransform.m_origin; + Vec carPosBT = car->_rigidBody.getWorldTransform().m_origin; bool colliding = false; if (_internalState.prevLockedCarID == car->id) { diff --git a/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.cpp b/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.cpp index 4a5ffe18..dfd982a4 100644 --- a/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.cpp +++ b/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.cpp @@ -6,7 +6,7 @@ void BoostPadGrid::CheckCollision(Car* car) { if (car->_internalState.isDemoed || car->_internalState.boost >= 100) return; - Vec carPos = car->_rigidBody.m_worldTransform.m_origin * BT_TO_UU; + Vec carPos = car->_rigidBody.getWorldTransform().m_origin * BT_TO_UU; if (carPos.z > EXTENT_Z) return; diff --git a/src/Sim/Car/Car.cpp b/src/Sim/Car/Car.cpp index cc57da82..06678855 100644 --- a/src/Sim/Car/Car.cpp +++ b/src/Sim/Car/Car.cpp @@ -9,7 +9,7 @@ RS_NS_START // Update our internal state from bullet and return it CarState Car::GetState() { if (!_internalState.isDemoed) { - _internalState.pos = _rigidBody.m_worldTransform.m_origin * BT_TO_UU; + _internalState.pos = _rigidBody.getWorldTransform().m_origin * BT_TO_UU; // NOTE: rotMat already updated at the start of Car::_PostTickUpdate() @@ -27,7 +27,7 @@ void Car::SetState(const CarState& state) { rbTransform.setOrigin(state.pos * UU_TO_BT); rbTransform.setBasis(state.rotMat); - _rigidBody.m_worldTransform = rbTransform; + _rigidBody.getWorldTransform() = rbTransform; _rigidBody.m_linearVelocity = state.vel * UU_TO_BT; _rigidBody.m_angularVelocity = state.angVel; @@ -93,7 +93,7 @@ void Car::_PreTickUpdate(GameMode gameMode, float tickTime, const MutatorConfig& _bulletVehicle.updateVehicleFirst(tickTime, grid); - btMatrix3x3 basis = _rigidBody.m_worldTransform.m_basis; + btMatrix3x3 basis = _rigidBody.getWorldTransform().m_basis; bool jumpPressed = controls.jump && !_internalState.lastControls.jump; @@ -131,7 +131,7 @@ void Car::_PostTickUpdate(GameMode gameMode, float tickTime, const MutatorConfig if (_internalState.isDemoed) return; - _internalState.rotMat = _rigidBody.m_worldTransform.m_basis; + _internalState.rotMat = _rigidBody.getWorldTransform().m_basis; // Update wheelsWithContact int numWheelsInContact = 0; @@ -432,7 +432,7 @@ void Car::_UpdateWheels(float tickTime, const MutatorConfig& mutatorConfig, int float frictionCurveInput = 0; - btVector3 wheelDelta = wheel.m_raycastInfo.m_hardPointWS - _rigidBody.m_worldTransform.m_origin; + btVector3 wheelDelta = wheel.m_raycastInfo.m_hardPointWS - _rigidBody.getWorldTransform().m_origin; auto crossVec = (angularVel.cross(wheelDelta) + vel) * BT_TO_UU; @@ -594,7 +594,7 @@ void Car::_UpdateAirTorque(float tickTime, const MutatorConfig& mutatorConfig, b relDodgeTorque.y() *= pitchScale; btVector3 dodgeTorque = relDodgeTorque * btVector3(FLIP_TORQUE_X, FLIP_TORQUE_Y, 0); - _rigidBody.applyTorque(_rigidBody.m_invInertiaTensorWorld.inverse() * _rigidBody.m_worldTransform.m_basis * dodgeTorque); + _rigidBody.applyTorque(_rigidBody.m_invInertiaTensorWorld.inverse() * _rigidBody.getWorldTransform().m_basis * dodgeTorque); } else { // Stall, allow air control doAirControl = true; diff --git a/src/Sim/GameEventTracker/GameEventTracker.cpp b/src/Sim/GameEventTracker/GameEventTracker.cpp index 7629c2c7..0d163326 100644 --- a/src/Sim/GameEventTracker/GameEventTracker.cpp +++ b/src/Sim/GameEventTracker/GameEventTracker.cpp @@ -65,7 +65,7 @@ void GameEventTracker::Update(Arena* arena) { Car* passer; if (GetShooterPasser( arena, - RS_TEAM_FROM_Y(-arena->ball->_rigidBody.m_worldTransform.m_origin.y()), + RS_TEAM_FROM_Y(-arena->ball->_rigidBody.getWorldTransform().m_origin.y()), shooter, true, passer, config.goalMaxTouchTime * tickrate, config.passMaxTouchTime * tickrate diff --git a/src/Sim/btVehicleRL/btVehicleRL.cpp b/src/Sim/btVehicleRL/btVehicleRL.cpp index 065abb6a..c9f6c3eb 100644 --- a/src/Sim/btVehicleRL/btVehicleRL.cpp +++ b/src/Sim/btVehicleRL/btVehicleRL.cpp @@ -166,7 +166,7 @@ float btVehicleRL::rayCast(btWheelInfoRL& wheel, SuspensionCollisionGrid* grid) float denominator = wheel.m_raycastInfo.m_contactNormalWS.dot(getUpVector()); - btVector3 relpos = wheel.m_raycastInfo.m_contactPointWS - m_chassisBody->m_worldTransform.m_origin; + btVector3 relpos = wheel.m_raycastInfo.m_contactPointWS - m_chassisBody->getWorldTransform().m_origin; wheel.m_velAtContactPoint = m_chassisBody->getVelocityInLocalPoint(relpos); float projVel = wheel.m_raycastInfo.m_contactNormalWS.dot(wheel.m_velAtContactPoint);