mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 10:22:52 +01:00
Vehicle seating
This commit is contained in:
parent
9340b11284
commit
17ca56a7fe
@ -78,12 +78,6 @@ struct CarData
|
||||
int16_t modelLOD; // used only when type == PLANE
|
||||
};
|
||||
float wheelScale; // used only when type == CAR
|
||||
|
||||
struct SeatData {
|
||||
glm::vec3 offset;
|
||||
};
|
||||
|
||||
std::vector<SeatData> seats;
|
||||
};
|
||||
|
||||
struct CharacterData
|
||||
|
@ -17,6 +17,7 @@ struct GTACharacter : public GTAObject
|
||||
{
|
||||
private:
|
||||
GTAVehicle* currentVehicle;
|
||||
size_t currentSeat;
|
||||
|
||||
void createActor(const glm::vec3& size = glm::vec3(0.35f, 0.35f, 1.3f));
|
||||
void destroyActor();
|
||||
@ -74,7 +75,8 @@ public:
|
||||
bool enterVehicle(GTAVehicle* vehicle, size_t seat);
|
||||
|
||||
GTAVehicle *getCurrentVehicle() const;
|
||||
void setCurrentVehicle(GTAVehicle *value);
|
||||
size_t getCurrentSeat() const;
|
||||
void setCurrentVehicle(GTAVehicle *value, size_t seat);
|
||||
|
||||
virtual bool takeDamage(const DamageInfo& damage);
|
||||
};
|
||||
|
@ -47,7 +47,7 @@ struct VehicleHandlingInfo
|
||||
float suspensionLowerLimit;
|
||||
float suspensionBias;
|
||||
uint32_t flags;
|
||||
|
||||
|
||||
enum /*VehicleFlags*/ {
|
||||
VF_1G_BOOST = 1 << 0,
|
||||
VF_2G_BOOST = 2 << 0,
|
||||
@ -73,11 +73,17 @@ struct WheelInfo
|
||||
glm::vec3 position;
|
||||
};
|
||||
|
||||
struct SeatInfo {
|
||||
glm::vec3 offset;
|
||||
};
|
||||
|
||||
struct VehicleInfo
|
||||
{
|
||||
VehicleHandlingInfo handling;
|
||||
|
||||
std::vector<WheelInfo> wheels;
|
||||
|
||||
std::vector<SeatInfo> seats;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -239,14 +239,22 @@ GTAVehicle *GTAEngine::createVehicle(const uint16_t id, const glm::vec3& pos, co
|
||||
Model* model = gameData.models[vti->second->modelName];
|
||||
auto info = gameData.vehicleInfo.find(vti->second->handlingID);
|
||||
if(model && info != gameData.vehicleInfo.end()) {
|
||||
if( info->second.wheels.size() == 0 ) {
|
||||
if( info->second.wheels.size() == 0 && info->second.seats.size() == 0 ) {
|
||||
for( size_t f = 0; f < model->frames.size(); ++f) {
|
||||
if( model->frameNames.size() > f) {
|
||||
std::string& name = model->frameNames[f];
|
||||
|
||||
if( name.substr(0, 5) == "wheel" ) {
|
||||
auto frameTrans = model->getFrameMatrix(f);
|
||||
info->second.wheels.push_back({glm::vec3(frameTrans[3])});
|
||||
}
|
||||
if(name.substr(0, 3) == "ped" && name.substr(name.size()-4) == "seat") {
|
||||
auto p = model->frames[f].defaultTranslation;
|
||||
p.x = p.x * -1.f;
|
||||
info->second.seats.push_back({p});
|
||||
p.x = p.x * -1.f;
|
||||
info->second.seats.push_back({p});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
GTACharacter::GTACharacter(GTAEngine* engine, const glm::vec3& pos, const glm::quat& rot, Model* model, std::shared_ptr<CharacterData> data)
|
||||
: GTAObject(engine, pos, rot, model),
|
||||
currentVehicle(nullptr), ped(data), physCharacter(nullptr),
|
||||
currentVehicle(nullptr), currentSeat(0), ped(data), physCharacter(nullptr),
|
||||
controller(nullptr), currentActivity(None)
|
||||
{
|
||||
mHealth = 100.f;
|
||||
@ -194,16 +194,19 @@ bool GTACharacter::enterVehicle(GTAVehicle* vehicle, size_t seat)
|
||||
// Make sure we leave any vehicle we're inside
|
||||
enterVehicle(nullptr, 0);
|
||||
vehicle->setOccupant(seat, this);
|
||||
setCurrentVehicle(vehicle);
|
||||
setCurrentVehicle(vehicle, seat);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(currentVehicle) {
|
||||
vehicle->setOccupant(seat, nullptr);
|
||||
setPosition(currentVehicle->getPosition());
|
||||
setCurrentVehicle(nullptr);
|
||||
setCurrentVehicle(nullptr, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
GTAVehicle *GTACharacter::getCurrentVehicle() const
|
||||
@ -211,9 +214,15 @@ GTAVehicle *GTACharacter::getCurrentVehicle() const
|
||||
return currentVehicle;
|
||||
}
|
||||
|
||||
void GTACharacter::setCurrentVehicle(GTAVehicle *value)
|
||||
size_t GTACharacter::getCurrentSeat() const
|
||||
{
|
||||
return currentSeat;
|
||||
}
|
||||
|
||||
void GTACharacter::setCurrentVehicle(GTAVehicle *value, size_t seat)
|
||||
{
|
||||
currentVehicle = value;
|
||||
currentSeat = seat;
|
||||
if(currentVehicle == nullptr && physCharacter == nullptr) {
|
||||
createActor();
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ void GTAVehicle::ejectAll()
|
||||
) {
|
||||
if(it->second->type() == GTAObject::Character) {
|
||||
GTACharacter* c = static_cast<GTACharacter*>(it->second);
|
||||
c->setCurrentVehicle(nullptr);
|
||||
c->setCurrentVehicle(nullptr, 0);
|
||||
c->setPosition(getPosition());
|
||||
}
|
||||
it = seatOccupants.erase(it);
|
||||
|
@ -268,8 +268,19 @@ void GTARenderer::renderWorld()
|
||||
GTACharacter* charac = engine->pedestrians[i];
|
||||
|
||||
glm::mat4 matrixModel;
|
||||
matrixModel = glm::translate(matrixModel, charac->getPosition());
|
||||
matrixModel = matrixModel * glm::mat4_cast(charac->rotation);
|
||||
|
||||
if(charac->getCurrentVehicle()) {
|
||||
auto v = charac->getCurrentVehicle();
|
||||
matrixModel = glm::translate(matrixModel,
|
||||
v->getPosition());
|
||||
matrixModel = matrixModel * glm::mat4_cast(v->getRotation());
|
||||
glm::vec3 seatpos = v->info.seats[charac->getCurrentSeat()].offset;
|
||||
matrixModel = glm::translate(matrixModel, seatpos);
|
||||
}
|
||||
else {
|
||||
matrixModel = glm::translate(matrixModel, charac->getPosition());
|
||||
matrixModel = matrixModel * glm::mat4_cast(charac->rotation);
|
||||
}
|
||||
|
||||
if(!charac->model) continue;
|
||||
|
||||
|
@ -165,33 +165,6 @@ void update(float dt)
|
||||
player = new GTAPlayerAIController(playerCharacter);
|
||||
}
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::K)) {
|
||||
if( player == nullptr ) {
|
||||
playerCharacter = gta->createPedestrian(1, plyPos+glm::vec3(0.f,10.f,0.f));
|
||||
player = new GTAPlayerAIController(playerCharacter);
|
||||
|
||||
// Pick random vehicle.
|
||||
auto it = gta->vehicleTypes.begin();
|
||||
std::uniform_int_distribution<int> uniform(0, 9);
|
||||
for(size_t i = 0, n = uniform(gta->randomEngine); i != n; i++) {
|
||||
it++;
|
||||
}
|
||||
|
||||
auto vehicle = gta->createVehicle(it->first, plyPos, glm::quat(glm::vec3(0.f, 0.f, -plyLook.x * PiOver180)));
|
||||
playerCharacter->setCurrentVehicle(vehicle);
|
||||
}
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::U)) {
|
||||
auto ped = gta->createPedestrian(2, plyPos+glm::vec3(0.f,10.f,0.f));
|
||||
// Pick random vehicle.
|
||||
auto it = gta->vehicleTypes.begin();
|
||||
std::uniform_int_distribution<int> uniform(0, 9);
|
||||
for(size_t i = 0, n = uniform(gta->randomEngine); i != n; i++) {
|
||||
it++;
|
||||
}
|
||||
auto vehicle = gta->createVehicle(it->first, plyPos, glm::quat(glm::vec3(0.f, 0.f, -plyLook.x * PiOver180)));
|
||||
ped->setCurrentVehicle(vehicle);
|
||||
}
|
||||
|
||||
glm::mat4 view;
|
||||
view = glm::rotate(view, -90.f, glm::vec3(1, 0, 0));
|
||||
|
@ -112,7 +112,7 @@ void command(const std::string& line)
|
||||
|
||||
auto spawnpos = hit + normal;
|
||||
auto vehicle = gta->createVehicle(it->first, spawnpos, glm::quat(glm::vec3(0.f, 0.f, -plyLook.x * PiOver180)));
|
||||
playerCharacter->setCurrentVehicle(vehicle);
|
||||
playerCharacter->enterVehicle(vehicle, 0);
|
||||
}
|
||||
}
|
||||
else if("player" == cmd) {
|
||||
|
Loading…
Reference in New Issue
Block a user