1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-12 13:52:48 +01:00
openrw/rwengine/include/engine/GameObject.hpp

163 lines
3.1 KiB
C++
Raw Normal View History

2013-09-09 01:18:36 +02:00
#pragma once
#ifndef _GAMEOBJECT_HPP_
#define _GAMEOBJECT_HPP_
2013-09-09 01:18:36 +02:00
2014-06-06 18:04:00 +02:00
#include <engine/RWTypes.hpp>
#include <loaders/LoaderIDE.hpp>
#include <loaders/LoaderIPL.hpp>
2013-09-09 01:18:36 +02:00
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
2013-09-09 01:18:36 +02:00
#include <memory>
class Skeleton;
2014-06-06 18:04:00 +02:00
class CharacterController;
2014-03-01 05:12:35 +01:00
class ModelFrame;
2013-09-11 01:26:13 +02:00
class Animator;
2013-09-09 01:18:36 +02:00
2013-12-20 17:02:46 +01:00
class GameWorld;
2013-09-09 01:18:36 +02:00
/**
* @brief Base data and interface for all world "objects" like vehicles, peds.
*
* Contains handle to the world, and other useful properties like water level
* tracking used to make tunnels work.
2013-09-09 01:18:36 +02:00
*/
class GameObject
2013-09-09 01:18:36 +02:00
{
glm::vec3 _lastPosition;
glm::quat _lastRotation;
public:
2013-09-09 01:18:36 +02:00
glm::vec3 position;
glm::quat rotation;
2014-06-06 13:18:32 +02:00
ModelHandle* model; /// Cached pointer to Object's Model.
2015-01-23 13:25:15 +01:00
2013-12-20 17:02:46 +01:00
GameWorld* engine;
2013-09-09 01:18:36 +02:00
2013-09-11 01:26:13 +02:00
Animator* animator; /// Object's animator.
Skeleton* skeleton;
2014-06-13 22:54:17 +02:00
2013-12-06 22:25:34 +01:00
/**
* Health value
*/
float mHealth;
2014-06-13 22:54:17 +02:00
bool _inWater;
/**
* @brief stores the height of water at the last tick
*/
float _lastHeight;
2015-01-23 13:25:15 +01:00
/**
* Should object be rendered?
*/
bool visible;
2014-06-06 13:18:32 +02:00
GameObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, ModelHandle* model)
: _lastPosition(pos), _lastRotation(rot), position(pos), rotation(rot),
model(model), engine(engine), animator(nullptr), skeleton(nullptr), mHealth(0.f),
2015-01-23 13:25:15 +01:00
_inWater(false), _lastHeight(std::numeric_limits<float>::max()), visible(true)
{}
2013-12-12 03:55:31 +01:00
virtual ~GameObject();
2013-09-09 01:18:36 +02:00
/**
* @brief Enumeration of possible object types.
*/
2013-09-09 01:18:36 +02:00
enum Type
{
Instance,
Character,
2014-03-01 12:19:33 +01:00
Vehicle,
Pickup,
Projectile,
Cutscene,
2014-03-01 12:19:33 +01:00
Unknown
2013-09-09 01:18:36 +02:00
};
/**
* @brief determines what type of object this is.
* @return one of Type
*/
2014-03-01 12:19:33 +01:00
virtual Type type() { return Unknown; }
2013-09-09 01:18:36 +02:00
virtual void setPosition(const glm::vec3& pos);
virtual glm::vec3 getPosition() const { return position; }
const glm::vec3& getLastPosition() const { return _lastPosition; }
2013-09-09 05:04:21 +02:00
virtual glm::quat getRotation() const;
2014-07-25 04:30:44 +02:00
virtual void setRotation(const glm::quat &orientation);
/**
* @brief setHeading Rotates the object to face heading, in degrees.
*/
void setHeading(float heading);
2013-12-06 22:25:34 +01:00
struct DamageInfo
{
enum DamageType
{
Explosion,
Burning,
Bullet,
Physics
};
/**
* World position of damage
*/
glm::vec3 damageLocation;
/**
* World position of the source (used for direction)
*/
glm::vec3 damageSource;
/**
* Magnitude of destruction
*/
float hitpoints;
/**
* Type of the damage
*/
DamageType type;
2014-06-11 22:00:53 +02:00
/**
* Physics impulse.
*/
float impulse;
2013-12-06 22:25:34 +01:00
};
virtual bool takeDamage(const DamageInfo& /*damage*/) { return false; }
2014-03-01 05:12:35 +01:00
virtual bool isAnimationFixed() const { return true; }
2014-06-13 22:54:17 +02:00
virtual bool isInWater() const { return _inWater; }
virtual void tick(float dt) = 0;
/**
* @brief Function used to modify the last transform
* @param newPos
*/
void _updateLastTransform()
{
_lastPosition = getPosition();
_lastRotation = getRotation();
}
glm::mat4 getTimeAdjustedTransform(float alpha) const {
glm::mat4 t;
t = glm::translate(t, glm::mix(_lastPosition, getPosition(), alpha));
t = t * glm::mat4_cast(glm::slerp(_lastRotation, getRotation(), alpha));
return t;
}
2013-09-09 01:18:36 +02:00
};
#endif // __GAMEOBJECTS_HPP__