1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 19:32:49 +01:00
openrw/rwengine/include/objects/VehicleObject.hpp

147 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
*/
class VehicleObject : public GameObject
2013-09-09 01:18:36 +02:00
{
private:
float steerAngle;
float throttle;
float brake;
bool handbrake;
public:
VehicleDataHandle vehicle;
VehicleInfoHandle info;
2014-08-22 15:29:46 +02:00
glm::u8vec3 colourPrimary;
glm::u8vec3 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;
struct Part
{
ModelFrame* dummy;
ModelFrame* normal;
ModelFrame* damaged;
2014-06-20 01:47:13 +02:00
btRigidBody* body;
btHingeConstraint* constraint;
bool moveToAngle;
float targetAngle;
float openAngle;
float closedAngle;
2014-06-20 01:47:13 +02: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,
VehicleDataHandle data,
VehicleInfoHandle info,
2014-08-22 15:29:46 +02:00
const glm::u8vec3& prim,
const glm::u8vec3& 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
bool isFlipped() const;
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
}
Part* getSeatEntryDoor(size_t seat);
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 setPartState(Part* part, FrameState state);
2014-03-01 05:12:35 +01:00
void setPartLocked(Part* part, bool locked);
void setPartTarget(Part* part, bool enable, float target);
Part* getPart(const std::string& name);
2014-06-20 01:47:13 +02:00
void applyWaterFloat(const glm::vec3& relPt);
2014-06-20 01:47:13 +02:00
private:
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