19 #ifndef HEADER_KART_MODEL_HPP
20 #define HEADER_KART_MODEL_HPP
24 #include <unordered_map>
27 #include <IAnimatedMeshSceneNode.h>
30 namespace scene {
class IAnimatedMesh;
class IMesh;
31 class ISceneNode;
class IMeshSceneNode; }
34 namespace GE {
class GERenderInfo;
class GESPM; }
35 namespace SP {
class SPMesh; }
37 #include "utils/constants.hpp"
38 #include "utils/no_copy.hpp"
39 #include "utils/vec3.hpp"
66 void loadFromXMLNode(
const XMLNode* xml_node);
75 scene::IAnimatedMeshSceneNode *
m_node;
91 typedef std::vector<SpeedWeightedObject> SpeedWeightedObjectList;
95 enum HeadlightType :
int
128 HeadlightType m_headlight_type;
139 static HeadlightType getHeadlightTypeFromString(
const std::string& s)
154 m_headlight_type = HLT_POINT;
161 HeadlightObject(
const std::string& filename,
const core::matrix4& location,
162 const std::string& bone_name,
const video::SColor& color,
163 HeadlightType headlight_type,
float radius,
float energy,
164 float inner_cone,
float outer_cone)
166 m_filename = filename;
167 m_location = location;
170 m_bone_name = bone_name;
171 m_headlight_color = color;
172 m_headlight_type = headlight_type;
175 m_inner_cone = inner_cone;
176 m_outer_cone = outer_cone;
179 const std::string& getFilename()
const {
return m_filename; }
182 void setModel(scene::IMesh *mesh) { m_model = mesh; }
184 void setLight(scene::ISceneNode* parent);
186 void setLightNode(scene::ISceneNode* node) { m_node = node; }
188 const scene::ISceneNode *getLightNode()
const {
return m_node; }
190 scene::ISceneNode *getLightNode() {
return m_node; }
192 const scene::IMesh *getModel()
const {
return m_model; }
194 scene::IMesh *getModel() {
return m_model; }
196 const core::matrix4&
getLocation()
const {
return m_location; }
198 const std::string& getBoneName()
const {
return m_bone_name; }
200 HeadlightType getHeadlightType()
const {
return m_headlight_type; }
202 void setRadius(
float radius) { m_radius = radius; }
204 void setEnergy(
float energy) { m_energy = energy; }
206 void setDefaultConeValues(
unsigned light_count)
208 float outer_cone_angle = (light_count == 1 ? 45.0f : 50.0f);
209 m_outer_cone = outer_cone_angle / 180.0f * M_PI;
210 m_inner_cone = m_outer_cone / 1.5f;
213 bool useDefaultSettings()
const
215 return m_radius == 0.0f && m_energy == 0.0f && m_inner_cone == 0.0f &&
216 m_outer_cone == 0.0f;
235 enum AnimationFrameType
237 AF_DEFAULT = AF_BEGIN,
244 AF_LOSE_END_STRAIGHT,
259 AF_END=AF_BACK_RIGHT,
264 int m_animation_frame[AF_COUNT];
293 scene::IMesh *m_wheel_model[4];
296 scene::ISceneNode *m_wheel_node[4];
299 std::string m_wheel_filename[4];
302 Vec3 m_wheel_graphics_position[4];
305 float m_wheel_graphics_radius[4];
308 Vec3 m_nitro_emitter_position[2];
316 std::vector<HeadlightObject> m_headlight_objects;
319 float m_default_physics_suspension[4];
323 float m_min_suspension[4];
328 float m_max_suspension[4];
332 float m_dampen_suspension_amplitude[4];
359 void loadWheelInfo(
const XMLNode &node,
360 const std::string &wheel_name,
int index);
362 void loadNitroEmitterInfo(
const XMLNode &node,
363 const std::string &emitter_name,
int index);
365 void loadSpeedWeightedInfo(
const XMLNode* speed_weighted_node,
int index);
367 void loadHeadlights(
const XMLNode &node,
const std::string& kart_dir);
369 void OnAnimationEnd(scene::IAnimatedMeshSceneNode *node);
393 void initInverseBoneMatrices();
395 void configNode(scene::ISceneNode* node,
const core::matrix4& global_mat,
396 const core::matrix4& inv_mat)
398 const core::matrix4 mat = inv_mat * global_mat;
399 const core::vector3df position = mat.getTranslation();
400 const core::vector3df rotation = mat.getRotationDegrees();
401 const core::vector3df scale = mat.getScale();
402 node->setPosition(position);
403 node->setRotation(rotation);
404 node->setScale(scale);
407 bool handleSpotlight(GE::GESPM* spm);
414 KartModel* makeCopy(std::shared_ptr<GE::GERenderInfo> ri);
416 void loadInfo(
const XMLNode &node);
418 void setDefaultSuspension();
419 void update(
float dt,
float distance,
float steer,
float speed,
420 float current_lean_angle,
421 int gt_replay_index = -1);
423 void resetVisualWheelPosition();
425 attachModel(
bool animatedModels,
bool human_player);
428 scene::IAnimatedMesh*
434 { assert(i>=0 && i<4);
return m_wheel_model[i]; }
440 int getFrame(AnimationFrameType f)
const {
return m_animation_frame[f]; }
442 float getAnimationSpeed()
const {
return m_animation_speed; }
448 {assert(i<4);
return m_wheel_graphics_position[i];}
453 {
return m_wheel_graphics_position;}
459 {assert(i<4);
return m_wheel_graphics_radius[i]; }
465 { assert(i<2);
return m_nitro_emitter_position[i]; }
469 {
return m_has_nitro_emitter;}
473 {
return m_speed_weighted_objects.size();}
478 {
return m_speed_weighted_objects[i];}
499 void setAnimation(AnimationFrameType type,
bool play_non_loop =
false);
510 scene::IAnimatedMeshSceneNode* getAnimatedNode(){
return m_animated_node; }
512 std::shared_ptr<GE::GERenderInfo> getRenderInfo();
514 bool supportColorization()
const {
return m_support_colorization; }
516 void toggleHeadlights(
bool on);
519 getInverseBoneMatrix(
const std::string& bone_name)
const;
521 const std::string& getExhaustXML()
const {
return m_exhaust_xml; }
523 bool hasWheel()
const {
return !m_wheel_filename[0].empty(); }
526 {
return m_kart_properties; }
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
A class to store the headlights of a kart.
Definition: kart_model.hpp:107
video::SColor m_headlight_color
The color of the real light.
Definition: kart_model.hpp:123
scene::IMesh * m_model
The mesh for the headlight.
Definition: kart_model.hpp:117
std::string m_filename
The filename of the headlight model.
Definition: kart_model.hpp:110
core::matrix4 m_location
The relative matrix to the parent kart scene node where the headlight mesh is attached to.
Definition: kart_model.hpp:114
std::string m_bone_name
Attach to which bone in kart model if not empty.
Definition: kart_model.hpp:126
scene::ISceneNode * m_node
The scene node of the headlight (real light).
Definition: kart_model.hpp:120
void setModel(scene::IMesh *mesh)
Sets the mesh for this headlight object.
Definition: kart_model.hpp:182
This class stores a 3D kart model.
Definition: kart_model.hpp:233
scene::IAnimatedMesh * getModel() const
Returns the animated mesh of this kart model.
Definition: kart_model.hpp:429
AnimationFrameType m_current_animation
Which animation is currently being played.
Definition: kart_model.hpp:337
std::string m_model_filename
Name of the 3d model file.
Definition: kart_model.hpp:290
const Vec3 & getNitroEmittersPositon(unsigned int i) const
Returns the position of nitro emitter relative to the kart.
Definition: kart_model.hpp:464
int getBaseFrame() const
Since karts might be animated, we might need to know which base frame to use.
Definition: kart_model.hpp:438
float m_kart_width
Width of kart.
Definition: kart_model.hpp:340
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.
Definition: kart_model.hpp:383
float getWheelGraphicsRadius(unsigned int i) const
Returns the radius of the graphical wheels.
Definition: kart_model.hpp:458
core::matrix4 * m_hat_location
Location of hat in object space.
Definition: kart_model.hpp:278
SpeedWeightedObjectList m_speed_weighted_objects
The speed weighted objects.
Definition: kart_model.hpp:314
float getHeight() const
Returns the height of the kart.
Definition: kart_model.hpp:487
unsigned m_version
Version of kart model (in kart.xml).
Definition: kart_model.hpp:386
scene::ISceneNode ** getWheelNodes()
Returns the array of wheel nodes.
Definition: kart_model.hpp:508
AbstractKart * m_kart
Pointer to the kart object belonging to this kart model.
Definition: kart_model.hpp:372
size_t getSpeedWeightedObjectsCount() const
Returns the number of speed weighted objects for this kart.
Definition: kart_model.hpp:472
float getWidth() const
Returns the width of the kart model.
Definition: kart_model.hpp:484
bool m_has_nitro_emitter
True if kart has nitro emitters.
Definition: kart_model.hpp:311
float m_kart_lowest_point
Smallest coordinate on up axis.
Definition: kart_model.hpp:352
bool m_is_master
True if this is the master copy, managed by KartProperties.
Definition: kart_model.hpp:357
float m_kart_height
Height of kart.
Definition: kart_model.hpp:346
std::shared_ptr< GE::GERenderInfo > m_render_info
For our engine to get the desired hue for colorization.
Definition: kart_model.hpp:375
const bool hasNitroEmitters() const
Returns true if kart has nitro emitters.
Definition: kart_model.hpp:468
float m_kart_length
Length of kart.
Definition: kart_model.hpp:343
AnimationFrameType getAnimation()
Returns information about currently played animation.
Definition: kart_model.hpp:496
float getHighestPoint() const
Highest coordinate on up axis.
Definition: kart_model.hpp:490
bool m_support_colorization
True if this kart model can be colorization in red / blue (now only used in soccer mode).
Definition: kart_model.hpp:379
scene::IMesh * getWheelModel(const int i) const
Returns the mesh of the wheel for this kart.
Definition: kart_model.hpp:433
void setHatMeshName(const std::string &name)
Name of the hat mesh to use.
Definition: kart_model.hpp:505
const Vec3 & getWheelGraphicsPosition(unsigned int i) const
Returns the position of a wheel relative to the kart.
Definition: kart_model.hpp:447
float getLength() const
Returns the length of the kart model.
Definition: kart_model.hpp:481
static float UNDEFINED
Value used to indicate undefined entries.
Definition: kart_model.hpp:287
void setKart(AbstractKart *k)
Sets the kart this model is currently used for.
Definition: kart_model.hpp:502
std::string m_hat_bone
Name of the bone for hat attachment.
Definition: kart_model.hpp:281
const SpeedWeightedObject & getSpeedWeightedObject(int i) const
Returns the position of a speed weighted object relative to the kart.
Definition: kart_model.hpp:477
std::string m_hat_name
Name of the hat to use for this kart.
Definition: kart_model.hpp:284
const Vec3 * getWheelsGraphicsPosition() const
Returns the position of wheels relative to the kart.
Definition: kart_model.hpp:452
float m_kart_highest_point
Largest coordinate on up axis.
Definition: kart_model.hpp:349
float getLowestPoint() const
Lowest coordinate on up axis.
Definition: kart_model.hpp:493
scene::IAnimatedMesh * m_mesh
The mesh of the model.
Definition: kart_model.hpp:270
scene::IAnimatedMeshSceneNode * m_animated_node
This is a pointer to the scene node of the kart this model belongs to.
Definition: kart_model.hpp:275
float m_animation_speed
Animation speed.
Definition: kart_model.hpp:267
std::string m_exhaust_xml
Exhaust particle file (xml) for the kart, empty if disabled.
Definition: kart_model.hpp:389
This class stores the properties of a kart.
Definition: kart_properties.hpp:60
Handles animated textures (textures that move)
Definition: moving_texture.hpp:34
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Definition: sp_mesh.hpp:44
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48
SimpleVec3 getLocation(int idKart)
Attempts to project kart to the given 2D location, to the position with height 0, at a 45 degree angl...
Definition: script_kart.cpp:110
Parameters for a speed-weighted object.
Definition: kart_model.hpp:51
float m_strength_factor
Strength factor: how much the kart speed affects the animation's distance from a static pose (-1 to d...
Definition: kart_model.hpp:59
float m_speed_factor
Speed factor: how much the kart speed affects the animation's speed (-1 to disable)
Definition: kart_model.hpp:62
A speed-weighted object is an object whose characteristics are influenced by the kart's speed.
Definition: kart_model.hpp:48
std::string m_name
Filename of the "speed weighted" object.
Definition: kart_model.hpp:82
scene::IAnimatedMesh * m_model
Model.
Definition: kart_model.hpp:72
core::matrix4 m_location
The relative matrix to the parent kart scene node where the speed weighted object is attached to.
Definition: kart_model.hpp:79
std::string m_bone_name
Attach to which bone in kart model if not empty.
Definition: kart_model.hpp:85
Properties m_properties
Specific properties for this given speed-weighted object, otherwise just a copy of the values from th...
Definition: kart_model.hpp:89
scene::IAnimatedMeshSceneNode * m_node
The scene node the speed weighted model is attached to.
Definition: kart_model.hpp:75