SuperTuxKart
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_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_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. More...
 
 ~KartModel ()
 Destructor.
 
KartModelmakeCopy (std::shared_ptr< RenderInfo > ri)
 This function returns a copy of this object. More...
 
void reset ()
 Resets the kart model. More...
 
void loadInfo (const XMLNode &node)
 This function loads the information about the kart from a xml file. More...
 
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. More...
 
void finishedRace ()
 Called when the kart finished the race. More...
 
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. More...
 
scene::IAnimatedMesh * getModel () const
 Returns the animated mesh of this kart model. More...
 
scene::IMesh * getWheelModel (const int i) const
 Returns the mesh of the wheel for this kart. More...
 
int getBaseFrame () const
 Since karts might be animated, we might need to know which base frame to use. More...
 
int getFrame (AnimationFrameType f) const
 
float getAnimationSpeed () const
 
const Vec3getWheelGraphicsPosition (unsigned int i) const
 Returns the position of a wheel relative to the kart. More...
 
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. More...
 
const Vec3getNitroEmittersPositon (unsigned int i) const
 Returns the position of nitro emitter relative to the kart. More...
 
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. More...
 
float getLength () const
 Returns the length of the kart model. More...
 
float getWidth () const
 Returns the width of the kart model. More...
 
float getHeight () const
 Returns the height of the kart. More...
 
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. More...
 
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. More...
 
scene::ISceneNode ** getWheelNodes ()
 Returns the array of wheel nodes. More...
 
scene::IAnimatedMeshSceneNode * getAnimatedNode ()
 
std::shared_ptr< RenderInfogetRenderInfo ()
 
bool supportColorization () const
 
void toggleHeadlights (bool on)
 
const core::matrix4 & getInverseBoneMatrix (const std::string &bone_name) const
 
const std::string & getExhaustXML () const
 

Private Member Functions

void loadWheelInfo (const XMLNode &node, const std::string &wheel_name, int index)
 Loads a single wheel node. More...
 
void loadNitroEmitterInfo (const XMLNode &node, const std::string &emitter_name, int index)
 Loads a single nitro emitter node. More...
 
void loadSpeedWeightedInfo (const XMLNode *speed_weighted_node)
 Loads a single speed weighted node. More...
 
void loadHeadlights (const XMLNode &node)
 
void OnAnimationEnd (scene::IAnimatedMeshSceneNode *node)
 Called from irrlicht when a non-looped animation ends. More...
 
void initInverseBoneMatrices ()
 Called when a kart is load. More...
 
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. More...
 
float m_animation_speed
 Animation speed. More...
 
scene::IAnimatedMesh * m_mesh
 The mesh of the model. More...
 
scene::IAnimatedMeshSceneNode * m_animated_node
 This is a pointer to the scene node of the kart this model belongs to. More...
 
core::matrix4 * m_hat_location
 Location of hat in object space. More...
 
std::string m_hat_bone
 Name of the bone for hat attachment. More...
 
std::string m_hat_name
 Name of the hat to use for this kart. More...
 
std::string m_model_filename
 Name of the 3d model file. More...
 
scene::IMesh * m_wheel_model [4]
 The four wheel models. More...
 
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. More...
 
Vec3 m_wheel_graphics_position [4]
 The position of all four wheels in the 3d model. More...
 
float m_wheel_graphics_radius [4]
 Radius of the graphical wheels. More...
 
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. More...
 
std::vector< HeadlightObjectm_headlight_objects
 
float m_default_physics_suspension [4]
 Length of the physics suspension when the kart is at rest. More...
 
