SuperTuxKart
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
PhysicalObject Class Reference
Inheritance diagram for PhysicalObject:
Inheritance graph
[legend]

Classes

class  Settings
 

Public Types

enum  BodyTypes {
  MP_NONE, MP_CONE_Y, MP_CONE_X, MP_CONE_Z,
  MP_CYLINDER_Y, MP_CYLINDER_X, MP_CYLINDER_Z, MP_BOX,
  MP_SPHERE, MP_EXACT
}
 The supported collision shapes. More...
 

Public Member Functions

 PhysicalObject (bool is_dynamic, const Settings &settings, TrackObject *object)
 
virtual void reset ()
 Nothing to do here. More...
 
virtual void handleExplosion (const Vec3 &pos, bool directHit)
 
void update (float dt)
 Update, called once per physics time step. More...
 
void updateGraphics (float dt)
 This updates all only graphical elements. More...
 
void init (const Settings &settings)
 Additional initialisation after loading of the model is finished.
 
void move (const Vec3 &xyz, const core::vector3df &hpr)
 
void hit (const Material *m, const Vec3 &normal)
 Called when a physical object hits the track. More...
 
bool isSoccerBall () const
 Returns true if this object is a soccer ball.
 
bool castRay (const btVector3 &from, const btVector3 &to, btVector3 *hit_point, const Material **material, btVector3 *normal, bool interpolate_normal) const
 Does a raycast against this physical object. More...
 
bool isDynamic () const
 
std::string getID ()
 Returns the ID of this physical object. More...
 
btDefaultMotionState * getMotionState () const
 
btRigidBody * getBody () const
 Returns the rigid body of this physical object. More...
 
bool isCrashReset () const
 Returns true if this object should trigger a rescue in a kart that hits it. More...
 
bool isExplodeKartObject () const
 Returns true if this object should cause an explosion if a kart hits it. More...
 
void setInteraction (std::string interaction)
 Sets the interaction type. More...
 
void removeBody ()
 Remove body from dynamic world. More...
 
void addBody ()
 Add body to dynamic world. More...
 
float getRadius () const
 
const std::string & getOnKartCollisionFunction () const
 
const std::string & getOnItemCollisionFunction () const
 
TrackObjectgetTrackObject ()
 
bool isFlattenKartObject () const
 Returns true if this object should cause a kart that touches it to be flattened. More...
 
void disable ()
 
void enable ()
 
void addForRewind ()
 
virtual void saveTransform ()
 Called before a rewind. More...
 
virtual void computeError ()
 Called when a rewind is finished, and is used to compute the error caused by the rewind (which is then visually smoothed over time). More...
 
virtual BareNetworkStringsaveState (std::vector< std::string > *ru)
 Provides a copy of the state of the object in one memory buffer. More...
 
virtual void undoEvent (BareNetworkString *buffer)
 Called when an event needs to be undone. More...
 
virtual void rewindToEvent (BareNetworkString *buffer)
 Called when an event needs to be replayed. More...
 
virtual void restoreState (BareNetworkString *buffer, int count)
 Called when a state needs to be replayed. More...
 
virtual void undoState (BareNetworkString *buffer)
 Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo). More...
 
virtual std::function< void()> getLocalStateRestoreFunction ()
 
bool hasTriangleMesh () const
 
void joinToMainTrack ()
 
- Public Member Functions inherited from Rewinder
 Rewinder (const std::string &ui="")
 
const std::string & getUniqueIdentity () const
 
bool rewinderAdd ()
 Add this object to the list of all rewindable objects in the rewind manager.
 
template<typename T >
std::shared_ptr< T > getShared ()
 
- Public Member Functions inherited from SmoothNetworkBody
 SmoothNetworkBody (bool enable=false)
 
void reset ()
 
void setEnable (bool val)
 
bool isEnabled () const
 
void setSmoothRotation (bool val)
 
void setAdjustVerticalOffset (bool val)
 
void prepareSmoothing (const btTransform &current_transform, const Vec3 &current_velocity)
 
void checkSmoothing (const btTransform &current_transform, const Vec3 &current_velocity)
 Adds a new error between graphical and physical position/rotation. More...
 
void updateSmoothedGraphics (const btTransform &current_transform, const Vec3 &current_velocity, float dt)
 
void setSmoothedTransform (const btTransform &t)
 
const btTransform & getSmoothedTrans () const
 
const Vec3getSmoothedXYZ () const
 
void setMinAdjustLength (float val)
 
void setMaxAdjustLength (float val)
 
void setMinAdjustSpeed (float val)
 
void setMaxAdjustTime (float val)
 
