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-12-12 16:36:50 +01:00
|
|
|
#include <map>
|
2013-12-20 15:03:32 +01:00
|
|
|
#include <objects/VehicleInfo.hpp>
|
2014-08-11 00:31:59 +02:00
|
|
|
#include <data/CollisionInstance.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-08-11 18:58:43 +02:00
|
|
|
class VehicleObject : public GameObject
|
2013-09-09 01:18:36 +02:00
|
|
|
{
|
2013-09-16 00:44:24 +02:00
|
|
|
private:
|
|
|
|
float steerAngle;
|
|
|
|
float throttle;
|
|
|
|
float brake;
|
|
|
|
bool handbrake;
|
|
|
|
public:
|
2013-09-19 00:16:26 +02:00
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
VehicleDataHandle vehicle;
|
|
|
|
VehicleInfoHandle info;
|
2014-08-22 15:29:46 +02:00
|
|
|
glm::u8vec3 colourPrimary;
|
|
|
|
glm::u8vec3 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
|
|
|
|
2014-08-11 00:31:59 +02:00
|
|
|
CollisionInstance* collision;
|
2013-09-09 05:04:21 +02:00
|
|
|
btRigidBody* physBody;
|
2013-09-15 03:42:35 +02:00
|
|
|
btVehicleRaycaster* physRaycaster;
|
|
|
|
btRaycastVehicle* physVehicle;
|
2014-12-14 02:32:00 +01:00
|
|
|
|
|
|
|
struct Part
|
|
|
|
{
|
|
|
|
ModelFrame* dummy;
|
|
|
|
ModelFrame* normal;
|
|
|
|
ModelFrame* damaged;
|
2014-06-20 01:47:13 +02:00
|
|
|
btRigidBody* body;
|
|
|
|
btHingeConstraint* constraint;
|
|
|
|
};
|
2014-12-14 02:32:00 +01:00
|
|
|
|
|
|
|
std::map<std::string, Part> dynamicParts;
|
2014-06-20 01:47:13 +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,
|
2014-08-22 15:29:46 +02:00
|
|
|
const glm::u8vec3& prim,
|
|
|
|
const glm::u8vec3& 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;
|
|
|
|
|
2014-07-27 01:38:01 +02:00
|
|
|
void setRotation(const glm::quat &orientation);
|
|
|
|
|
2013-09-09 05:04:21 +02:00
|
|
|
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);
|
2014-06-19 00:05:59 +02:00
|
|
|
|
|
|
|
void tickPhysics(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
|
|
|
|
2014-06-19 20:18:34 +02:00
|
|
|
enum FrameState {
|
|
|
|
OK,
|
|
|
|
DAM,
|
|
|
|
BROKEN
|
|
|
|
};
|
|
|
|
|
2014-12-14 02:32:00 +01:00
|
|
|
void setPartState(Part* part, FrameState state);
|
2014-03-01 05:12:35 +01:00
|
|
|
|
2014-12-14 02:32:00 +01:00
|
|
|
void setPartLocked(Part* part, bool locked);
|
|
|
|
|
|
|
|
Part* getPart(const std::string& name);
|
2014-06-20 01:47:13 +02:00
|
|
|
|
2014-12-14 02:32:00 +01:00
|
|
|
void applyWaterFloat(const glm::vec3& relPt);
|
2014-06-20 01:47:13 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-12-14 02:32:00 +01:00
|
|
|
void registerPart(ModelFrame* mf);
|
|
|
|
void createObjectHinge(btTransform &local, Part* part);
|
|
|
|
void destroyObjectHinge(Part* part);
|
2013-09-09 01:18:36 +02:00
|
|
|
};
|
|
|
|
|
2014-06-07 05:11:20 +02:00
|
|
|
/**
|
|
|
|
* Implements vehicle ray casting behaviour.
|
|
|
|
* i.e. ignore the god damn vehicle body when casting rays.
|
|
|
|
*/
|
|
|
|
class VehicleRaycaster : public btVehicleRaycaster
|
|
|
|
{
|
|
|
|
btDynamicsWorld* _world;
|
|
|
|
VehicleObject* _vehicle;
|
|
|
|
public:
|
|
|
|
VehicleRaycaster(VehicleObject* vehicle, btDynamicsWorld* world)
|
|
|
|
: _world(world), _vehicle(vehicle) {}
|
|
|
|
|
|
|
|
void* castRay(const btVector3 &from, const btVector3 &to, btVehicleRaycasterResult &result);
|
|
|
|
};
|
|
|
|
|
2013-09-09 01:18:36 +02:00
|
|
|
#endif
|