1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-08 03:42:35 +01:00
openrw/rwengine/include/objects/VehicleObject.hpp

149 lines
3.0 KiB
C++
Raw Normal View History

2013-09-09 01:18:36 +02:00
#pragma once
2014-06-06 16:22:26 +02:00
#ifndef _VEHICLEOBJECT_HPP_
#define _VEHICLEOBJECT_HPP_
#include <engine/GameObject.hpp>
#include <map>
#include <objects/VehicleInfo.hpp>
#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-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,
};
private:
float steerAngle;
float throttle;
float brake;
bool handbrake;
2014-03-01 05:12:35 +01:00
unsigned int damageFlags;
public:
VehicleDataHandle vehicle;
VehicleInfoHandle info;
2013-09-09 01:18:36 +02:00
glm::vec3 colourPrimary;
glm::vec3 colourSecondary;
std::map<size_t, GameObject*> seatOccupants;
2013-09-09 01:18:36 +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;
2013-09-09 05:04:21 +02:00
2014-06-20 01:47:13 +02:00
struct HingeInfo {
btRigidBody* body;
btHingeConstraint* constraint;
};
std::map<ModelFrame*, HingeInfo> _hingedObjects;
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,
VehicleDataHandle data,
VehicleInfoHandle info,
2013-09-15 03:42:35 +02:00
const glm::vec3& prim,
const glm::vec3& sec);
2014-06-06 16:22:26 +02:00
virtual ~VehicleObject();
void setPosition(const glm::vec3& pos);
2013-09-09 05:04:21 +02:00
glm::vec3 getPosition() const;
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
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);
void tickPhysics(float dt);
2013-12-06 22:25:34 +01:00
void ejectAll();
GameObject* getOccupant(size_t seat);
void setOccupant(size_t seat, GameObject* occupant);
2014-05-29 12:12:40 +02:00
glm::vec3 getSeatEntryPosition(size_t seat) const {
auto pos = info->seats[seat].offset;
pos -= glm::vec3(glm::sign(pos.x) * -0.81756252f, 0.34800607f, -0.486281008f);
return getPosition() + getRotation() * pos;
2014-05-29 12:12:40 +02: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
};
void setFrameState(ModelFrame *f, FrameState state);
2014-03-01 05:12:35 +01:00
void applyWaterFloat(const glm::vec3& relPt);
2014-06-20 01:47:13 +02:00
void setHingeLocked(ModelFrame* frame, bool locked);
private:
void createObjectHinge(btTransform &local, ModelFrame* frame);
void destroyObjectHinge(HingeInfo& hinge);
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