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 but not owned.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.boolean
canWalkStairs
(Vec3Arg desiredVelocity) Test whether the character has moved onto a steep slope.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.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.float
Return the thickness of the character's padding.Access the char-vs-char collision interface.boolean
Test whether enhanced internal edge removal is enabled.float
Return the maximum angle for merging during hit reduction.int
getId()
Return the character's ID.int
Return the ID of the inner body.Copy the linear velocity of the character.Access the (application-provided) contact listener.float
getMass()
Return the character's mass.boolean
Test whether the last collision check discarded one or more hits.int
Return the maximum number of hits to be collected.float
Return the maximum force applied to other bodies.float
Return how quickly penetration is resolved.Copy the location of the character.void
getPositionAndRotation
(RVec3 storeLocation, Quat storeOrientation) Copy the position of the character.Copy the orientation of the character.Copy the local offset applied to the shape.Return a TransformedShape that represents the volume occupied by the character.long
Return the character's user data: can be used for anything.Calculate the character's local-to-system coordinate transform.boolean
hasCollidedWith
(int bodyId) Test whether the character is in contact with or collided with the specified body during the previous time step.boolean
hasCollidedWith
(ConstCharacterVirtual otherCharacter) Test whether the character is in contact with or has collided with the specified character during the previous time step.void
Replace the char-vs-char collision interface.void
setEnhancedInternalEdgeRemoval
(boolean enable) Enable or disable enhanced internal edge removal.void
setHitReductionCosMaxAngle
(float cosine) Alter the maximum angle for merging during hit reduction.void
setInnerBodyShape
(ConstShape shape) Alter the shape of the inner body.void
setLinearVelocity
(Vec3Arg velocity) Alter the character's linear velocity.void
setListener
(CharacterContactListener listener) Replace the contact listener.void
setMass
(float mass) Alter the character's mass.void
setMaxNumHits
(int maxHits) Alter the maximum number of hits to be collected.void
setMaxStrength
(float force) Alter the maximum force applied to bodies.void
setPenetrationRecoverySpeed
(float fraction) Alter how quickly penetration is resolved.void
setPosition
(RVec3Arg location) Relocate the character.void
setRotation
(QuatArg orientation) Re-orient the character.boolean
setShape
(ConstShape shape, float maxPenetrationDepth, BroadPhaseLayerFilter broadPhaseLayerFilter, ObjectLayerFilter objectLayerFilter, BodyFilter bodyFilter, ShapeFilter shapeFilter, TempAllocator allocator) Alter the character's shape.void
setShapeOffset
(Vec3Arg offset) Alter the shape offset.void
setUserData
(long userData) Alter the user data.toRef()
Create a counted reference to the nativeCharacterVirtual
.toRefC()
Create a counted reference to the nativeCharacterVirtual
.void
Update 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, setUp
Methods inherited from class com.github.stephengold.joltjni.JoltPhysicsObject
close, compareTo, equals, getContainingObject, hasAssignedNativeObject, hashCode, ownsNativeObject, setVirtualAddress, setVirtualAddress, startCleaner, targetVa, toString, va
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface com.github.stephengold.joltjni.readonly.ConstCharacterBase
getCosMaxSlopeAngle, getGroundBodyId, getGroundMaterial, getGroundNormal, getGroundPosition, getGroundState, getGroundSubShapeId, getGroundUserData, getGroundVelocity, getShape, getUp, isSlopeTooSteep, isSupported, saveState
Methods inherited from interface com.github.stephengold.joltjni.readonly.ConstJoltPhysicsObject
close, hasAssignedNativeObject, ownsNativeObject, targetVa
-
Constructor Details
-
CharacterVirtual
Instantiate a character with the specified native object assigned but not owned.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)
-
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)
-
-
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
null
if none
-
getListener
Access the (application-provided) contact listener.- Returns:
- the pre-existing instance, or
null
if 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
-true
to enable,false
to 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
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_VALUE
to 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:
true
if 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:
cancelVelocityTowardsSteepSlopes
in 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:
canWalkStairs
in interfaceConstCharacterVirtual
- Parameters:
desiredVelocity
- velocity vector (in system coordinates, not null, unaffected)- Returns:
true
if too step to walk, otherwisefalse
-
getActiveContacts
Copy the list of active contacts. The character is unaffected.- Specified by:
getActiveContacts
in 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:
getCenterOfMassPosition
in 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:
getCenterOfMassTransform
in 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:
getCharacterPadding
in interfaceConstCharacterVirtual
- Returns:
- the thickness (in meters)
-
getEnhancedInternalEdgeRemoval
public boolean getEnhancedInternalEdgeRemoval()Test whether enhanced internal edge removal is enabled. The character is unaffected.- Specified by:
getEnhancedInternalEdgeRemoval
in interfaceConstCharacterVirtual
- Returns:
true
if enabled, otherwisefalse
-
getHitReductionCosMaxAngle
public float getHitReductionCosMaxAngle()Return the maximum angle for merging during hit reduction. The character is unaffected.- Specified by:
getHitReductionCosMaxAngle
in 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:
getId
in interfaceConstCharacterVirtual
- Returns:
- a
CharacterId
value
-
getInnerBodyId
public int getInnerBodyId()Return the ID of the inner body. The character is unaffected. (native method: GetInnerBodyID)- Specified by:
getInnerBodyId
in interfaceConstCharacterVirtual
- Returns:
- the
BodyID
value
-
getLinearVelocity
Copy the linear velocity of the character. The character is unaffected.- Specified by:
getLinearVelocity
in 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:
getMass
in 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:
getMaxHitsExceeded
in interfaceConstCharacterVirtual
- Returns:
true
if discarded hits, otherwisefalse
-
getMaxNumHits
public int getMaxNumHits()Return the maximum number of hits to be collected. The character is unaffected.- Specified by:
getMaxNumHits
in interfaceConstCharacterVirtual
- Returns:
- the limit (≥0)
-
getMaxStrength
public float getMaxStrength()Return the maximum force applied to other bodies. The character is unaffected.- Specified by:
getMaxStrength
in interfaceConstCharacterVirtual
- Returns:
- the force (in Newtons)
-
getPenetrationRecoverySpeed
public float getPenetrationRecoverySpeed()Return how quickly penetration is resolved. The character is unaffected.- Specified by:
getPenetrationRecoverySpeed
in 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:
getPosition
in interfaceConstCharacterVirtual
- Returns:
- a new location vector (in system coordinates)
-
getPositionAndRotation
Copy the position of the character. The character is unaffected.- Specified by:
getPositionAndRotation
in 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:
getRotation
in interfaceConstCharacterVirtual
- Returns:
- a new rotation quaternion (in system coordinates)
-
getShapeOffset
Copy the local offset applied to the shape. The character is unaffected.- Specified by:
getShapeOffset
in interfaceConstCharacterVirtual
- Returns:
- a new offset vector (in local coordinates)
-
getTransformedShape
Return a TransformedShape that represents the volume occupied by the character. The character is unaffected.- Specified by:
getTransformedShape
in 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:
getUserData
in interfaceConstCharacterVirtual
- Returns:
- the value
-
getWorldTransform
Calculate the character's local-to-system coordinate transform. The character is unaffected.- Specified by:
getWorldTransform
in 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:
hasCollidedWith
in interfaceConstCharacterVirtual
- Parameters:
bodyId
- the ID of the body to test against- Returns:
true
if 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:
hasCollidedWith
in interfaceConstCharacterVirtual
- Parameters:
otherCharacter
- the character to test against (not null, unaffected)- Returns:
true
if contact or collision, otherwisefalse
-
toRefC
Create a counted reference to the nativeCharacterVirtual
.- Specified by:
toRefC
in interfaceConstCharacterVirtual
- Returns:
- a new JVM object with a new native object assigned
-