Commit 18c06434 authored by Martin Turski's avatar Martin Turski

fixed entity world rotation (? please verify)

parent 9e179144
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <Console.VariableHelpers.h> #include <Console.VariableHelpers.h>
#pragma warning(disable:4996) #pragma warning(disable : 4996)
namespace krt namespace krt
{ {
...@@ -517,6 +517,11 @@ struct sa_iplInstance_t ...@@ -517,6 +517,11 @@ struct sa_iplInstance_t
int lodIndex; // 36, index inside of the .ipl file pointing at the LOD instance. int lodIndex; // 36, index inside of the .ipl file pointing at the LOD instance.
}; };
inline rw::Quat gta_quat_to_rw(const rw::Quat& rotation)
{
return rw::Quat(rotation.w, -rotation.x, -rotation.y, -rotation.z);
}
struct inst_section_manager struct inst_section_manager
{ {
inline void RegisterGTA3Instance( inline void RegisterGTA3Instance(
...@@ -526,19 +531,21 @@ struct inst_section_manager ...@@ -526,19 +531,21 @@ struct inst_section_manager
rw::V3d scale, rw::V3d scale,
rw::Quat rotation) rw::Quat rotation)
{ {
streaming::ident_t universeModelIndex = g_currentParseUniverse->GetModelIndexMapping(modelID);
// I have no actual idea how things are made exactly, but lets just register it somehow. // I have no actual idea how things are made exactly, but lets just register it somehow.
ModelManager::ModelResource* modelInfo = theGame->GetModelManager().GetModelByID(g_currentParseUniverse->GetModelIndexMapping(modelID)); ModelManager::ModelResource* modelInfo = theGame->GetModelManager().GetModelByID(universeModelIndex);
if (!modelInfo) if (!modelInfo)
return; return;
Entity* resultEntity = new Entity(theGame); Entity* resultEntity = new Entity(theGame);
resultEntity->SetModelIndex(modelInfo->GetID()); resultEntity->SetModelIndex(universeModelIndex);
// Assign the matrix. // Assign the matrix.
{ {
rw::Matrix instMatrix = rw::Matrix::makeRotation( rotation ); rw::Matrix instMatrix = rw::Matrix::makeRotation(gta_quat_to_rw(rotation));
instMatrix.rightw = 0; instMatrix.rightw = 0;
instMatrix.atw = 0; instMatrix.atw = 0;
...@@ -551,7 +558,7 @@ struct inst_section_manager ...@@ -551,7 +558,7 @@ struct inst_section_manager
resultEntity->interiorId = areaCode; resultEntity->interiorId = areaCode;
resultEntity->isStaticWorldEntity = true; resultEntity->isStaticWorldEntity = true;
// Register this instance entity. // Register this instance entity.
// Note that we have no support for LOD instances here. // Note that we have no support for LOD instances here.
...@@ -564,7 +571,9 @@ struct inst_section_manager ...@@ -564,7 +571,9 @@ struct inst_section_manager
inline void RegisterBinarySAInstance(sa_iplInstance_t& instData) inline void RegisterBinarySAInstance(sa_iplInstance_t& instData)
{ {
ModelManager::ModelResource* modelInfo = theGame->GetModelManager().GetModelByID(g_currentParseUniverse->GetModelIndexMapping(instData.modelIndex)); streaming::ident_t universeModelIndex = g_currentParseUniverse->GetModelIndexMapping(instData.modelIndex);
ModelManager::ModelResource* modelInfo = theGame->GetModelManager().GetModelByID(universeModelIndex);
if (!modelInfo) if (!modelInfo)
return; return;
...@@ -578,14 +587,14 @@ struct inst_section_manager ...@@ -578,14 +587,14 @@ struct inst_section_manager
resultEntity = new Entity(theGame); resultEntity = new Entity(theGame);
resultEntity->SetModelIndex(instData.modelIndex); resultEntity->SetModelIndex(universeModelIndex);
// dont write z buffer flag? // dont write z buffer flag?
} }
// Convert the Quat to a matrix and assign it. // Convert the Quat to a matrix and assign it.
{ {
rw::Matrix instMatrix = rw::Matrix::makeRotation( instData.quatRotation ); rw::Matrix instMatrix = rw::Matrix::makeRotation(gta_quat_to_rw(instData.quatRotation));
instMatrix.rightw = 0; instMatrix.rightw = 0;
instMatrix.atw = 0; instMatrix.atw = 0;
...@@ -619,7 +628,7 @@ struct inst_section_manager ...@@ -619,7 +628,7 @@ struct inst_section_manager
resultEntity->interiorId = instData.areaIndex; resultEntity->interiorId = instData.areaIndex;
resultEntity->isStaticWorldEntity = true; resultEntity->isStaticWorldEntity = true;
// Register this instance entity. // Register this instance entity.
lod_inst_entity inst_info; lod_inst_entity inst_info;
...@@ -657,31 +666,35 @@ struct inst_section_manager ...@@ -657,31 +666,35 @@ struct inst_section_manager
baseEntity->LinkToWorld(theGame->GetWorld()); baseEntity->LinkToWorld(theGame->GetWorld());
} }
// If certain entities have LOD "models" and their entities do not have lod LODs already. // Only do this if we are running gtasa.
// Then automatically create lower LODs for them. if (g_currentParseUniverse->GetConfiguration().gameName == "gtasa")
for (const lod_inst_entity& inst : this->instances)
{ {
Entity* entity = inst.entity; // If certain entities have LOD "models" and their entities do not have lod LODs already.
// Then automatically create lower LODs for them.
if (entity->GetLODEntity() == NULL) for (const lod_inst_entity& inst : this->instances)
{ {
ModelManager::ModelResource* modelEntry = entity->GetModelInfo(); Entity* entity = inst.entity;
if (modelEntry) if (entity->GetLODEntity() == NULL)
{ {
ModelManager::ModelResource* lodModel = modelEntry->GetLODModel(); ModelManager::ModelResource* modelEntry = entity->GetModelInfo();
if (lodModel) if (modelEntry)
{ {
// Actually create an automatic LOD instance placed at the exact same position. ModelManager::ModelResource* lodModel = modelEntry->GetLODModel();
Entity* lodInst = new Entity(entity->GetGame());
if (lodModel)
{
// Actually create an automatic LOD instance placed at the exact same position.
Entity* lodInst = new Entity(entity->GetGame());
lodInst->SetModelIndex(lodModel->GetID()); lodInst->SetModelIndex(lodModel->GetID());
lodInst->SetModelling(entity->GetModelling()); lodInst->SetModelling(entity->GetModelling());
entity->SetLODEntity(lodInst); entity->SetLODEntity(lodInst);
lodInst->LinkToWorld(theGame->GetWorld()); lodInst->LinkToWorld(theGame->GetWorld());
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment