SuperTuxKart
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
KartModel Class Reference

This class stores a 3D kart model. More...

#include <kart_model.hpp>

Inheritance diagram for KartModel:
Inheritance graph
[legend]

Public Types

enum  AnimationFrameType {
  AF_BEGIN , AF_DEFAULT = AF_BEGIN , AF_LEFT , AF_STRAIGHT ,
  AF_RIGHT , AF_LOSE_START , AF_LOSE_LOOP_START , AF_LOSE_END ,
  AF_LOSE_END_STRAIGHT , AF_BEGIN_EXPLOSION , AF_END_EXPLOSION , AF_JUMP_START ,
  AF_JUMP_LOOP , AF_JUMP_END , AF_WIN_START , AF_WIN_LOOP_START ,
  AF_WIN_END , AF_WIN_END_STRAIGHT , AF_SELECTION_START , AF_SELECTION_END ,
  AF_BACK_LEFT , AF_BACK_STRAIGHT , AF_BACK_RIGHT , AF_END =AF_BACK_RIGHT ,
  AF_COUNT
}
 

Public Member Functions

 KartModel (bool is_master)
 Default constructor which initialises all variables with defaults.
 
 ~KartModel ()
 Destructor.
 
KartModelmakeCopy (std::shared_ptr< GE::GERenderInfo > ri)
 This function returns a copy of this object.
 
void reset ()
 Resets the kart model.
 
void loadInfo (const XMLNode &node)
 This function loads the information about the kart from a xml file.
 
bool loadModels (const KartProperties &kart_properties)
 Loads the 3d model and all wheels.
 
void setDefaultSuspension ()
 
void update (float dt, float distance, float steer, float speed, float current_lean_angle, int gt_replay_index=-1)
 Rotates and turns the wheels appropriately, and adjust for suspension updates the speed-weighted objects' animations.
 
void finishedRace ()
 Called when the kart finished the race.
 
void resetVisualWheelPosition ()
 Called when a kart is rescued to reset all visual wheels to their default position to avoid that some wheels look too far away from the kart (which is not that visible while a kart is driving).
 
scene::ISceneNode * attachModel (bool animatedModels, bool human_player)
 Attach the kart model and wheels to the scene node.
 
scene::IAnimatedMesh * getModel () const
 Returns the animated mesh of this kart model.
 
scene::IMesh * getWheelModel (const int i) const
 Returns the mesh of the wheel for this kart.
 
int getBaseFrame () const
 Since karts might be animated, we might need to know which base frame to use.
 
int getFrame (AnimationFrameType f) const
 
float getAnimationSpeed () const
 
const Vec3getWheelGraphicsPosition (unsigned int i) const
 Returns the position of a wheel relative to the kart.
 
const Vec3getWheelsGraphicsPosition () const
 Returns the position of wheels relative to the kart.
 
float getWheelGraphicsRadius (unsigned int i) const
 Returns the radius of the graphical wheels.
 
const Vec3getNitroEmittersPositon (unsigned int i) const
 Returns the position of nitro emitter relative to the kart.
 
const bool hasNitroEmitters () const
 Returns true if kart has nitro emitters.
 
size_t getSpeedWeightedObjectsCount () const
 Returns the number of speed weighted objects for this kart.
 
const SpeedWeightedObjectgetSpeedWeightedObject (int i) const
 Returns the position of a speed weighted object relative to the kart.
 
float getLength () const
 Returns the length of the kart model.
 
float getWidth () const
 Returns the width of the kart model.
 
float getHeight () const
 Returns the height of the kart.
 
float getHighestPoint () const
 Highest coordinate on up axis.
 
float getLowestPoint () const
 Lowest coordinate on up axis.
 
AnimationFrameType getAnimation ()
 Returns information about currently played animation.
 
void setAnimation (AnimationFrameType type, bool play_non_loop=false)
 Enables- or disables the end animation.
 
void setKart (AbstractKart *k)
 Sets the kart this model is currently used for.
 
void setHatMeshName (const std::string &name)
 Name of the hat mesh to use.
 