void setAdjustLengthThreshold (float val)
 

Static Public Member Functions

static std::shared_ptr< PhysicalObjectfromXML (bool is_dynamic, const XMLNode &node, TrackObject *object)
 

Private Attributes

core::vector3df m_init_xyz
 The initial XYZ position of the object. More...
 
core::vector3df m_init_hpr
 The initial hpr of the object. More...
 
core::vector3df m_init_scale
 The initial scale of the object. More...
 
TrackObjectm_object
 
BodyTypes m_body_type
 The shape of this object. More...
 
btCollisionShape * m_shape
 The bullet collision shape. More...
 
std::string m_id
 ID of the object. More...
 
btRigidBody * m_body
 The corresponding bullet rigid body. More...
 
btDefaultMotionState * m_motion_state
 Bullet's motion state for this object. More...
 
float m_mass
 The mass of this object. More...
 
bool m_body_added
 
UserPointer m_user_pointer
 The pointer that is stored in the bullet rigid body back to this object. More...
 
btTransform m_init_pos
 This is the initial position of the object for the physics. More...
 
btTransform m_current_transform
 Save current transform to avoid frequent lookup from world transform. More...
 
Vec3 m_graphical_offset
 The mesh might not have the same center as bullet does. More...
 
float m_radius
 Radius of the object - this obviously depends on the actual shape. More...
 
bool m_crash_reset
 True if a kart colliding with this object should be rescued. More...
 
bool m_explode_kart
 True if kart should "explode" when touching this.
 
bool m_flatten_kart
 
bool m_reset_when_too_low
 True if object should be reset to its initial position if it's too low (see m_reset_height). More...
 
float m_reset_height
 If m_reset_when_too_low this object is set back to its start position if its height is below this value. More...
 
std::string m_on_kart_collision
 If non-empty, the name of the scripting function to call when a kart collides with this object.
 
std::string m_on_item_collision
 If non-empty, the name of the scripting function to call when a (flyable) item collides with this object.
 
bool m_is_dynamic
 If this body is a bullet dynamic body, i.e. More...
 
TriangleMeshm_triangle_mesh
 Non-null only if the shape is exact.
 
btTransform m_last_transform
 
Vec3 m_last_lv
 
Vec3 m_last_av
 
bool m_no_server_state
 

Additional Inherited Members

- Protected Member Functions inherited from Rewinder
void setUniqueIdentity (const std::string &uid)
 

Member Enumeration Documentation

◆ BodyTypes

The supported collision shapes.

Member Function Documentation

◆ addBody()

void PhysicalObject::addBody ( )

Add body to dynamic world.

Add body to physics dynamic world.

◆ castRay()

bool PhysicalObject::castRay ( const btVector3 &  from,
const btVector3 &  to,
btVector3 *  hit_point,
const Material **  material,
btVector3 *  normal,
bool  interpolate_normal 
) const

Does a raycast against this physical object.

The physical object must have an 'exact' shape, i.e. be a triangle mesh (for other physical objects no material information would be available).

Parameters
from/toThe from and to position for the raycast.
xyzThe position in world where the ray hit.
materialThe material of the mesh that was hit.
normalThe intrapolated normal at that position.
interpolate_normalIf true, the returned normal is the interpolated based on the three normals of the triangle and the location of the hit point (which is more compute intensive, but results in much smoother results).
Returns
True if a triangle was hit, false otherwise (and no output variable will be set.

◆ computeError()

void PhysicalObject::computeError ( )
virtual

Called when a rewind is finished, and is used to compute the error caused by the rewind (which is then visually smoothed over time).

Implements Rewinder.

◆ getBody()

btRigidBody* PhysicalObject::getBody ( ) const
inline

Returns the rigid body of this physical object.

◆ getID()

std::string PhysicalObject::getID ( )
inline

Returns the ID of this physical object.

◆ hit()

void PhysicalObject::hit ( const Material m,
const Vec3 normal 
)

Called when a physical object hits the track.

Atm only used to push a soccer ball away from the edge of the field.

Parameters
mMaterial which was hit.
normalNormal of the track at the hit point.

◆ isCrashReset()

bool PhysicalObject::isCrashReset ( ) const
inline

Returns true if this object should trigger a rescue in a kart that hits it.

◆ isExplodeKartObject()

bool PhysicalObject::isExplodeKartObject ( ) const
inline

Returns true if this object should cause an explosion if a kart hits it.

◆ removeBody()

void PhysicalObject::removeBody ( )

Remove body from dynamic world.

Remove body from physics dynamic world interaction type for object.

◆ reset()

void PhysicalObject::reset ( )
virtual

Nothing to do here.

Reimplemented from Rewinder.

◆ restoreState()

void PhysicalObject::restoreState ( BareNetworkString buffer,
int  count 
)
virtual

Called when a state needs to be replayed.

This is called during rewind, i.e. when going forward in time again, and only for confirmed states.

Implements Rewinder.

◆ rewindToEvent()

virtual void PhysicalObject::rewindToEvent ( BareNetworkString buffer)
inlinevirtual

Called when an event needs to be replayed.

This is called during rewind, i.e. when going forward in time again.

Implements Rewinder.

◆ saveState()

BareNetworkString * PhysicalObject::saveState ( std::vector< std::string > *  ru)
virtual

Provides a copy of the state of the object in one memory buffer.

The memory is managed by the RewindManager.

Parameters
[out]ruThe unique identity of rewinder writing to.
Returns
The address of the memory buffer with the state.

Implements Rewinder.

◆ saveTransform()

void PhysicalObject::saveTransform ( )
virtual

Called before a rewind.

Is used to save the previous position of an object before a rewind, so that the error due to a rewind can be computed.

Implements Rewinder.

◆ setInteraction()

void PhysicalObject::setInteraction ( std::string  interaction)

Sets the interaction type.

Sets interaction type for object.

◆ undoEvent()

virtual void PhysicalObject::undoEvent ( BareNetworkString buffer)
inlinevirtual

Called when an event needs to be undone.

This is called while going backwards for rewinding - all stored events will get an 'undo' call.

Implements Rewinder.

◆ undoState()

virtual void PhysicalObject::undoState ( BareNetworkString buffer)
inlinevirtual

Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo).

