2013-09-09 01:18:36 +02:00
|
|
|
#pragma once
|
2014-06-06 16:22:26 +02:00
|
|
|
#ifndef _VEHICLEOBJECT_HPP_
|
|
|
|
#define _VEHICLEOBJECT_HPP_
|
2014-02-28 12:23:51 +01:00
|
|
|
#include <engine/GameObject.hpp>
|
2013-09-09 05:04:21 +02:00
|
|
|
#include <bullet/btBulletDynamicsCommon.h>
|
2013-12-12 16:36:50 +01:00
|
|
|
#include <map>
|
2013-12-20 15:03:32 +01:00
|
|
|
#include <objects/VehicleInfo.hpp>
|
2013-09-09 01:18:36 +02:00
|
|
|
|
|
|
|
/**
|
2014-06-06 16:22:26 +02:00
|
|
|
* @class VehicleObject
|
|
|
|
* Implements Vehicle behaviours.
|
2013-09-09 01:18:36 +02:00
|
|
|
*/
|
2014-06-06 16:22:26 +02:00
|
|
|
struct VehicleObject : public GameObject
|
2013-09-09 01:18:36 +02:00
|
|
|
{
|
2014-03-01 05:12:35 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum /*DamageFlags*/ {
|
|
|
|
DF_Bonnet = 1,
|
|
|
|
DF_Door_lf = 2,
|
|
|
|
DF_Door_rf = 4,
|
|
|
|
DF_Door_lr = 8,
|
|
|
|
DF_Door_rr = 16,
|
|
|
|
DF_Boot = 32,
|
|
|
|
DF_Windscreen = 64,
|
|
|
|
DF_Bump_front = 128,
|
|
|
|
DF_Bump_rear = 256,
|
|
|
|
DF_Wing_lf = 512,
|
|
|
|
DF_Wing_rf = 1024,
|
|
|
|
DF_Wing_lr = 2048,
|
|
|
|
DF_Wing_rr = 4096,
|
|
|
|
};
|
|
|
|
|
2013-09-16 00:44:24 +02:00
|
|
|
private:
|
|
|
|
float steerAngle;
|
|
|
|
float throttle;
|
|
|
|
float brake;
|
|
|
|
bool handbrake;
|
2014-03-01 05:12:35 +01:00
|
|
|
unsigned int damageFlags;
|
2013-09-16 00:44:24 +02:00
|
|
|
public:
|
2013-09-19 00:16:26 +02:00
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
VehicleDataHandle vehicle;
|
|
|
|
VehicleInfoHandle info;
|
2013-09-09 01:18:36 +02:00
|
|
|
glm::vec3 colourPrimary;
|
|
|
|
glm::vec3 colourSecondary;
|
2013-12-12 16:36:50 +01:00
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
std::map<size_t, GameObject*> seatOccupants;
|
2013-09-09 01:18:36 +02:00
|
|
|
|
2013-09-09 05:04:21 +02:00
|
|
|
btRigidBody* physBody;
|
2013-09-15 03:42:35 +02:00
|
|
|
btVehicleRaycaster* physRaycaster;
|
|
|
|
btRaycastVehicle* physVehicle;
|
2013-09-09 05:04:21 +02:00
|
|
|
|
2014-06-06 16:22:26 +02:00
|
|
|
VehicleObject(GameWorld* engine,
|
2013-09-15 03:42:35 +02:00
|
|
|
const glm::vec3& pos,
|
|
|
|
const glm::quat& rot,
|
2014-06-06 13:18:32 +02:00
|
|
|
ModelHandle* model,
|
2014-02-28 12:23:51 +01:00
|
|
|
VehicleDataHandle data,
|
|
|
|
VehicleInfoHandle info,
|
2013-09-15 03:42:35 +02:00
|
|
|
const glm::vec3& prim,
|
|
|
|
const glm::vec3& sec);
|
2013-12-12 16:36:50 +01:00
|
|
|
|
2014-06-06 16:22:26 +02:00
|
|
|
virtual ~VehicleObject();
|
2013-12-15 03:45:47 +01:00
|
|
|
|
|
|
|
void setPosition(const glm::vec3& pos);
|
2013-09-09 05:04:21 +02:00
|
|
|
|
|
|
|
glm::vec3 getPosition() const;
|
|
|
|
|
|
|
|
glm::quat getRotation() const;
|
2013-09-09 01:18:36 +02:00
|
|
|
|
|
|
|
Type type() { return Vehicle; }
|
2013-09-15 03:42:35 +02:00
|
|
|
|
2013-09-16 00:44:24 +02:00
|
|
|
void setSteeringAngle(float);
|
|
|
|
|
|
|
|
float getSteeringAngle() const;
|
|
|
|
|
|
|
|
void setThrottle(float);
|
|
|
|
|
|
|
|
float getThrottle() const;
|
|
|
|
|
|
|
|
void setBraking(float);
|
|
|
|
|
|
|
|
float getBraking() const;
|
|
|
|
|
|
|
|
void setHandbraking(bool);
|
|
|
|
|
|
|
|
bool getHandbraking() const;
|
|
|
|
|
2013-09-15 03:42:35 +02:00
|
|
|
void tick(float dt);
|
2013-12-06 22:25:34 +01:00
|
|
|
|
2013-12-12 16:36:50 +01:00
|
|
|
void ejectAll();
|
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
GameObject* getOccupant(size_t seat);
|
2013-12-12 16:36:50 +01:00
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
void setOccupant(size_t seat, GameObject* occupant);
|
2014-05-29 12:12:40 +02:00
|
|
|
|
|
|
|
glm::vec3 getSeatEntryPosition(size_t seat) const {
|
2014-05-31 09:18:50 +02:00
|
|
|
auto pos = info->seats[seat].offset;
|
2014-06-02 01:08:48 +02:00
|
|
|
pos -= glm::vec3(glm::sign(pos.x) * -0.81756252f, 0.34800607f, -0.486281008f);
|
2014-05-31 09:18:50 +02:00
|
|
|
return getPosition() + getRotation() * pos;
|
2014-05-29 12:12:40 +02:00
|
|
|
}
|
2013-12-12 16:36:50 +01:00
|
|
|
|
2013-12-06 22:25:34 +01:00
|
|
|
virtual bool takeDamage(const DamageInfo& damage);
|
2014-03-01 05:12:35 +01:00
|
|
|
|
|
|
|
void setPartDamaged(unsigned int flag, bool damaged);
|
|
|
|
|
|
|
|
virtual bool isFrameVisible(ModelFrame *frame) const;
|
2013-09-09 01:18:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|