SuperTuxKart
|
This class stores a 3D kart model. More...
#include <kart_model.hpp>
Public Member Functions | |
KartModel (bool is_master) | |
Default constructor which initialises all variables with defaults. More... | |
~KartModel () | |
Destructor. | |
KartModel * | makeCopy (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 Vec3 & | getWheelGraphicsPosition (unsigned int i) const |
Returns the position of a wheel relative to the kart. More... | |
const Vec3 * | getWheelsGraphicsPosition () 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 Vec3 & | getNitroEmittersPositon (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 SpeedWeightedObject & | getSpeedWeightedObject (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< RenderInfo > | 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 KartProperties * | getKartProperties () 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< HeadlightObject > | m_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... | |
AbstractKart * | m_kart |
Pointer to the kart object belonging to this kart model. More... | |
std::shared_ptr< RenderInfo > | m_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... | |
const KartProperties * | m_kart_properties |
Static Private Attributes | |
static float | UNDEFINED = -99.9f |
Value used to indicate undefined entries. More... | |
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.
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:
scene::ISceneNode * KartModel::attachModel | ( | bool | animated_models, |
bool | human_player | ||
) |
Attach the kart model and wheels to the scene node.
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.
|
inline |
Since karts might be animated, we might need to know which base frame to use.
|
inline |
Returns the height of the kart.
|
inline |
Returns the length of the kart model.
|
inline |
Returns the animated mesh of this kart model.
|
inline |
Returns the position of nitro emitter relative to the kart.
i | Index of the emitter: 0 = right, 1 = left |
|
inline |
Returns the position of a speed weighted object relative to the kart.
i | Index of the object |
|
inline |
Returns the position of a wheel relative to the kart.
i | Index of the wheel: 0=front right, 1 = front left, 2 = rear right, 3 = rear left. |
|
inline |
Returns the radius of the graphical wheels.
i | Index of the wheel: 0=front right, 1 = front left, 2 = rear right, 3 = rear left. |
|
inline |
Returns the mesh of the wheel for this kart.
|
inline |
Returns the array of wheel nodes.
|
inline |
Returns the width of the kart model.
|
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.
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()).
node | XML object of configuration file. |
|
private |
Loads a single nitro emitter node.
Currently this the position of the nitro emitter relative to the kart.
emitter_name | Name of the nitro emitter, e.g. emitter-a. |
index | Index of this emitter in the global m_emitter* fields. |
|
private |
Loads a single speed weighted node.
|
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.
wheel_name | Name of the wheel, e.g. wheel-rear-left. |
index | Index of this wheel in the global m_wheel* fields. |
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.
|
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.
node | The node for which the animation ended. Should always be m_animated_node |
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).
void KartModel::setAnimation | ( | AnimationFrameType | type, |
bool | play_non_loop = false |
||
) |
Enables- or disables the end animation.
type | The type of animation to play. |
|
inline |
Name of the hat mesh to use.
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.
dt | time since last frame |
distance | How far the wheels have rotated since last time. |
steer | The actual steer settings. |
suspension | Suspension height for all four wheels. |
speed | The speed of the kart in meters/sec, used for the speed-weighted objects' animations |
current_lean_angle | How much the kart is leaning (positive meaning left side down) |
gt_replay_index | The index to get replay data, used by ghost kart |
|
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.
|
private |
Which frame number starts/end which animation.
|
private |
Animation speed.
|
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.
|
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
|
private |
Length of the physics suspension when the kart is at rest.
|
private |
Exhaust particle file (xml) for the kart, empty if disabled.
|
private |
Name of the bone for hat attachment.
|
private |
Location of hat in object space.
|
private |
Name of the hat to use for this kart.
"" if no hat.
|
private |
Used to cache inverse bone matrices for each bone in straight frame for attachment.
|
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.
|
private |
Pointer to the kart object belonging to this kart model.
|
private |
Height of kart.
|
private |
Largest coordinate on up axis.
|
private |
Length of kart.
|
private |
Smallest coordinate on up axis.
|
private |
Width of kart.
|
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.
|
private |
The mesh of the model.
|
private |
Minimum suspension length (i.e.
most compressed). If the displayed suspension is shorter than this, the wheel would look wrong.
|
private |
Name of the 3d model file.
|
private |
For our engine to get the desired hue for colorization.
|
private |
The speed weighted objects.
|
private |
True if this kart model can be colorization in red / blue (now only used in soccer mode).
|
private |
Version of kart model (in kart.xml).
|
private |
Filename of the wheel models.
|
private |
The position of all four wheels in the 3d model.
|
private |
Radius of the graphical wheels.
|
private |
The four wheel models.
|
staticprivate |
Value used to indicate undefined entries.