This is called while going backwards for rewinding - all stored events will get an 'undo' call.

Implements Rewinder.

◆ update()

void PhysicalObject::update ( float  dt)

Update, called once per physics time step.

Parameters
dtTimestep.

◆ updateGraphics()

void PhysicalObject::updateGraphics ( float  dt)

This updates all only graphical elements.

It is only called once per rendered frame, not once per time step. float dt Time since last rame.

Member Data Documentation

◆ m_body

btRigidBody* PhysicalObject::m_body
private

The corresponding bullet rigid body.

◆ m_body_type

BodyTypes PhysicalObject::m_body_type
private

The shape of this object.

◆ m_crash_reset

bool PhysicalObject::m_crash_reset
private

True if a kart colliding with this object should be rescued.

◆ m_current_transform

btTransform PhysicalObject::m_current_transform
private

Save current transform to avoid frequent lookup from world transform.

◆ m_graphical_offset

Vec3 PhysicalObject::m_graphical_offset
private

The mesh might not have the same center as bullet does.

This offset is used to offset the location of the graphical mesh so that the graphics are aligned with the bullet collision shape.

◆ m_id

std::string PhysicalObject::m_id
private

ID of the object.

◆ m_init_hpr

core::vector3df PhysicalObject::m_init_hpr
private

The initial hpr of the object.

◆ m_init_pos

btTransform PhysicalObject::m_init_pos
private

This is the initial position of the object for the physics.

◆ m_init_scale

core::vector3df PhysicalObject::m_init_scale
private

The initial scale of the object.

◆ m_init_xyz

core::vector3df PhysicalObject::m_init_xyz
private

The initial XYZ position of the object.

◆ m_is_dynamic

bool PhysicalObject::m_is_dynamic
private

If this body is a bullet dynamic body, i.e.

affected by physics or not (static (not moving) or kinematic (animated outside of physics).

◆ m_mass

float PhysicalObject::m_mass
private

The mass of this object.

◆ m_motion_state

btDefaultMotionState* PhysicalObject::m_motion_state
private

Bullet's motion state for this object.

◆ m_radius

float PhysicalObject::m_radius
private

Radius of the object - this obviously depends on the actual shape.

As a default the radius is being determined from the shape of the mesh, but in somce cases that could lead to incorrect results (if the mesh does not closely resemble a sphere, see init() for details, but is supposed to be a sphere). In this case the radius can be set in the scene file.

◆ m_reset_height

float PhysicalObject::m_reset_height
private

If m_reset_when_too_low this object is set back to its start position if its height is below this value.

◆ m_reset_when_too_low

bool PhysicalObject::m_reset_when_too_low
private

True if object should be reset to its initial position if it's too low (see m_reset_height).

◆ m_shape

btCollisionShape* PhysicalObject::m_shape
private

The bullet collision shape.

◆ m_user_pointer

UserPointer PhysicalObject::m_user_pointer
private

The pointer that is stored in the bullet rigid body back to this object.


The documentation for this class was generated from the following files: