SuperTuxKart
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private 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.
 

Public Member Functions

 PhysicalObject (bool is_dynamic, const Settings &settings, TrackObject *object)
 
virtual void reset ()
 Nothing to do here.
 
virtual void handleExplosion (const Vec3 &pos, bool directHit)
 
void update (float dt)
 Update, called once per physics time step.
 
void updateGraphics (float dt)
 This updates all only graphical elements.
 
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.
 
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.
 
bool isDynamic () const
 
std::string getID ()
 Returns the ID of this physical object.
 
btDefaultMotionState * getMotionState () const
 
btRigidBody * getBody () const
 Returns the rigid body of this physical object.
 
bool isCrashReset () const
 Returns true if this object should trigger a rescue in a kart that hits it.
 
bool isExplodeKartObject () const
 Returns true if this object should cause an explosion if a kart hits it.
 
void setInteraction (std::string interaction)
 Sets the interaction type.
 
void removeBody ()
 Remove body from dynamic world.
 
void addBody ()
 Add body to dynamic world.
 
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.
 
void disable ()
 
void enable ()
 
void addForRewind ()
 
virtual void saveTransform ()
 Called before a rewind.
 
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).
 
virtual BareNetworkStringsaveState (std::vector< std::string > *ru)
 Provides a copy of the state of the object in one memory buffer.
 
virtual void undoEvent (BareNetworkString *buffer)
 Called when an event needs to be undone.
 
virtual void rewindToEvent (BareNetworkString *buffer)
 Called when an event needs to be replayed.
 
virtual void restoreState (BareNetworkString *buffer, int count)
 Called when a state needs to be replayed.
 
virtual void undoState (BareNetworkString *buffer)
 Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo).
 
virtual std::function< void()> getLocalStateRestoreFunction ()
 
bool hasTriangleMesh () const
 
void joinToMainTrack ()
 
std::shared_ptr< PhysicalObjectclone (TrackObject *track_obj)
 
- Public Member Functions inherited from Rewinder
 Rewinder (const std::string &ui="")
 
virtual void saveTransform ()=0
 Called before a rewind.
 
virtual void computeError ()=0
 Called when a rewind is finished, and is used to compute the error caused by the rewind (which is then visually smoothed over time).
 
virtual BareNetworkStringsaveState (std::vector< std::string > *ru)=0
 Provides a copy of the state of the object in one memory buffer.
 
virtual void undoEvent (BareNetworkString *buffer)=0
 Called when an event needs to be undone.
 
virtual void rewindToEvent (BareNetworkString *buffer)=0
 Called when an event needs to be replayed.
 
virtual void restoreState (BareNetworkString *buffer, int count)=0
 Called when a state needs to be replayed.
 
virtual void undoState (BareNetworkString *buffer)=0
 Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo).
 
virtual void reset ()
 Nothing to do here.
 
virtual std::function< void()> getLocalStateRestoreFunction ()
 
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.
 
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 Member Functions

void copyFromMainProcess (TrackObject *track_obj)
 

Private Attributes

core::vector3df m_init_xyz
 The initial XYZ position of the object.
 
core::vector3df m_init_hpr
 The initial hpr of the object.
 
core::vector3df m_init_scale
 The initial scale of the object.
 
TrackObjectm_object
 
BodyTypes m_body_type
 The shape of this object.
 
btCollisionShape * m_shape
 The bullet collision shape.
 
std::string m_id
 ID of the object.
 
btRigidBody * m_body
 The corresponding bullet rigid body.
 
btDefaultMotionState * m_motion_state
 Bullet's motion state for this object.
 
float m_mass
 The mass of this object.
 
bool m_body_added
 
UserPointer m_user_pointer
 The pointer that is stored in the bullet rigid body back to this object.
 
btTransform m_init_pos
 This is the initial position of the object for the physics.
 
btTransform m_current_transform
 Save current transform to avoid frequent lookup from world transform.
 
Vec3 m_graphical_offset
 The mesh might not have the same center as bullet does.
 
float m_radius
 Radius of the object - this obviously depends on the actual shape.
 
bool m_crash_reset
 True if a kart colliding with this object should be rescued.
 
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).
 
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.
 
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.
 
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 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.

◆ getLocalStateRestoreFunction()

std::function< void()> PhysicalObject::getLocalStateRestoreFunction ( )
virtual

Reimplemented from Rewinder.

◆ 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.

◆ 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_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_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_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.


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