2013-09-09 01:18:36 +02:00
|
|
|
#pragma once
|
2014-02-28 12:23:51 +01:00
|
|
|
#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>
|
2013-12-20 15:03:32 +01:00
|
|
|
#include <loaders/LoaderIDE.hpp>
|
|
|
|
#include <loaders/LoaderIPL.hpp>
|
2013-09-09 01:18:36 +02:00
|
|
|
#include <glm/gtc/quaternion.hpp>
|
2014-07-14 02:29:05 +02:00
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
2013-09-09 01:18:36 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2014-12-11 18:48:47 +01:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
2014-07-09 06:04:48 +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
|
|
|
*/
|
2014-07-14 02:29:05 +02:00
|
|
|
class GameObject
|
2013-09-09 01:18:36 +02:00
|
|
|
{
|
2014-07-14 02:29:05 +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.
|
2014-12-11 18:48:47 +01:00
|
|
|
Skeleton* skeleton;
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2013-12-06 22:25:34 +01:00
|
|
|
/**
|
|
|
|
* Health value
|
|
|
|
*/
|
2014-06-02 01:08:48 +02:00
|
|
|
float mHealth;
|
|
|
|
|
2014-06-13 22:54:17 +02:00
|
|
|
bool _inWater;
|
|
|
|
|
2014-07-09 06:04:48 +02:00
|
|
|
/**
|
|
|
|
* @brief stores the height of water at the last tick
|
|
|
|
*/
|
2014-06-15 02:34:13 +02:00
|
|
|
float _lastHeight;
|
2015-01-23 13:25:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Should object be rendered?
|
|
|
|
*/
|
|
|
|
bool visible;
|
2014-06-15 02:34:13 +02:00
|
|
|
|
2014-06-06 13:18:32 +02:00
|
|
|
GameObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, ModelHandle* model)
|
2014-12-11 18:48:47 +01:00
|
|
|
: _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)
|
2014-06-02 01:08:48 +02:00
|
|
|
{}
|
2013-12-12 03:55:31 +01:00
|
|
|
|
2014-12-11 18:48:47 +01:00
|
|
|
virtual ~GameObject();
|
2013-09-09 01:18:36 +02:00
|
|
|
|
2014-07-09 06:04:48 +02:00
|
|
|
/**
|
|
|
|
* @brief Enumeration of possible object types.
|
|
|
|
*/
|
2013-09-09 01:18:36 +02:00
|
|
|
enum Type
|
|
|
|
{
|
2014-07-04 22:06:56 +02:00
|
|
|
Instance,
|
|
|
|
Character,
|
2014-03-01 12:19:33 +01:00
|
|
|
Vehicle,
|
2014-07-04 22:06:56 +02:00
|
|
|
Pickup,
|
2014-07-20 22:21:51 +02:00
|
|
|
Projectile,
|
2014-07-30 14:44:25 +02:00
|
|
|
Cutscene,
|
2014-03-01 12:19:33 +01:00
|
|
|
Unknown
|
2013-09-09 01:18:36 +02:00
|
|
|
};
|
|
|
|
|
2014-07-09 06:04:48 +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);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-07-27 01:38:01 +02:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
};
|
|
|
|
|
2014-07-09 06:04:48 +02:00
|
|
|
virtual bool takeDamage(const DamageInfo& /*damage*/) { return false; }
|
2014-03-01 05:12:35 +01:00
|
|
|
|
2014-06-02 05:58:41 +02:00
|
|
|
virtual bool isAnimationFixed() const { return true; }
|
2014-06-13 22:54:17 +02:00
|
|
|
|
|
|
|
virtual bool isInWater() const { return _inWater; }
|
2014-07-02 00:04:23 +02:00
|
|
|
|
|
|
|
virtual void tick(float dt) = 0;
|
2014-07-14 02:29:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
};
|
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
#endif // __GAMEOBJECTS_HPP__
|