scene::ISceneNode ** getWheelNodes ()
 Returns the array of wheel nodes.
 
scene::IAnimatedMeshSceneNode * getAnimatedNode ()
 
std::shared_ptr< GE::GERenderInfo > getRenderInfo ()
 
bool supportColorization () const
 
void toggleHeadlights (bool on)
 
const core::matrix4 & getInverseBoneMatrix (const std::string &bone_name) const
 
const std::string & getExhaustXML () const
 
bool hasWheel () const
 
const KartPropertiesgetKartProperties () const
 

Private Member Functions

void loadWheelInfo (const XMLNode &node, const std::string &wheel_name, int index)
 Loads a single wheel node.
 
void loadNitroEmitterInfo (const XMLNode &node, const std::string &emitter_name, int index)
 Loads a single nitro emitter node.
 
void loadSpeedWeightedInfo (const XMLNode *speed_weighted_node)
 Loads a single speed weighted node.
 
void loadHeadlights (const XMLNode &node)
 
void OnAnimationEnd (scene::IAnimatedMeshSceneNode *node)
 Called from irrlicht when a non-looped animation ends.
 
void initInverseBoneMatrices ()
 Called when a kart is load.
 
void configNode (scene::ISceneNode *node, const core::matrix4 &global_mat, const core::matrix4 &inv_mat)
 

Private Attributes

int m_animation_frame [AF_COUNT]
 Which frame number starts/end which animation.
 
float m_animation_speed
 Animation speed.
 
scene::IAnimatedMesh * m_mesh
 The mesh of the model.
 
scene::IAnimatedMeshSceneNode * m_animated_node
 This is a pointer to the scene node of the kart this model belongs to.
 
core::matrix4 * m_hat_location
 Location of hat in object space.
 
std::string m_hat_bone
 Name of the bone for hat attachment.
 
std::string m_hat_name
 Name of the hat to use for this kart.
 
std::string m_model_filename
 Name of the 3d model file.
 
scene::IMesh * m_wheel_model [4]
 The four wheel models.
 
scene::ISceneNode * m_wheel_node [4]
 The four scene nodes the wheels are attached to.
 
std::string m_wheel_filename [4]
 Filename of the wheel models.
 
Vec3 m_wheel_graphics_position [4]
 The position of all four wheels in the 3d model.
 
float m_wheel_graphics_radius [4]
 Radius of the graphical wheels.
 
Vec3 m_nitro_emitter_position [2]
 The position of the nitro emitters.
 
bool m_has_nitro_emitter
 True if kart has nitro emitters.
 
SpeedWeightedObjectList m_speed_weighted_objects
 The speed weighted objects.
 
std::vector< HeadlightObjectm_headlight_objects
 
float m_default_physics_suspension [4]
 Length of the physics suspension when the kart is at rest.
 
