From 7879fb82097d8a8adb93f8de06c96709ded5f5e5 Mon Sep 17 00:00:00 2001 From: stephengold Date: Wed, 6 Nov 2024 18:11:14 -0800 Subject: [PATCH] samples: invoke getPtr() so Ref subclasses needn't implement so much --- .../samples/character/CharacterBaseTest.java | 4 +- .../character/CharacterPlanetTest.java | 24 +++---- .../character/CharacterSpaceShipTest.java | 16 ++--- .../app/samples/character/CharacterTest.java | 24 +++---- .../character/CharacterVirtualTest.java | 72 +++++++++---------- .../constraints/ConstraintPriorityTest.java | 2 +- .../shapes/DeformedHeightFieldShapeTest.java | 4 +- 7 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/test/java/testjoltjni/app/samples/character/CharacterBaseTest.java b/src/test/java/testjoltjni/app/samples/character/CharacterBaseTest.java index 21ac2303..4acec0e3 100644 --- a/src/test/java/testjoltjni/app/samples/character/CharacterBaseTest.java +++ b/src/test/java/testjoltjni/app/samples/character/CharacterBaseTest.java @@ -595,7 +595,7 @@ else if (sSceneName.equals( "ObstacleCourse") ) { CharacterVirtualSettings settings=new CharacterVirtualSettings(); settings.setShape ( mStandingShape); - settings.setInnerBodyShape ( mInnerStandingShape); + settings.setInnerBodyShape ( mInnerStandingShape.getPtr()); settings.setSupportingVolume (new Plane(Vec3.sAxisY(), -cCharacterRadiusStanding)); // Accept contacts that touch the lower sphere of the capsule mAnimatedCharacterVirtualWithInnerBody = new CharacterVirtual(settings, cCharacterVirtualWithInnerBodyPosition, Quat.sIdentity(), 0, mPhysicsSystem).toRef(); mAnimatedCharacterVirtualWithInnerBody.getPtr().setCharacterVsCharacterCollision(mCharacterVsCharacterCollision); @@ -689,7 +689,7 @@ else if (pos.yy() > cReversingVerticallyMovingPosition.yy() + 5.0f) if (character.getGroundState() == EGroundState.OnGround) velocity = Vec3.sZero(); else - velocity = Op.add(Op.multiply(character.getLinearVelocity() , mAnimatedCharacter.getUp()) , Op.multiply(mPhysicsSystem.getGravity() , inParams.mDeltaTime)); + velocity = Op.add(Op.multiply(character.getLinearVelocity() , mAnimatedCharacter.getPtr().getUp()) , Op.multiply(mPhysicsSystem.getGravity() , inParams.mDeltaTime)); Op.plusEquals(velocity , Op.multiply((float)Math.sin(mTime) , cCharacterVelocity)); character.setLinearVelocity(velocity); diff --git a/src/test/java/testjoltjni/app/samples/character/CharacterPlanetTest.java b/src/test/java/testjoltjni/app/samples/character/CharacterPlanetTest.java index b4ccd594..d9ff36e2 100644 --- a/src/test/java/testjoltjni/app/samples/character/CharacterPlanetTest.java +++ b/src/test/java/testjoltjni/app/samples/character/CharacterPlanetTest.java @@ -112,23 +112,23 @@ void ProcessInput(const ProcessInputParams &inParams) public void PrePhysicsUpdate(PreUpdateParams inParams) { // Calculate up vector based on position on planet surface - Vec3 old_up = mCharacter.getUp(); - Vec3 up =new Vec3(mCharacter.getPosition()).normalized(); + Vec3 old_up = mCharacter.getPtr().getUp(); + Vec3 up =new Vec3(mCharacter.getPtr().getPosition()).normalized(); mCharacter.getPtr().setUp(up); // Rotate capsule so it points up relative to the planet surface - mCharacter.getPtr().setRotation(Op.multiply(Quat.sFromTo(old_up, up) , mCharacter.getRotation()).normalized()); + mCharacter.getPtr().setRotation(Op.multiply(Quat.sFromTo(old_up, up) , mCharacter.getPtr().getRotation()).normalized()); // Draw character pre update (the sim is also drawn pre update) if (Jolt.implementsDebugRendering()) { - mCharacter.getShape().draw(mDebugRenderer, mCharacter.getCenterOfMassTransform(), Vec3.sReplicate(1.0f), Color.sGreen, false, true); + mCharacter.getPtr().getShape().draw(mDebugRenderer, mCharacter.getPtr().getCenterOfMassTransform(), Vec3.sReplicate(1.0f), Color.sGreen, false, true); } // Determine new character velocity - Vec3 current_vertical_velocity = Op.multiply(mCharacter.getLinearVelocity().dot(up) , up); - Vec3 ground_velocity = mCharacter.getGroundVelocity(); + Vec3 current_vertical_velocity = Op.multiply(mCharacter.getPtr().getLinearVelocity().dot(up) , up); + Vec3 ground_velocity = mCharacter.getPtr().getGroundVelocity(); Vec3 new_velocity; - if (mCharacter.getGroundState() == EGroundState.OnGround // If on ground + if (mCharacter.getPtr().getGroundState() == EGroundState.OnGround // If on ground && Op.subtract(current_vertical_velocity , ground_velocity).dot(up) < 0.1f) // And not moving away from ground { // Assume velocity of ground when on ground @@ -173,23 +173,23 @@ RMat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) { // Pivot is center of character + distance behind based on the heading and pitch of the camera. Vec3 fwd = new Vec3(Math.cos(inCameraPitch) * Math.cos(inCameraHeading), Math.sin(inCameraPitch), Math.cos(inCameraPitch) * Math.sin(inCameraHeading)); - RVec3 cam_pos = Op.subtract(mCharacter.getPosition() , Op.multiply(5.0f , Op.rotate(mCharacter.getRotation() , fwd))); - return RMat44.sRotationTranslation(mCharacter.getRotation(), cam_pos); + RVec3 cam_pos = Op.subtract(mCharacter.getPtr().getPosition() , Op.multiply(5.0f , Op.rotate(mCharacter.getPtr().getRotation() , fwd))); + return RMat44.sRotationTranslation(mCharacter.getPtr().getRotation(), cam_pos); } void SaveState(StateRecorder inStream) { - mCharacter.saveState(inStream); + mCharacter.getPtr().saveState(inStream); // Save character up, it's not stored by default but we use it in this case update the rotation of the character - inStream.write(mCharacter.getUp()); + inStream.write(mCharacter.getPtr().getUp()); } void RestoreState(StateRecorder inStream) { mCharacter.getPtr().restoreState(inStream); - Vec3 up = mCharacter.getUp(); + Vec3 up = mCharacter.getPtr().getUp(); inStream.readVec3(up); mCharacter.getPtr().setUp(up); } diff --git a/src/test/java/testjoltjni/app/samples/character/CharacterSpaceShipTest.java b/src/test/java/testjoltjni/app/samples/character/CharacterSpaceShipTest.java index c17b2c03..b802c545 100644 --- a/src/test/java/testjoltjni/app/samples/character/CharacterSpaceShipTest.java +++ b/src/test/java/testjoltjni/app/samples/character/CharacterSpaceShipTest.java @@ -109,7 +109,7 @@ public void PrePhysicsUpdate(PreUpdateParams inParams) // Update the character so it stays relative to the space ship RMat44 new_space_ship_transform = mBodyInterface.getCenterOfMassTransform(mSpaceShip); - mCharacter.getPtr().setPosition(Op.multiply(Op.multiply(new_space_ship_transform , mSpaceShipPrevTransform.inversed()) , mCharacter.getPosition())); + mCharacter.getPtr().setPosition(Op.multiply(Op.multiply(new_space_ship_transform , mSpaceShipPrevTransform.inversed()) , mCharacter.getPtr().getPosition())); // Update the character rotation and its up vector to match the new up vector of the ship mCharacter.getPtr().setUp(new_space_ship_transform.getAxisY()); @@ -118,14 +118,14 @@ public void PrePhysicsUpdate(PreUpdateParams inParams) // Draw character pre update (the sim is also drawn pre update) // Note that we have first updated the position so that it matches the new position of the ship if(Jolt.implementsDebugRendering()){ - mCharacter.getShape().draw(mDebugRenderer, mCharacter.getCenterOfMassTransform(), Vec3.sReplicate(1.0f), Color.sGreen, false, true); + mCharacter.getPtr().getShape().draw(mDebugRenderer, mCharacter.getPtr().getCenterOfMassTransform(), Vec3.sReplicate(1.0f), Color.sGreen, false, true); } // JPH_DEBUG_RENDERER // Determine new character velocity - Vec3 current_vertical_velocity =Op.multiply( mCharacter.getLinearVelocity().dot(mSpaceShipPrevTransform.getAxisY()) , mCharacter.getUp()); - Vec3 ground_velocity = mCharacter.getGroundVelocity(); + Vec3 current_vertical_velocity =Op.multiply( mCharacter.getPtr().getLinearVelocity().dot(mSpaceShipPrevTransform.getAxisY()) , mCharacter.getPtr().getUp()); + Vec3 ground_velocity = mCharacter.getPtr().getGroundVelocity(); Vec3 new_velocity; - if (mCharacter.getGroundState() == EGroundState.OnGround // If on ground + if (mCharacter.getPtr().getGroundState() == EGroundState.OnGround // If on ground && (current_vertical_velocity.getY() - ground_velocity.getY()) < 0.1f) // And not moving away from ground { // Assume velocity of ground when on ground @@ -133,7 +133,7 @@ public void PrePhysicsUpdate(PreUpdateParams inParams) // Jump if (mJump) - Op.plusEquals(new_velocity , Op.multiply(cJumpSpeed , mCharacter.getUp())); + Op.plusEquals(new_velocity , Op.multiply(cJumpSpeed , mCharacter.getPtr().getUp())); } else new_velocity = current_vertical_velocity; @@ -186,12 +186,12 @@ RMat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) { // Pivot is center of character + distance behind based on the heading and pitch of the camera Vec3 fwd =new Vec3(Math.cos(inCameraPitch) * Math.cos(inCameraHeading), Math.sin(inCameraPitch), Math.cos(inCameraPitch) * Math.sin(inCameraHeading)); - return RMat44.sTranslation(Op.subtract(Op.add(mCharacter.getPosition() ,new Vec3(0, cCharacterHeightStanding + cCharacterRadiusStanding, 0)) , Op.multiply(5.0f , fwd))); + return RMat44.sTranslation(Op.subtract(Op.add(mCharacter.getPtr().getPosition() ,new Vec3(0, cCharacterHeightStanding + cCharacterRadiusStanding, 0)) , Op.multiply(5.0f , fwd))); } void SaveState(StateRecorder inStream) { - mCharacter.saveState(inStream); + mCharacter.getPtr().saveState(inStream); inStream.write(mTime); inStream.write(mSpaceShipPrevTransform); diff --git a/src/test/java/testjoltjni/app/samples/character/CharacterTest.java b/src/test/java/testjoltjni/app/samples/character/CharacterTest.java index f5a375e1..fde5f4d4 100644 --- a/src/test/java/testjoltjni/app/samples/character/CharacterTest.java +++ b/src/test/java/testjoltjni/app/samples/character/CharacterTest.java @@ -36,7 +36,7 @@ of this software and associated documentation files (the "Software"), to deal public class CharacterTest extends CharacterBaseTest{ static final float cCollisionTolerance = 0.05f; CharacterRef mCharacter; -RVec3 GetCharacterPosition(){return mCharacter.getPosition();} +RVec3 GetCharacterPosition(){return mCharacter.getPtr().getPosition();} public void Initialize() { @@ -58,7 +58,7 @@ void PrePhysicsUpdate(PreUpdateParams inParams) super.PrePhysicsUpdate(inParams); // Draw state of character - DrawCharacterState(mCharacter, mCharacter.getWorldTransform(), mCharacter.getLinearVelocity()); + DrawCharacterState(mCharacter.getPtr(), mCharacter.getPtr().getWorldTransform(), mCharacter.getPtr().getLinearVelocity()); } public void PostPhysicsUpdate(float inDeltaTime) @@ -71,9 +71,9 @@ void SaveState(StateRecorder inStream) { super.SaveState(inStream); - mCharacter.saveState(inStream); + mCharacter.getPtr().saveState(inStream); - boolean is_standing = mCharacter.getShape() == mStandingShape; + boolean is_standing = mCharacter.getPtr().getShape() == mStandingShape.getPtr(); inStream.write(is_standing); } @@ -83,20 +83,20 @@ void RestoreState(StateRecorder inStream) mCharacter.getPtr().restoreState(inStream); - boolean is_standing = mCharacter.getShape() == mStandingShape; // Initialize variable for validation mode + boolean is_standing = mCharacter.getPtr().getShape() == mStandingShape.getPtr(); // Initialize variable for validation mode is_standing = inStream.readBoolean(is_standing); - mCharacter.getPtr().setShape(is_standing? mStandingShape : mCrouchingShape, Float.MAX_VALUE); + mCharacter.getPtr().setShape(is_standing? mStandingShape.getPtr() : mCrouchingShape.getPtr(), Float.MAX_VALUE); } void HandleInput(Vec3Arg inMovementDirection, boolean inJump, boolean inSwitchStance, float inDeltaTime) { // Cancel movement in opposite direction of normal when touching something we can't walk up Vec3 movement_direction =new Vec3(inMovementDirection); - EGroundState ground_state = mCharacter.getGroundState(); + EGroundState ground_state = mCharacter.getPtr().getGroundState(); if (ground_state == EGroundState.OnSteepGround || ground_state == EGroundState.NotSupported) { - Vec3 normal = mCharacter.getGroundNormal(); + Vec3 normal = mCharacter.getPtr().getGroundNormal(); normal.setY(0.0f); float dot = normal.dot(movement_direction); if (dot < 0.0f) @@ -105,14 +105,14 @@ void HandleInput(Vec3Arg inMovementDirection, boolean inJump, boolean inSwitchSt // Stance switch if (inSwitchStance) - mCharacter.getPtr().setShape(mCharacter.getShape() == mStandingShape? mCrouchingShape : mStandingShape, 1.5f * mPhysicsSystem.getPhysicsSettings().getPenetrationSlop()); + mCharacter.getPtr().setShape(mCharacter.getPtr().getShape() == mStandingShape.getPtr()? mCrouchingShape.getPtr() : mStandingShape.getPtr(), 1.5f * mPhysicsSystem.getPhysicsSettings().getPenetrationSlop()); - if (sControlMovementDuringJump || mCharacter.isSupported()) + if (sControlMovementDuringJump || mCharacter.getPtr().isSupported()) { // Update velocity - Vec3 current_velocity =new Vec3(mCharacter.getLinearVelocity()); + Vec3 current_velocity =new Vec3(mCharacter.getPtr().getLinearVelocity()); Vec3 desired_velocity =new Vec3(Op.multiply(sCharacterSpeed , movement_direction)); - if (!desired_velocity.isNearZero() || current_velocity.getY() < 0.0f || !mCharacter.isSupported()) + if (!desired_velocity.isNearZero() || current_velocity.getY() < 0.0f || !mCharacter.getPtr().isSupported()) desired_velocity.setY(current_velocity.getY()); Vec3 new_velocity =new Vec3(Op.add(Op.multiply(0.75f , current_velocity) , Op.multiply(0.25f , desired_velocity))); diff --git a/src/test/java/testjoltjni/app/samples/character/CharacterVirtualTest.java b/src/test/java/testjoltjni/app/samples/character/CharacterVirtualTest.java index 501f9537..75df98ce 100644 --- a/src/test/java/testjoltjni/app/samples/character/CharacterVirtualTest.java +++ b/src/test/java/testjoltjni/app/samples/character/CharacterVirtualTest.java @@ -51,7 +51,7 @@ public class CharacterVirtualTest extends CharacterBaseTest{ CharacterVirtualRef mCharacter=new CharacterVirtualRef(); Vec3 mDesiredVelocity = Vec3.sZero(); boolean mAllowSliding = false; -RVec3 GetCharacterPosition(){return mCharacter.getPosition();} +RVec3 GetCharacterPosition(){return mCharacter.getPtr().getPosition();} public void Initialize() { @@ -68,11 +68,11 @@ public void Initialize() settings.setPredictiveContactDistance ( sPredictiveContactDistance); settings.setSupportingVolume (new Plane(Vec3.sAxisY(), -cCharacterRadiusStanding)); // Accept contacts that touch the lower sphere of the capsule settings.setEnhancedInternalEdgeRemoval ( sEnhancedInternalEdgeRemoval); - settings.setInnerBodyShape ( sCreateInnerBody? mInnerStandingShape : null); + settings.setInnerBodyShape ( sCreateInnerBody? mInnerStandingShape.getPtr() : null); settings.setInnerBodyLayer ( Layers.MOVING); mCharacter = new CharacterVirtual(settings, RVec3.sZero(), Quat.sIdentity(), 0, mPhysicsSystem).toRef(); mCharacter.getPtr().setCharacterVsCharacterCollision(mCharacterVsCharacterCollision); - mCharacterVsCharacterCollision.add(mCharacter); + mCharacterVsCharacterCollision.add(mCharacter.getPtr()); // Install contact listener for all characters for (CharacterVirtual character : mCharacterVsCharacterCollision.getCharactersAsList()) @@ -90,38 +90,38 @@ void PrePhysicsUpdate(PreUpdateParams inParams) super.PrePhysicsUpdate(inParams); // Draw character pre update (the sim is also drawn pre update) - RMat44 com = mCharacter.getCenterOfMassTransform(); - RMat44 world_transform = mCharacter.getWorldTransform(); + RMat44 com = mCharacter.getPtr().getCenterOfMassTransform(); + RMat44 world_transform = mCharacter.getPtr().getWorldTransform(); if(Jolt.implementsDebugRendering()){ - mCharacter.getShape().draw(mDebugRenderer, com, Vec3.sReplicate(1.0f), Color.sGreen, false, true); + mCharacter.getPtr().getShape().draw(mDebugRenderer, com, Vec3.sReplicate(1.0f), Color.sGreen, false, true); } // JPH_DEBUG_RENDERER // Draw shape including padding (only implemented for capsules right now) - if (((RotatedTranslatedShape)mCharacter.getShape()).getInnerShape().getSubType() == EShapeSubType.Capsule) + if (((RotatedTranslatedShape)mCharacter.getPtr().getShape()).getInnerShape().getSubType() == EShapeSubType.Capsule) { - if (mCharacter.getShape() == mStandingShape) - mDebugRenderer.drawCapsule(com, 0.5f * cCharacterHeightStanding, cCharacterRadiusStanding + mCharacter.getCharacterPadding(), Color.sGrey, ECastShadow.Off, EDrawMode.Wireframe); + if (mCharacter.getPtr().getShape() == mStandingShape.getPtr()) + mDebugRenderer.drawCapsule(com, 0.5f * cCharacterHeightStanding, cCharacterRadiusStanding + mCharacter.getPtr().getCharacterPadding(), Color.sGrey, ECastShadow.Off, EDrawMode.Wireframe); else - mDebugRenderer.drawCapsule(com, 0.5f * cCharacterHeightCrouching, cCharacterRadiusCrouching + mCharacter.getCharacterPadding(), Color.sGrey, ECastShadow.Off, EDrawMode.Wireframe); + mDebugRenderer.drawCapsule(com, 0.5f * cCharacterHeightCrouching, cCharacterRadiusCrouching + mCharacter.getPtr().getCharacterPadding(), Color.sGrey, ECastShadow.Off, EDrawMode.Wireframe); } // Remember old position - RVec3 old_position = mCharacter.getPosition(); + RVec3 old_position = mCharacter.getPtr().getPosition(); // Settings for our update function ExtendedUpdateSettings update_settings=new ExtendedUpdateSettings(); if (!sEnableStickToFloor) update_settings.setStickToFloorStepDown ( Vec3.sZero()); else - update_settings.setStickToFloorStepDown ( Op.multiply(Op.negate(mCharacter.getUp()) , update_settings.getStickToFloorStepDown().length())); + update_settings.setStickToFloorStepDown ( Op.multiply(Op.negate(mCharacter.getPtr().getUp()) , update_settings.getStickToFloorStepDown().length())); if (!sEnableWalkStairs) update_settings.setWalkStairsStepUp ( Vec3.sZero()); else - update_settings.setWalkStairsStepUp ( Op.multiply(mCharacter.getUp() , update_settings.getWalkStairsStepUp().length())); + update_settings.setWalkStairsStepUp ( Op.multiply(mCharacter.getPtr().getUp() , update_settings.getWalkStairsStepUp().length())); // Update the character position mCharacter.getPtr().extendedUpdate(inParams.mDeltaTime, - Op.multiply(Op.negate(mCharacter.getUp()) , mPhysicsSystem.getGravity().length()), + Op.multiply(Op.negate(mCharacter.getPtr().getUp()) , mPhysicsSystem.getGravity().length()), update_settings, mPhysicsSystem.getDefaultBroadPhaseLayerFilter(Layers.MOVING), mPhysicsSystem.getDefaultLayerFilter(Layers.MOVING), @@ -130,11 +130,11 @@ void PrePhysicsUpdate(PreUpdateParams inParams) mTempAllocator); // Calculate effective velocity - RVec3 new_position = mCharacter.getPosition(); + RVec3 new_position = mCharacter.getPtr().getPosition(); Vec3 velocity = Op.divide(Op.subtract(new_position , old_position) , inParams.mDeltaTime).toVec3(); // Draw state of character - DrawCharacterState(mCharacter, world_transform, velocity); + DrawCharacterState(mCharacter.getPtr(), world_transform, velocity); // Draw labels on ramp blocks for (int i = 0; i < mRampBlocks.size(); ++i) @@ -143,7 +143,7 @@ void PrePhysicsUpdate(PreUpdateParams inParams) void HandleInput(Vec3Arg inMovementDirection, boolean inJump, boolean inSwitchStance, float inDeltaTime) { - boolean player_controls_horizontal_velocity = sControlMovementDuringJump || mCharacter.isSupported(); + boolean player_controls_horizontal_velocity = sControlMovementDuringJump || mCharacter.getPtr().isSupported(); if (player_controls_horizontal_velocity) { // Smooth the player input @@ -168,21 +168,21 @@ void HandleInput(Vec3Arg inMovementDirection, boolean inJump, boolean inSwitchSt mCharacter.getPtr().updateGroundVelocity(); // Determine new basic velocity - Vec3 current_vertical_velocity = Op.multiply(mCharacter.getLinearVelocity().dot(mCharacter.getUp()) , mCharacter.getUp()); - Vec3 ground_velocity = mCharacter.getGroundVelocity(); + Vec3 current_vertical_velocity = Op.multiply(mCharacter.getPtr().getLinearVelocity().dot(mCharacter.getPtr().getUp()) , mCharacter.getPtr().getUp()); + Vec3 ground_velocity = mCharacter.getPtr().getGroundVelocity(); Vec3 new_velocity; boolean moving_towards_ground = (current_vertical_velocity.getY() - ground_velocity.getY()) < 0.1f; - if (mCharacter.getGroundState() == EGroundState.OnGround // If on ground + if (mCharacter.getPtr().getGroundState() == EGroundState.OnGround // If on ground && (sEnableCharacterInertia? moving_towards_ground // Inertia enabled: And not moving away from ground - : !mCharacter.isSlopeTooSteep(mCharacter.getGroundNormal()))) // Inertia disabled: And not on a slope that is too steep + : !mCharacter.getPtr().isSlopeTooSteep(mCharacter.getPtr().getGroundNormal()))) // Inertia disabled: And not on a slope that is too steep { // Assume velocity of ground when on ground new_velocity = ground_velocity; // Jump if (inJump && moving_towards_ground) - Op.plusEquals(new_velocity , Op.multiply(sJumpSpeed , mCharacter.getUp())); + Op.plusEquals(new_velocity , Op.multiply(sJumpSpeed , mCharacter.getPtr().getUp())); } else new_velocity = current_vertical_velocity; @@ -198,7 +198,7 @@ void HandleInput(Vec3Arg inMovementDirection, boolean inJump, boolean inSwitchSt else { // Preserve horizontal velocity - Vec3 current_horizontal_velocity = Op.subtract(mCharacter.getLinearVelocity() , current_vertical_velocity); + Vec3 current_horizontal_velocity = Op.subtract(mCharacter.getPtr().getLinearVelocity() , current_vertical_velocity); Op.plusEquals(new_velocity , current_horizontal_velocity); } @@ -208,11 +208,11 @@ void HandleInput(Vec3Arg inMovementDirection, boolean inJump, boolean inSwitchSt // Stance switch if (inSwitchStance) { - boolean is_standing = mCharacter.getShape() == mStandingShape; - ConstShape shape = is_standing? mCrouchingShape : mStandingShape; + boolean is_standing = mCharacter.getPtr().getShape() == mStandingShape.getPtr(); + ConstShape shape = is_standing? mCrouchingShape.getPtr() : mStandingShape.getPtr(); if (mCharacter.getPtr().setShape(shape, 1.5f * mPhysicsSystem.getPhysicsSettings().getPenetrationSlop(), mPhysicsSystem.getDefaultBroadPhaseLayerFilter(Layers.MOVING), mPhysicsSystem.getDefaultLayerFilter(Layers.MOVING), new BodyFilter(){ }, new ShapeFilter(){ }, mTempAllocator)) { - ConstShape inner_shape = is_standing? mInnerCrouchingShape : mInnerStandingShape; + ConstShape inner_shape = is_standing? mInnerCrouchingShape.getPtr() : mInnerStandingShape.getPtr(); mCharacter.getPtr().setInnerBodyShape(inner_shape); } } @@ -247,9 +247,9 @@ void SaveState(StateRecorder inStream) { super.SaveState(inStream); - mCharacter.saveState(inStream); + mCharacter.getPtr().saveState(inStream); - boolean is_standing = mCharacter.getShape() == mStandingShape; + boolean is_standing = mCharacter.getPtr().getShape() == mStandingShape.getPtr(); inStream.write(is_standing); inStream.write(mAllowSliding); @@ -262,11 +262,11 @@ void RestoreState(StateRecorder inStream) mCharacter.getPtr().restoreState(inStream); - boolean is_standing = mCharacter.getShape() == mStandingShape; // Initialize variable for validation mode + boolean is_standing = mCharacter.getPtr().getShape() == mStandingShape.getPtr(); // Initialize variable for validation mode is_standing=inStream.readBoolean(is_standing); - ConstShape shape = is_standing? mStandingShape : mCrouchingShape; + ConstShape shape = is_standing? mStandingShape.getPtr() : mCrouchingShape.getPtr(); mCharacter.getPtr().setShape(shape, Float.MAX_VALUE, new BroadPhaseLayerFilter(){ }, new ObjectLayerFilter(){ }, new BodyFilter(){ }, new ShapeFilter(){ }, mTempAllocator); - ConstShape inner_shape = is_standing? mInnerStandingShape : mInnerCrouchingShape; + ConstShape inner_shape = is_standing? mInnerStandingShape.getPtr() : mInnerCrouchingShape.getPtr(); mCharacter.getPtr().setInnerBodyShape(inner_shape); mAllowSliding=inStream.readBoolean(mAllowSliding); @@ -299,7 +299,7 @@ void OnContactAdded(ConstCharacterVirtual inCharacter, ConstBodyId inBodyID2, Co } // If we encounter an object that can push the player, enable sliding - if (inCharacter == mCharacter + if (inCharacter == mCharacter.getPtr() && ioSettings.getCanPushCharacter() && mPhysicsSystem.getBodyInterface().getMotionType(inBodyID2) != EMotionType.Static) mAllowSliding = true; @@ -309,21 +309,21 @@ void OnCharacterContactAdded(ConstCharacterVirtual inCharacter, ConstCharacterVi { // Characters can only be pushed in their own update if (sPlayerCanPushOtherCharacters) - ioSettings.setCanPushCharacter ( sOtherCharactersCanPushPlayer || inOtherCharacter == mCharacter); + ioSettings.setCanPushCharacter ( sOtherCharactersCanPushPlayer || inOtherCharacter == mCharacter.getPtr()); else if (sOtherCharactersCanPushPlayer) - ioSettings.setCanPushCharacter ( inCharacter == mCharacter); + ioSettings.setCanPushCharacter ( inCharacter == mCharacter.getPtr()); else ioSettings.setCanPushCharacter ( false); // If the player can be pushed by the other virtual character, we allow sliding - if (inCharacter == mCharacter && ioSettings.getCanPushCharacter()) + if (inCharacter == mCharacter.getPtr() && ioSettings.getCanPushCharacter()) mAllowSliding = true; } void OnContactSolve(ConstCharacterVirtual inCharacter, ConstBodyId inBodyID2, ConstSubShapeId inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, Vec3Arg inContactVelocity, ConstPhysicsMaterial inContactMaterial, Vec3Arg inCharacterVelocity, Vec3 ioNewCharacterVelocity) { // Ignore callbacks for other characters than the player - if (inCharacter != mCharacter) + if (inCharacter != mCharacter.getPtr()) return; // Don't allow the player to slide down static not-too-steep surfaces when not actively moving and when not on a moving platform diff --git a/src/test/java/testjoltjni/app/samples/constraints/ConstraintPriorityTest.java b/src/test/java/testjoltjni/app/samples/constraints/ConstraintPriorityTest.java index 15f8a2d1..db03384b 100644 --- a/src/test/java/testjoltjni/app/samples/constraints/ConstraintPriorityTest.java +++ b/src/test/java/testjoltjni/app/samples/constraints/ConstraintPriorityTest.java @@ -72,6 +72,6 @@ public void Initialize() public void PostPhysicsUpdate(float inDeltaTime) { for (TwoBodyConstraintRef c : mConstraints) - mDebugRenderer.drawText3D(Op.multiply(0.5f , Op.add(c.getBody1().getCenterOfMassPosition() , c.getBody2().getCenterOfMassPosition())), String.format("Priority: %d", c.getConstraintPriority()), Color.sWhite, 0.2f); + mDebugRenderer.drawText3D(Op.multiply(0.5f , Op.add(c.getPtr().getBody1().getCenterOfMassPosition() , c.getPtr().getBody2().getCenterOfMassPosition())), String.format("Priority: %d", c.getPtr().getConstraintPriority()), Color.sWhite, 0.2f); } } \ No newline at end of file diff --git a/src/test/java/testjoltjni/app/samples/shapes/DeformedHeightFieldShapeTest.java b/src/test/java/testjoltjni/app/samples/shapes/DeformedHeightFieldShapeTest.java index 827a17b6..6dcd3c23 100644 --- a/src/test/java/testjoltjni/app/samples/shapes/DeformedHeightFieldShapeTest.java +++ b/src/test/java/testjoltjni/app/samples/shapes/DeformedHeightFieldShapeTest.java @@ -72,7 +72,7 @@ public void Initialize() Vec3 center = Op.add(offset , GetPathCenter(t)); // Cast a ray onto the terrain - RShapeCast shape_cast=new RShapeCast(sphere_shape, Vec3.sReplicate(1.0f), RMat44.sTranslation(Op.add(new RVec3(0, 10, 0) , center)),new Vec3(0, -20, 0)); + RShapeCast shape_cast=new RShapeCast(sphere_shape.getPtr(), Vec3.sReplicate(1.0f), RMat44.sTranslation(Op.add(new RVec3(0, 10, 0) , center)),new Vec3(0, -20, 0)); ClosestHitCastShapeCollector collector=new ClosestHitCastShapeCollector(); mPhysicsSystem.getNarrowPhaseQuery().castShape(shape_cast,new ShapeCastSettings(){ }, RVec3.sZero(), collector); if (collector.getHit().getBodyId2() == mHeightFieldID) @@ -117,7 +117,7 @@ public void PrePhysicsUpdate(PreUpdateParams inParams) if (count_x > 0 && count_y > 0) { // Remember COM before we change the height field - Vec3 old_com = mHeightField.getCenterOfMass(); + Vec3 old_com = mHeightField.getPtr().getCenterOfMass(); // A function to calculate the delta height at a certain distance from the center of the pit final float cHalfPi = 0.5f * Jolt.JPH_PI;