java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.NonCopyable
com.github.stephengold.joltjni.CharacterBase
com.github.stephengold.joltjni.CharacterVirtual
- All Implemented Interfaces:
ConstCharacterBase,ConstCharacterVirtual,ConstJoltPhysicsObject,RefTarget,AutoCloseable,Comparable<JoltPhysicsObject>
A character implemented without a rigid body.
-
Constructor Summary
ConstructorsConstructorDescriptionCharacterVirtual(long characterVa, PhysicsSystem physicsSystem) Instantiate a character with the specified native object assigned.CharacterVirtual(ConstCharacterVirtualSettings settings, RVec3Arg location, QuatArg orientation, long userData, PhysicsSystem system) Instantiate a character with a new native object assigned. -
Method Summary
Modifier and TypeMethodDescriptioncancelVelocityTowardsSteepSlopes(Vec3Arg desiredVelocity) Convert the specified velocity to one that won't climb steep slopes.booleancanWalkStairs(Vec3Arg desiredVelocity) Test whether the character has moved onto a steep slope.voidextendedUpdate(float deltaTime, Vec3Arg gravity, ExtendedUpdateSettings settings, BroadPhaseLayerFilter bpFilter, ObjectLayerFilter olFilter, BodyFilter bodyFilter, ShapeFilter shapeFilter, TempAllocator allocator) Apply a combination of Update, StickToFloor, and WalkStairs.Copy the list of active contacts.Calculate the location of the character's center of mass.Calculate the local-to-system transform of the character's center of mass.floatReturn the thickness of the character's padding.Generate settings to reconstruct the character.Access the char-vs-char collision interface.booleanTest whether enhanced internal edge removal is enabled.floatReturn the maximum angle for merging during hit reduction.intgetId()Return the character's ID.intReturn the ID of the inner body.Copy the linear velocity of the character.Access the (application-provided) contact listener.floatgetMass()Return the character's mass.booleanTest whether the last collision check discarded one or more hits.intReturn the maximum number of hits to be collected.floatReturn the maximum force applied to other bodies.floatReturn how quickly penetration is resolved.Copy the location of the character.voidgetPositionAndRotation(RVec3 storeLocation, Quat storeOrientation) Copy the position of the character.Copy the orientation of the character.Copy the local offset applied to the shape.Generate a TransformedShape that represents the volume occupied by the character.longReturn the character's user data: can be used for anything.Calculate the character's local-to-system coordinate transform.booleanhasCollidedWith(int bodyId) Test whether the character is in contact with or collided with the specified body during the previous time step.booleanhasCollidedWith(ConstCharacterVirtual otherCharacter) Test whether the character is in contact with or has collided with the specified character during the previous time step.voidReplace the char-vs-char collision interface.voidsetEnhancedInternalEdgeRemoval(boolean enable) Enable or disable enhanced internal edge removal.voidsetHitReductionCosMaxAngle(float cosine) Alter the maximum angle for merging during hit reduction.voidsetInnerBodyShape(ConstShape shape) Alter the shape of the inner body.voidsetLinearVelocity(float vx, float vy, float vz) Alter the character's linear velocity.voidsetLinearVelocity(Vec3Arg velocity) Alter the character's linear velocity.voidsetListener(CharacterContactListener listener) Replace the contact listener.voidsetMass(float mass) Alter the character's mass.voidsetMaxNumHits(int maxHits) Alter the maximum number of hits to be collected.voidsetMaxStrength(float force) Alter the maximum force applied to bodies.voidsetPenetrationRecoverySpeed(float fraction) Alter how quickly penetration is resolved.voidsetPosition(RVec3Arg location) Relocate the character.voidsetRotation(QuatArg orientation) Re-orient the character.booleansetShape(ConstShape shape, float maxPenetrationDepth, BroadPhaseLayerFilter broadPhaseLayerFilter, ObjectLayerFilter objectLayerFilter, BodyFilter bodyFilter, ShapeFilter shapeFilter, TempAllocator allocator) Alter the character's shape.voidsetShapeOffset(Vec3Arg offset) Alter the shape offset.voidsetUserData(long userData) Alter the user data.toRef()Create a counted reference to the nativeCharacterVirtual.toRefC()Create a counted reference to the nativeCharacterVirtual.voidUpdate the estimated ground velocity.Methods inherited from class com.github.stephengold.joltjni.CharacterBase
getCosMaxSlopeAngle, getGroundBodyId, getGroundMaterial, getGroundNormal, getGroundPosition, getGroundState, getGroundSubShapeId, getGroundUserData, getGroundVelocity, getRefCount, getShape, getUp, isSlopeTooSteep, isSupported, restoreState, saveState, setEmbedded, setMaxSlopeAngle, setUpMethods inherited from class com.github.stephengold.joltjni.JoltPhysicsObject
close, compareTo, equals, getContainingObject, hasAssignedNativeObject, hashCode, isCleanerStarted, ownsNativeObject, setVirtualAddress, setVirtualAddress, startCleaner, targetVa, toString, vaMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods inherited from interface com.github.stephengold.joltjni.readonly.ConstCharacterBase
getCosMaxSlopeAngle, getGroundBodyId, getGroundMaterial, getGroundNormal, getGroundPosition, getGroundState, getGroundSubShapeId, getGroundUserData, getGroundVelocity, getRefCount, getShape, getUp, isSlopeTooSteep, isSupported, saveStateMethods inherited from interface com.github.stephengold.joltjni.readonly.ConstJoltPhysicsObject
close, hasAssignedNativeObject, ownsNativeObject, targetVa
-
Constructor Details
-
CharacterVirtual
public CharacterVirtual(ConstCharacterVirtualSettings settings, RVec3Arg location, QuatArg orientation, long userData, PhysicsSystem system) Instantiate a character with a new native object assigned.- Parameters:
settings- the settings to use (not null, unaffected)location- the desired initial location (in system coordinates, not null, unaffected)orientation- the desired initial orientation (in system coordinates, not null, unaffected)userData- the desired user-data valuesystem- where to add the body (not null)
-
CharacterVirtual
Instantiate a character with the specified native object assigned.For use in custom contact listeners.
- Parameters:
characterVa- the virtual address of the native object to assign (not zero)physicsSystem- where to add the body (not null)
-
-
Method Details
-
extendedUpdate
public void extendedUpdate(float deltaTime, Vec3Arg gravity, ExtendedUpdateSettings settings, BroadPhaseLayerFilter bpFilter, ObjectLayerFilter olFilter, BodyFilter bodyFilter, ShapeFilter shapeFilter, TempAllocator allocator) Apply a combination of Update, StickToFloor, and WalkStairs.- Parameters:
deltaTime- the time step to simulategravity- the gravity acceleration vector (in meters per second squared, not null, unaffected)settings- settings to use (not null, unaffected)bpFilter- to test whether the character collides with a broad-phase layer (not null, unaffected)olFilter- to test whether the character collides with an object layer (not null, unaffected)bodyFilter- to test whether the character collides with a body (not null, unaffected)shapeFilter- to test whether the character collides with a shape (not null, unaffected)allocator- for temporary allocations (not null)
-
getCharacterVsCharacterCollision
Access the char-vs-char collision interface.- Returns:
- the pre-existing object, or
nullif none
-
getListener
Access the (application-provided) contact listener.- Returns:
- the pre-existing instance, or
nullif none
-
setCharacterVsCharacterCollision
Replace the char-vs-char collision interface.- Parameters:
cvcInterface- the desired interface (not null)
-
setEnhancedInternalEdgeRemoval
public void setEnhancedInternalEdgeRemoval(boolean enable) Enable or disable enhanced internal edge removal.- Parameters:
enable-trueto enable,falseto disable (default=false)
-
setHitReductionCosMaxAngle
public void setHitReductionCosMaxAngle(float cosine) Alter the maximum angle for merging during hit reduction.- Parameters:
cosine- the cosine of the desired maximum angle, or -1 to disable hit reduction (default=1)
-
setInnerBodyShape
Alter the shape of the inner body. Invoke this after a successful invocation ofsetShape().- Parameters:
shape- the desired shape (not null, unaffected, default=?)
-
setLinearVelocity
public void setLinearVelocity(float vx, float vy, float vz) Alter the character's linear velocity.- Parameters:
vx- the X component of the desired velocity (in meters per second, default=0)vy- the Y component of the desired velocity (in meters per second, default=0)vz- the Z component of the desired velocity (in meters per second, default=0)
-
setLinearVelocity
Alter the character's linear velocity.- Parameters:
velocity- the desired velocity vector (meters per second in system coordinates, default=(0,0,0))
-
setListener
Replace the contact listener.- Parameters:
listener- the desired listener
-
setMass
public void setMass(float mass) Alter the character's mass.- Parameters:
mass- the desired mass (in kilograms, default=70)
-
setMaxNumHits
public void setMaxNumHits(int maxHits) Alter the maximum number of hits to be collected.- Parameters:
maxHits- the desired limit (≥0, default=256)
-
setMaxStrength
public void setMaxStrength(float force) Alter the maximum force applied to bodies.- Parameters:
force- the desired force limit (in Newtons, default=100)
-
setPenetrationRecoverySpeed
public void setPenetrationRecoverySpeed(float fraction) Alter how quickly penetration is resolved.- Parameters:
fraction- the desired resolution fraction (0→never resolved, 1→all in one update, default=1)
-
setPosition
Relocate the character.- Parameters:
location- the desired location (in system coordinates, default=(0,0,0))
-
setRotation
Re-orient the character.- Parameters:
orientation- the desired orientation (in system coordinates, default=(0,0,0,1))
-
setShape
public boolean setShape(ConstShape shape, float maxPenetrationDepth, BroadPhaseLayerFilter broadPhaseLayerFilter, ObjectLayerFilter objectLayerFilter, BodyFilter bodyFilter, ShapeFilter shapeFilter, TempAllocator allocator) Alter the character's shape.- Parameters:
shape- the desired shape (not null)maxPenetrationDepth- the maximum acceptable penetration after the alteration, orFloat.MAX_VALUEto skip the checkbroadPhaseLayerFilter- the broadphase filter used to test for collisions (not null)objectLayerFilter- the object-layer filter used to test for collisions (not null)bodyFilter- the body filter used to test for collisions (not null)shapeFilter- the shape filter used to test for collisions (not null)allocator- the desired allocator (not null)- Returns:
trueif successful, otherwisefalse
-
setShapeOffset
Alter the shape offset.- Parameters:
offset- the desired offset (in local coordinates, default=(0,0,0))
-
setUserData
public void setUserData(long userData) Alter the user data.- Parameters:
userData- the desired value
-
updateGroundVelocity
public void updateGroundVelocity()Update the estimated ground velocity. -
toRef
Create a counted reference to the nativeCharacterVirtual. -
cancelVelocityTowardsSteepSlopes
Convert the specified velocity to one that won't climb steep slopes. The character is unaffected.- Specified by:
cancelVelocityTowardsSteepSlopesin interfaceConstCharacterVirtual- Parameters:
desiredVelocity- velocity vector (in system coordinates, not null, unaffected)- Returns:
- a new velocity vector (in system coordinates)
-
canWalkStairs
Test whether the character has moved onto a steep slope. The character is unaffected.- Specified by:
canWalkStairsin interfaceConstCharacterVirtual- Parameters:
desiredVelocity- velocity vector (in system coordinates, not null, unaffected)- Returns:
trueif too step to walk, otherwisefalse
-
getActiveContacts
Copy the list of active contacts. The character is unaffected.- Specified by:
getActiveContactsin interfaceConstCharacterVirtual- Returns:
- a new array of new objects
-
getCenterOfMassPosition
Calculate the location of the character's center of mass. The character is unaffected.- Specified by:
getCenterOfMassPositionin interfaceConstCharacterVirtual- Returns:
- a new location vector (in system coordinates)
-
getCenterOfMassTransform
Calculate the local-to-system transform of the character's center of mass. The character is unaffected.- Specified by:
getCenterOfMassTransformin interfaceConstCharacterVirtual- Returns:
- a new coordinate transform matrix
-
getCharacterPadding
public float getCharacterPadding()Return the thickness of the character's padding. The character is unaffected.- Specified by:
getCharacterPaddingin interfaceConstCharacterVirtual- Returns:
- the thickness (in meters)
-
getCharacterVirtualSettings
Generate settings to reconstruct the character. The character is unaffected.- Specified by:
getCharacterVirtualSettingsin interfaceConstCharacterVirtual- Returns:
- a new object
-
getEnhancedInternalEdgeRemoval
public boolean getEnhancedInternalEdgeRemoval()Test whether enhanced internal edge removal is enabled. The character is unaffected.- Specified by:
getEnhancedInternalEdgeRemovalin interfaceConstCharacterVirtual- Returns:
trueif enabled, otherwisefalse
-
getHitReductionCosMaxAngle
public float getHitReductionCosMaxAngle()Return the maximum angle for merging during hit reduction. The character is unaffected.- Specified by:
getHitReductionCosMaxAnglein interfaceConstCharacterVirtual- Returns:
- the cosine of the maximum angle, or -1 if hit reduction is disabled
-
getId
public int getId()Return the character's ID. The character is unaffected. (native method: GetID)- Specified by:
getIdin interfaceConstCharacterVirtual- Returns:
- a
CharacterIdvalue
-
getInnerBodyId
public int getInnerBodyId()Return the ID of the inner body. The character is unaffected. (native method: GetInnerBodyID)- Specified by:
getInnerBodyIdin interfaceConstCharacterVirtual- Returns:
- the
BodyIDvalue
-
getLinearVelocity
Copy the linear velocity of the character. The character is unaffected.- Specified by:
getLinearVelocityin interfaceConstCharacterVirtual- Returns:
- a new velocity vector (meters per second in system coordinates)
-
getMass
public float getMass()Return the character's mass. The character is unaffected.- Specified by:
getMassin interfaceConstCharacterVirtual- Returns:
- the mass (in kilograms)
-
getMaxHitsExceeded
public boolean getMaxHitsExceeded()Test whether the last collision check discarded one or more hits. The character is unaffected.- Specified by:
getMaxHitsExceededin interfaceConstCharacterVirtual- Returns:
trueif discarded hits, otherwisefalse
-
getMaxNumHits
public int getMaxNumHits()Return the maximum number of hits to be collected. The character is unaffected.- Specified by:
getMaxNumHitsin interfaceConstCharacterVirtual- Returns:
- the limit (≥0)
-
getMaxStrength
public float getMaxStrength()Return the maximum force applied to other bodies. The character is unaffected.- Specified by:
getMaxStrengthin interfaceConstCharacterVirtual- Returns:
- the force (in Newtons)
-
getPenetrationRecoverySpeed
public float getPenetrationRecoverySpeed()Return how quickly penetration is resolved. The character is unaffected.- Specified by:
getPenetrationRecoverySpeedin interfaceConstCharacterVirtual- Returns:
- the resolution fraction (0=never resolved, 1=all in one update)
-
getPosition
Copy the location of the character. The character is unaffected.- Specified by:
getPositionin interfaceConstCharacterVirtual- Returns:
- a new location vector (in system coordinates)
-
getPositionAndRotation
Copy the position of the character. The character is unaffected.- Specified by:
getPositionAndRotationin interfaceConstCharacterVirtual- Parameters:
storeLocation- storage for the location (in system coordinates, not null, modified)storeOrientation- storage for the orientation (in system coordinates, not null, modified)
-
getRotation
Copy the orientation of the character. The character is unaffected.- Specified by:
getRotationin interfaceConstCharacterVirtual- Returns:
- a new rotation quaternion (in system coordinates)
-
getShapeOffset
Copy the local offset applied to the shape. The character is unaffected.- Specified by:
getShapeOffsetin interfaceConstCharacterVirtual- Returns:
- a new offset vector (in local coordinates)
-
getTransformedShape
Generate a TransformedShape that represents the volume occupied by the character. The character is unaffected.- Specified by:
getTransformedShapein interfaceConstCharacterVirtual- Returns:
- a new object
-
getUserData
public long getUserData()Return the character's user data: can be used for anything. The character is unaffected.- Specified by:
getUserDatain interfaceConstCharacterVirtual- Returns:
- the value
-
getWorldTransform
Calculate the character's local-to-system coordinate transform. The character is unaffected.- Specified by:
getWorldTransformin interfaceConstCharacterVirtual- Returns:
- a new transform matrix
-
hasCollidedWith
public boolean hasCollidedWith(int bodyId) Test whether the character is in contact with or collided with the specified body during the previous time step. The character is unaffected.- Specified by:
hasCollidedWithin interfaceConstCharacterVirtual- Parameters:
bodyId- the ID of the body to test against- Returns:
trueif contact or collision, otherwisefalse
-
hasCollidedWith
Test whether the character is in contact with or has collided with the specified character during the previous time step. The current character is unaffected.- Specified by:
hasCollidedWithin interfaceConstCharacterVirtual- Parameters:
otherCharacter- the character to test against (not null, unaffected)- Returns:
trueif contact or collision, otherwisefalse
-
toRefC
Create a counted reference to the nativeCharacterVirtual.- Specified by:
toRefCin interfaceConstCharacterVirtual- Returns:
- a new JVM object with a new native object assigned
-