19#ifndef HEADER_PHYSICAL_OBJECT_HPP
20#define HEADER_PHYSICAL_OBJECT_HPP
24#include "btBulletDynamicsCommon.h"
26#include "network/rewinder.hpp"
28#include "physics/user_pointer.hpp"
29#include "utils/vec3.hpp"
44 MP_CONE_Y, MP_CONE_X, MP_CONE_Z,
45 MP_CYLINDER_Y, MP_CYLINDER_X, MP_CYLINDER_Z,
46 MP_BOX, MP_SPHERE, MP_EXACT};
190 btTransform m_last_transform;
196 bool m_no_server_state;
203 static std::shared_ptr<PhysicalObject> fromXML
207 virtual void reset ();
208 virtual void handleExplosion(
const Vec3& pos,
bool directHit);
212 void move (
const Vec3& xyz,
const core::vector3df& hpr);
215 bool castRay(
const btVector3 &from,
216 const btVector3 &to, btVector3 *hit_point,
217 const Material **material, btVector3 *normal,
218 bool interpolate_normal)
const;
226 btDefaultMotionState* getMotionState()
const {
return m_motion_state; }
248 float getRadius()
const {
return m_radius; }
270 void disable(
void *memory)
276 void enable(
void *memory)
292 virtual std::function<void()> getLocalStateRestoreFunction();
294 void joinToMainTrack();
295 std::shared_ptr<PhysicalObject> clone(
TrackObject* track_obj)
298 obj->copyFromMainProcess(track_obj);
299 return std::shared_ptr<PhysicalObject>(obj);
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Definition: material.hpp:48
Definition: physical_object.hpp:49
Vec3 m_linear_factor
Bullet's linear factor.
Definition: physical_object.hpp:66
float m_linear_damping
Bullet's linear damping factor.
Definition: physical_object.hpp:70
float m_friction
Friction for this object.
Definition: physical_object.hpp:64
float m_reset_height
If the item is below that height, it is reset (when m_reset_when_too_low is true).
Definition: physical_object.hpp:85
std::string m_id
ID of the object.
Definition: physical_object.hpp:52
bool m_crash_reset
Trigger a reset in karts touching it?
Definition: physical_object.hpp:75
float m_mass
Mass of the object.
Definition: physical_object.hpp:54
bool m_flatten_kart
Flatten the kart when this object is touched.
Definition: physical_object.hpp:79
bool m_reset_when_too_low
Reset the object when it falls under the track (useful e.g.
Definition: physical_object.hpp:82
float m_height
Height of an object, to overwrite the graphical dimension.
Definition: physical_object.hpp:58
float m_radius
Radius of the object, to overwrite the graphical dimension.
Definition: physical_object.hpp:56
Vec3 m_angular_factor
Bullet angular factor.
Definition: physical_object.hpp:68
PhysicalObject::BodyTypes m_body_type
Shape of the object.
Definition: physical_object.hpp:60
float m_angular_damping
Bullet's angular damping factor.
Definition: physical_object.hpp:72
std::string m_on_kart_collision
If non-empty, the name of the scripting function to call when a kart collides with this object.
Definition: physical_object.hpp:89
void init()
Initialises a Settings object.
Definition: physical_object.cpp:113
std::string m_on_item_collision
If non-empty, the name of the scripting function to call when a (flyable) item collides with this obj...
Definition: physical_object.hpp:93
float m_restitution
Restitution of the physical object.
Definition: physical_object.hpp:62
bool m_knock_kart
Knock the kart around.
Definition: physical_object.hpp:77
Definition: physical_object.hpp:40
btDefaultMotionState * m_motion_state
Bullet's motion state for this object.
Definition: physical_object.hpp:127
UserPointer m_user_pointer
The pointer that is stored in the bullet rigid body back to this object.
Definition: physical_object.hpp:136
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).
Definition: physical_object.hpp:168
virtual void rewindToEvent(BareNetworkString *buffer)
Called when an event needs to be replayed.
Definition: physical_object.hpp:289
btRigidBody * m_body
The corresponding bullet rigid body.
Definition: physical_object.hpp:124
Vec3 m_graphical_offset
The mesh might not have the same center as bullet does.
Definition: physical_object.hpp:148
void removeBody()
Remove body from dynamic world.
Definition: physical_object.cpp:774
float m_mass
The mass of this object.
Definition: physical_object.hpp:130
virtual BareNetworkString * saveState(std::vector< std::string > *ru)
Provides a copy of the state of the object in one memory buffer.
Definition: physical_object.cpp:841
virtual void reset()
Nothing to do here.
Definition: physical_object.cpp:708
bool isSoccerBall() const
Returns true if this object is a soccer ball.
Definition: physical_object.cpp:753
std::string m_id
ID of the object.
Definition: physical_object.hpp:121
btCollisionShape * m_shape
The bullet collision shape.
Definition: physical_object.hpp:118
void init(const Settings &settings)
Additional initialisation after loading of the model is finished.
Definition: physical_object.cpp:238
void updateGraphics(float dt)
This updates all only graphical elements.
Definition: physical_object.cpp:630
bool m_explode_kart
True if kart should "explode" when touching this.
Definition: physical_object.hpp:162
btTransform m_init_pos
This is the initial position of the object for the physics.
Definition: physical_object.hpp:139
virtual void undoState(BareNetworkString *buffer)
Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo).
Definition: physical_object.hpp:291
core::vector3df m_init_xyz
The initial XYZ position of the object.
Definition: physical_object.hpp:104
btRigidBody * getBody() const
Returns the rigid body of this physical object.
Definition: physical_object.hpp:229
std::string m_on_kart_collision
If non-empty, the name of the scripting function to call when a kart collides with this object.
Definition: physical_object.hpp:176
TriangleMesh * m_triangle_mesh
Non-null only if the shape is exact.
Definition: physical_object.hpp:187
BodyTypes m_body_type
The shape of this object.
Definition: physical_object.hpp:115
bool isCrashReset() const
Returns true if this object should trigger a rescue in a kart that hits it.
Definition: physical_object.hpp:233
virtual void undoEvent(BareNetworkString *buffer)
Called when an event needs to be undone.
Definition: physical_object.hpp:288
core::vector3df m_init_scale
The initial scale of the object.
Definition: physical_object.hpp:110
void setInteraction(std::string interaction)
Sets the interaction type.
Definition: physical_object.cpp:760
btTransform m_current_transform
Save current transform to avoid frequent lookup from world transform.
Definition: physical_object.hpp:143
void addBody()
Add body to dynamic world.
Definition: physical_object.cpp:785
std::string getID()
Returns the ID of this physical object.
Definition: physical_object.hpp:224
void update(float dt)
Update, called once per physics time step.
Definition: physical_object.cpp:658
float m_radius
Radius of the object - this obviously depends on the actual shape.
Definition: physical_object.hpp:156
bool m_crash_reset
True if a kart colliding with this object should be rescued.
Definition: physical_object.hpp:159
core::vector3df m_init_hpr
The initial hpr of the object.
Definition: physical_object.hpp:107
void hit(const Material *m, const Vec3 &normal)
Called when a physical object hits the track.
Definition: physical_object.cpp:800
BodyTypes
The supported collision shapes.
Definition: physical_object.hpp:43
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 val...
Definition: physical_object.hpp:172
bool m_is_dynamic
If this body is a bullet dynamic body, i.e.
Definition: physical_object.hpp:184
std::string m_on_item_collision
If non-empty, the name of the scripting function to call when a (flyable) item collides with this obj...
Definition: physical_object.hpp:180
bool isExplodeKartObject() const
Returns true if this object should cause an explosion if a kart hits it.
Definition: physical_object.hpp:237
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.
Definition: physical_object.cpp:692
virtual void saveTransform()
Called before a rewind.
Definition: physical_object.cpp:826
virtual void restoreState(BareNetworkString *buffer, int count)
Called when a state needs to be replayed.
Definition: physical_object.cpp:874
virtual void computeError()
Called when a rewind is finished, and is used to compute the error caused by the rewind (which is the...
Definition: physical_object.cpp:834
Definition: rewinder.hpp:44
Definition: smooth_network_body.hpp:39
This is a base object for any separate object on the track, which might also have a skeletal animatio...
Definition: track_object.hpp:56
A special class to store a triangle mesh with a separate material per triangle.
Definition: triangle_mesh.hpp:35
A UserPointer is stored as a user pointer in all bullet bodies.
Definition: user_pointer.hpp:36
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
bool isFlattenKartObject() const
Returns true if this object should cause a kart that touches it to be flattened.
Definition: physical_object.hpp:269
This class help to smooth the graphicial transformation of network controlled object....