float m_min_suspension [4]
 Minimum suspension length (i.e. More...
 
float m_max_suspension [4]
 Maximum suspension length (i.e. More...
 
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). More...
 
AnimationFrameType m_current_animation
 Which animation is currently being played. More...
 
float m_kart_width
 Width of kart. More...
 
float m_kart_length
 Length of kart. More...
 
float m_kart_height
 Height of kart. More...
 
float m_kart_highest_point
 Largest coordinate on up axis. More...
 
float m_kart_lowest_point
 Smallest coordinate on up axis. More...
 
bool m_is_master
 True if this is the master copy, managed by KartProperties. More...
 
bool m_play_non_loop
 True if the animation played is non-loop, which will reset to AF_DEFAULT after first loop ends. More...
 
AbstractKartm_kart
 Pointer to the kart object belonging to this kart model. More...
 
std::shared_ptr< RenderInfom_render_info
 For our engine to get the desired hue for colorization. More...
 
bool m_support_colorization
 True if this kart model can be colorization in red / blue (now only used in soccer mode). More...
 
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. More...
 
unsigned m_version
 Version of kart model (in kart.xml). More...
 
std::string m_exhaust_xml
 Exhaust particle file (xml) for the kart, empty if disabled. More...
 

Static Private Attributes

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

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.

◆ getBaseFrame()

int KartModel::getBaseFrame ( ) const
inline

Since karts might be animated, we might need to know which base frame to use.

◆ getHeight()

float KartModel::getHeight ( ) const
inline

Returns the height of the kart.

◆ getLength()

float KartModel::getLength ( ) const
inline

Returns the length of the kart model.

◆ getModel()

scene::IAnimatedMesh* KartModel::getModel ( ) const
inline

Returns the animated mesh of this kart model.

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

◆ getWheelModel()

scene::IMesh* KartModel::getWheelModel ( const int  i) const
inline

Returns the mesh of the wheel for this kart.

◆ getWheelNodes()

scene::ISceneNode** KartModel::getWheelNodes ( )
inline

Returns the array of wheel nodes.

◆ getWidth()

float KartModel::getWidth ( ) const
inline

Returns the width of the kart model.

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

◆ loadSpeedWeightedInfo()

void KartModel::loadSpeedWeightedInfo ( const XMLNode speed_weighted_node)
private

Loads a single speed weighted node.

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

◆ setHatMeshName()

void KartModel::setHatMeshName ( const std::string &  name)
inline

Name of the hat mesh to use.

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

int KartModel::m_animation_frame[AF_COUNT]
private

Which frame number starts/end which animation.

◆ m_animation_speed

float KartModel::m_animation_speed
private

Animation speed.

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

float KartModel::m_default_physics_suspension[4]
private

Length of the physics suspension when the kart is at rest.

◆ m_exhaust_xml

std::string KartModel::m_exhaust_xml
private

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

◆ m_hat_bone

std::string KartModel::m_hat_bone
private

Name of the bone for hat attachment.

◆ m_hat_location

core::matrix4* KartModel::m_hat_location
private

Location of hat in object space.

◆ m_hat_name

std::string KartModel::m_hat_name
private

Name of the hat to use for this kart.

"" if no hat.

◆ m_inverse_bone_matrices

std::unordered_map<std::string, core::matrix4> KartModel::m_inverse_bone_matrices
private

Used to cache inverse bone matrices for each bone in straight frame for attachment.

◆ 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

AbstractKart* KartModel::m_kart
private

Pointer to the kart object belonging to this kart model.

◆ m_kart_height

float KartModel::m_kart_height
private

Height of kart.

◆ m_kart_highest_point

float KartModel::m_kart_highest_point
private

Largest coordinate on up axis.

◆ m_kart_length

float KartModel::m_kart_length
private

Length of kart.

◆ m_kart_lowest_point

float KartModel::m_kart_lowest_point
private

Smallest coordinate on up axis.

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

scene::IAnimatedMesh* KartModel::m_mesh
private

The mesh of the model.

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

std::string KartModel::m_model_filename
private

Name of the 3d model file.

◆ m_play_non_loop

bool KartModel::m_play_non_loop
private

True if the animation played is non-loop, which will reset to AF_DEFAULT after first loop ends.

Mainly used in soccer mode for animation playing after scored.

◆ m_render_info

std::shared_ptr<RenderInfo> KartModel::m_render_info
private

For our engine to get the desired hue for colorization.

◆ m_speed_weighted_objects

SpeedWeightedObjectList KartModel::m_speed_weighted_objects
private

The speed weighted objects.

◆ m_support_colorization

bool KartModel::m_support_colorization
private

True if this kart model can be colorization in red / blue (now only used in soccer mode).

◆ m_version

unsigned KartModel::m_version
private

Version of kart model (in kart.xml).

◆ m_wheel_filename

std::string KartModel::m_wheel_filename[4]
private

Filename of the wheel models.

◆ m_wheel_graphics_position

Vec3 KartModel::m_wheel_graphics_position[4]
private

The position of all four wheels in the 3d model.

◆ m_wheel_graphics_radius

float KartModel::m_wheel_graphics_radius[4]
private

Radius of the graphical wheels.

◆ m_wheel_model

scene::IMesh* KartModel::m_wheel_model[4]
private

The four wheel models.

◆ UNDEFINED

float KartModel::UNDEFINED = -99.9f
staticprivate

Value used to indicate undefined entries.


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