float m_min_suspension [4]
 Minimum suspension length (i.e.
 
float m_max_suspension [4]
 Maximum suspension length (i.e.
 
float m_dampen_suspension_amplitude [4]
 value used to divide the visual movement of wheels (because the actual movement of wheels in bullet is too large and looks strange).
 
AnimationFrameType m_current_animation
 Which animation is currently being played.
 
float m_kart_width
 Width of kart.
 
float m_kart_length
 Length of kart.
 
float m_kart_height
 Height of kart.
 
float m_kart_highest_point
 Largest coordinate on up axis.
 
float m_kart_lowest_point
 Smallest coordinate on up axis.
 
bool m_is_master
 True if this is the master copy, managed by KartProperties.
 
AbstractKartm_kart
 Pointer to the kart object belonging to this kart model.
 
std::shared_ptr< GE::GERenderInfo > m_render_info
 For our engine to get the desired hue for colorization.
 
bool m_support_colorization
 True if this kart model can be colorization in red / blue (now only used in soccer mode).
 
std::unordered_map< std::string, core::matrix4 > m_inverse_bone_matrices
 Used to cache inverse bone matrices for each bone in straight frame for attachment.
 
unsigned m_version
 Version of kart model (in kart.xml).
 
std::string m_exhaust_xml
 Exhaust particle file (xml) for the kart, empty if disabled.
 
const KartPropertiesm_kart_properties
 

Static Private Attributes

static float UNDEFINED = -99.9f
 Value used to indicate undefined entries.
 

Detailed Description

This class stores a 3D kart model.

It takes especially care of attaching the wheels, which are loaded as separate objects. The wheels can turn and (for the front wheels) rotate. The implementation is dependent on the OpenGL library used. Note that this object is copied using the default copy function. See kart.cpp.

Constructor & Destructor Documentation

◆ KartModel()

KartModel::KartModel ( bool  is_master)

Default constructor which initialises all variables with defaults.

Note that the KartModel is copied, so make sure to update makeCopy if any more variables are added to this object. ATM there are two pointers:

  • to the scene node (which is otherwise handled by kart/movable and set later anyway)
  • to the mesh. Sharing mesh is supported in irrlicht, so that's no problem. There are two different type of instances of this class: One is the 'master instances' which is part of the kart_properties. These instances have m_is_master = true, will cause an assertion crash if attachModel is called or the destructor notices any wheels being defined. The other types are copies of one of the master objects: these are used when actually displaying the karts (e.g. in race). They must be copied since otherwise (if the same kart is used more than once) shared variables in KartModel (esp. animation status) will cause incorrect animations. The mesh is shared (between the master instance and all of its copies). Technically the scene node and mesh should be grab'ed on copy, and dropped when the copy is deleted. But since the master copy in the kart_properties_manager is always kept, there is no risk of a mesh being deleted to early.

Member Function Documentation

◆ attachModel()

scene::ISceneNode * KartModel::attachModel ( bool  animated_models,
bool  human_player 
)

Attach the kart model and wheels to the scene node.

Returns
the node with the model attached

◆ finishedRace()

void KartModel::finishedRace ( )

Called when the kart finished the race.

It will force the highest LOD for the kart, since otherwise the end camera can be far away (due to zooming) and show non-animated karts.

◆ getNitroEmittersPositon()

const Vec3 & KartModel::getNitroEmittersPositon ( unsigned int  i) const
inline

Returns the position of nitro emitter relative to the kart.

Parameters
iIndex of the emitter: 0 = right, 1 = left

◆ getSpeedWeightedObject()

const SpeedWeightedObject & KartModel::getSpeedWeightedObject ( int  i) const
inline

Returns the position of a speed weighted object relative to the kart.

Parameters
iIndex of the object

◆ getWheelGraphicsPosition()

const Vec3 & KartModel::getWheelGraphicsPosition ( unsigned int  i) const
inline

Returns the position of a wheel relative to the kart.

Parameters
iIndex of the wheel: 0=front right, 1 = front left, 2 = rear right, 3 = rear left.

◆ getWheelGraphicsRadius()

float KartModel::getWheelGraphicsRadius ( unsigned int  i) const
inline

Returns the radius of the graphical wheels.

Parameters
iIndex of the wheel: 0=front right, 1 = front left, 2 = rear right, 3 = rear left.

◆ initInverseBoneMatrices()

void KartModel::initInverseBoneMatrices ( )
private

Called when a kart is load.

this will load all the inverse bone matrices for each bone in straight frame. The location, rotation and scale in kart.xml for attachments (speedweighted objects, headlight, hat...) are in object space, so if you use a inverse bone matrix * that matrix, it will be relative to the bone, and you can use the result to set parent.

◆ loadInfo()

void KartModel::loadInfo ( const XMLNode node)

This function loads the information about the kart from a xml file.

It does not actually load the models (see load()).

Parameters
nodeXML object of configuration file.

◆ loadNitroEmitterInfo()

void KartModel::loadNitroEmitterInfo ( const XMLNode node,
const std::string &  emitter_name,
int  index 
)
private

Loads a single nitro emitter node.

Currently this the position of the nitro emitter relative to the kart.

Parameters
emitter_nameName of the nitro emitter, e.g. emitter-a.
indexIndex of this emitter in the global m_emitter* fields.

◆ loadWheelInfo()

void KartModel::loadWheelInfo ( const XMLNode node,
const std::string &  wheel_name,
int  index 
)
private

Loads a single wheel node.

Currently this is the name of the wheel model and the position of the wheel relative to the kart.

Parameters
wheel_nameName of the wheel, e.g. wheel-rear-left.
indexIndex of this wheel in the global m_wheel* fields.

◆ makeCopy()

KartModel * KartModel::makeCopy ( std::shared_ptr< GE::GERenderInfo >  ri)

This function returns a copy of this object.

The memory is allocated here, but needs to be managed (esp. freed) by the calling function. It is also marked not to be a master copy, so attachModel can be called for this instance.

◆ OnAnimationEnd()

void KartModel::OnAnimationEnd ( scene::IAnimatedMeshSceneNode *  node)
private

Called from irrlicht when a non-looped animation ends.

This is used to implement an introductory frame sequence before the actual loop can start: first a non-looped version from the first frame to the last frame is being played. When this is finished, this function is called, which then enables the actual loop.

Parameters
nodeThe node for which the animation ended. Should always be m_animated_node

◆ reset()

void KartModel::reset ( )

Resets the kart model.

It stops animation from being played and resets the wheels to the correct position (i.e. no suspension).

◆ setAnimation()

void KartModel::setAnimation ( AnimationFrameType  type,
bool  play_non_loop = false 
)

Enables- or disables the end animation.

Parameters
typeThe type of animation to play.

◆ update()

void KartModel::update ( float  dt,
float  distance,
float  steer,
float  speed,
float  current_lean_angle,
int  gt_replay_index = -1 
)

Rotates and turns the wheels appropriately, and adjust for suspension updates the speed-weighted objects' animations.

Parameters
dttime since last frame
distanceHow far the wheels have rotated since last time.
steerThe actual steer settings.
suspensionSuspension height for all four wheels.
speedThe speed of the kart in meters/sec, used for the speed-weighted objects' animations
current_lean_angleHow much the kart is leaning (positive meaning left side down)
gt_replay_indexThe index to get replay data, used by ghost kart

Member Data Documentation

◆ m_animated_node

scene::IAnimatedMeshSceneNode* KartModel::m_animated_node
private

This is a pointer to the scene node of the kart this model belongs to.

It is necessary to adjust animations, and it is not used (i.e. neither read nor written) if animations are disabled.

◆ m_current_animation

AnimationFrameType KartModel::m_current_animation
private

Which animation is currently being played.

This is used to overwrite the default steering animations while being in race. If this is set to AF_DEFAULT the default steering animation is shown.

◆ m_dampen_suspension_amplitude

float KartModel::m_dampen_suspension_amplitude[4]
private

value used to divide the visual movement of wheels (because the actual movement of wheels in bullet is too large and looks strange).

1=no change, 2=half the amplitude

◆ m_exhaust_xml

std::string KartModel::m_exhaust_xml
private

Exhaust particle file (xml) for the kart, empty if disabled.


◆ m_hat_name

std::string KartModel::m_hat_name
private

Name of the hat to use for this kart.

"" if no hat.

◆ m_is_master

bool KartModel::m_is_master
private

True if this is the master copy, managed by KartProperties.

This is mainly used for debugging, e.g. the master copies might not have anything attached to it etc.

◆ m_kart_width

float KartModel::m_kart_width
private

Width of kart.


◆ m_max_suspension

float KartModel::m_max_suspension[4]
private

Maximum suspension length (i.e.

most extended). If the displayed suspension is any longer, the wheel would look too far away from the chassis.

◆ m_min_suspension

float KartModel::m_min_suspension[4]
private

Minimum suspension length (i.e.

most compressed). If the displayed suspension is shorter than this, the wheel would look wrong.

◆ m_version

unsigned KartModel::m_version
private

Version of kart model (in kart.xml).


◆ m_wheel_graphics_radius

float KartModel::m_wheel_graphics_radius[4]
private

Radius of the graphical wheels.



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