1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-18 16:32:32 +02:00

Refactored Instance data

This commit is contained in:
Daniel Evans 2013-12-05 07:23:07 +00:00
parent 0b046947da
commit 84c94c5c24
7 changed files with 48 additions and 63 deletions

View File

@ -0,0 +1,32 @@
#pragma once
#ifndef __INSTANCEDATA_HPP__
#define __INSTANCEDATA_HPP__
#include <string>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
struct InstanceData
{
/**
* ID of the object this instance
*/
int id;
/**
* Model name
*/
std::string model;
/**
* Instance position
*/
glm::vec3 pos;
/**
* Instance scaleX
*/
glm::vec3 scale;
/**
* Instance rotation
*/
glm::quat rot;
};
#endif

View File

@ -98,12 +98,6 @@ public:
*/
GTACharacter* createPedestrian(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat());
/**
* Roughly the middle of everything
*/
glm::vec3 itemCentroid;
size_t itemCount;
/**
* Game Clock
*/

View File

@ -1,23 +1,10 @@
#ifndef _LOADERIPL_HPP_
#define _LOADERIPL_HPP_
#include <renderwure/data/InstanceData.hpp>
#include <iostream>
#include <vector>
#include <glm/glm.hpp>
/**
\class LoaderIPLInstance
\brief One INST entry's data from a IPL file
*/
class LoaderIPLInstance
{
public:
int id; ///< ID of the asset in the main IMG archive
std::string model; ///< Name of the model for this instance, as seen in the IMG archive
float posX, posY, posZ; ///< 3D Position of the instance
float scaleX, scaleY, scaleZ; ///< Scale of the instance
float rotX, rotY, rotZ, rotW; ///< Rotation of the instance, in a Quaternion
};
#include <memory>
/**
\class LoaderIPL
@ -66,10 +53,7 @@ public:
bool load(const std::string& filename);
/// The list of instances from the IPL file
std::vector<LoaderIPLInstance> m_instances;
/// The centroid of the instances
glm::vec3 centroid;
std::vector<std::shared_ptr<InstanceData>> m_instances;
/// List of Zones
std::vector<Zone> zones;

View File

@ -11,7 +11,7 @@
#include <renderwure/objects/GTAVehicle.hpp>
GTAEngine::GTAEngine(const std::string& path)
: itemCount(0), gameTime(0.f), gameData(path), renderer(this), randomEngine(rand())
: gameTime(0.f), gameData(path), renderer(this), randomEngine(rand())
{
gameData.engine = this;
}
@ -123,17 +123,13 @@ bool GTAEngine::placeItems(const std::string& name)
{
// Find the object.
for( size_t i = 0; i < ipll.m_instances.size(); ++i) {
LoaderIPLInstance& inst = ipll.m_instances[i];
glm::quat rot(-inst.rotW, inst.rotX, inst.rotY, inst.rotZ);
rot = glm::normalize(rot);
if(! createInstance(inst.id, glm::vec3(inst.posX, inst.posY, inst.posZ), rot)) {
std::cerr << "No object for instance " << inst.id << " (" << path << ")" << std::endl;
std::shared_ptr<InstanceData> inst = ipll.m_instances[i];
if(! createInstance(inst->id, inst->pos, inst->rot)) {
std::cerr << "No object for instance " << inst->id << " (" << path << ")" << std::endl;
}
}
itemCentroid += ipll.centroid;
itemCount += ipll.m_instances.size();
// Associate LODs.
// Attempt to Associate LODs.
for( size_t i = 0; i < objectInstances.size(); ++i ) {
if( !objectInstances[i]->object->LOD ) {
auto lodInstit = modelInstances.find("LOD" + objectInstances[i]->object->modelName.substr(3));

View File

@ -60,8 +60,6 @@ bool LoaderIPL::load(const std::string& filename)
{
if(section == INST)
{
LoaderIPLInstance instance;
std::string id;
std::string model;
std::string posX, posY, posZ;
@ -83,30 +81,15 @@ bool LoaderIPL::load(const std::string& filename)
getline(strstream, rotY, ',');
getline(strstream, rotZ, ',');
getline(strstream, rotW, ',');
// convert to our structure
instance.id = atoi(id.c_str());
instance.model = model.substr(1, model.size()-1);
instance.posX = atof(posX.c_str());
instance.posY = atof(posY.c_str());
instance.posZ = atof(posZ.c_str());
instance.scaleX = atof(scaleX.c_str());
instance.scaleY = atof(scaleY.c_str());
instance.scaleZ = atof(scaleZ.c_str());
instance.rotX = atof(rotX.c_str());
instance.rotY = atof(rotY.c_str());
instance.rotZ = atof(rotZ.c_str());
instance.rotW = atof(rotW.c_str());
centroid += glm::vec3(instance.posX, instance.posY, instance.posZ);
/*std::cout << "id: " << instance.id << std::endl;
std::cout << "model: " << instance.model << std::endl;
std::cout << "posX: " << instance.posX << std::endl;
std::cout << "posY: " << instance.posY << std::endl;
std::cout << "posZ: " << instance.posZ << std::endl;
std::cout << "rotW: " << instance.rotW << std::endl;*/
std::shared_ptr<InstanceData> instance(new InstanceData{
atoi(id.c_str()), // ID
model.substr(1, model.size()-1),
glm::vec3(atof(posX.c_str()), atof(posY.c_str()), atof(posZ.c_str())),
glm::vec3(atof(scaleX.c_str()), atof(scaleY.c_str()), atof(scaleZ.c_str())),
glm::normalize(glm::quat(-atof(rotW.c_str()), atof(rotX.c_str()), atof(rotY.c_str()), atof(rotZ.c_str())))
});
m_instances.push_back(instance);
}
else if(section == ZONE)

View File

@ -97,8 +97,6 @@ void init(std::string gtapath)
gta->placeItems(gtapath + "/data/maps/industse/industSE.ipl");
gta->placeItems(gtapath + "/data/maps/industne/industNE.ipl");*/
plyPos = gta->itemCentroid / (float) gta->itemCount + glm::vec3(0, 0, 2);
glm::vec3 spawnPos = plyPos + glm::vec3(-5, -20, 0.0);
size_t k = 1;
// Spawn every vehicle, cause why not.

View File

@ -258,8 +258,6 @@ void init(std::string gtapath, bool loadWorld)
gta->loadZone(it->second);
gta->placeItems(it->second);
}
plyPos = gta->itemCentroid / (float) gta->itemCount + glm::vec3(0, 0, 2);
}
glm::vec3 spawnPos = plyPos + glm::vec3(-5, -20, 0.0);