diff options
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/src/game.cpp b/src/game.cpp index e1accc9..f0fac6c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -130,35 +130,34 @@ void SerializeInstance(std::ofstream &stream, const CompInstance &comp) { assert(et != nullptr); CompInstance c{}; InstPos baseInst{}; - baseInst.pos = glm::vec3(0, 0, 0); - baseInst.rot = glm::quat(1, 0, 0, 0); - baseInst.scale = glm::vec3(1, 1, 1); + baseInst.posRot = btTransform{}; + baseInst.posRot.setIdentity(); + baseInst.scale = btVector3(1, 1, 1); if (comp.entHandle != c.entHandle) stream << PKE_FILE_INSTANCE_ENTITY_HANDLE << handleStr << std::endl; stream << PKE_FILE_INSTANCE_ENTITY_TYPE_CODE << et->entityTypeCode << std::endl; btTransform trans; comp.bt.defaultMotionState.getWorldTransform(trans); - InstPos inst; - BulletToGlm(trans.getOrigin(), inst.pos); - BulletToGlm(trans.getRotation(), inst.rot); - BulletToGlm(comp.bt.collisionShape->getLocalScaling(), inst.scale); - if (inst.pos != baseInst.pos) + btVector3 scale = comp.bt.collisionShape->getLocalScaling(); + if (trans != baseInst.posRot) { + btVector3 pos = trans.getOrigin(); + btQuaternion rot = trans.getRotation(); stream << PKE_FILE_INSTANCE_POS_POS << "[" - << std::setw(10) << inst.pos[0] << "," - << std::setw(10) << inst.pos[1] << "," - << std::setw(10) << inst.pos[2] << "]" << std::endl; - if (inst.rot != baseInst.rot) - stream << PKE_FILE_INSTANCE_POS_ROT << "[" - << std::setw(10) << inst.rot[0] << "," - << std::setw(10) << inst.rot[1] << "," - << std::setw(10) << inst.rot[2] << "," - << std::setw(10) << inst.rot[3] << "]" << std::endl; - if (inst.scale != baseInst.scale) + << std::setw(10) << pos[0] << "," + << std::setw(10) << pos[1] << "," + << std::setw(10) << pos[2] << "]" << std::endl + << PKE_FILE_INSTANCE_POS_ROT << "[" + << std::setw(10) << rot[0] << "," + << std::setw(10) << rot[1] << "," + << std::setw(10) << rot[2] << "," + << std::setw(10) << rot[3] << "]" << std::endl; + } + if (scale != baseInst.scale) stream << PKE_FILE_INSTANCE_POS_SCALE << "[" - << std::setw(10) << inst.scale[0] << "," - << std::setw(10) << inst.scale[1] << "," - << std::setw(10) << inst.scale[2] << "]" << std::endl; + << std::setw(10) << scale[0] << "," + << std::setw(10) << scale[1] << "," + << std::setw(10) << scale[2] << "]" << std::endl; } void ParseEntityType(std::ifstream &stream) { @@ -245,9 +244,9 @@ void ParseEntityType(std::ifstream &stream) { void ParseInstance(std::ifstream &stream) { CompInstance comp{}; InstPos instPos{}; - instPos.pos = glm::vec3(0, 0, 0); - instPos.rot = glm::quat(1, 0, 0, 0); - instPos.scale = glm::vec3(1, 1, 1); + instPos.posRot = btTransform{}; + instPos.posRot.setIdentity(); + instPos.scale = btVector3(1, 1, 1); char entTypeCode[21]; memset(reinterpret_cast<void *>(entTypeCode), '\0', 21); while (stream.getline(readLine, readLineLength)) { @@ -286,13 +285,15 @@ void ParseInstance(std::ifstream &stream) { assert(startingChar != nullptr); char *pEnd = nullptr; long index = 0; + btVector3 pos; do { assert(index < 3); - STR2NUM_ERROR result = str2num(instPos.pos[index], startingChar, pEnd); + STR2NUM_ERROR result = str2num(pos[index], startingChar, pEnd); assert(result == STR2NUM_ERROR::SUCCESS); startingChar = pEnd + 1; ++index; } while (*pEnd != ']'); + instPos.posRot.setOrigin(pos); continue; } if (strstr(readLine, PKE_FILE_INSTANCE_POS_ROT)) { @@ -301,13 +302,15 @@ void ParseInstance(std::ifstream &stream) { assert(startingChar != nullptr); char *pEnd = nullptr; long index = 0; + btQuaternion rot; do { assert(index < 4); - STR2NUM_ERROR result = str2num(instPos.rot[index], startingChar, pEnd); + STR2NUM_ERROR result = str2num(rot[index], startingChar, pEnd); assert(result == STR2NUM_ERROR::SUCCESS); startingChar = pEnd + 1; ++index; } while (*pEnd != ']'); + instPos.posRot.setRotation(rot); continue; } if (strstr(readLine, PKE_FILE_INSTANCE_POS_SCALE)) { @@ -437,9 +440,9 @@ void Game_Tick(double delta) { auto createInfo = entityInstancesToCreate.Pop(); EntityHandle newEntity = ECS_CreateEntity(); InstPos instPos; - instPos.pos = glm::vec3(0, 0, 0); - instPos.rot = glm::quat(1, 0, 0, 0); - instPos.scale = glm::vec3(1); + instPos.posRot = btTransform{}; + instPos.posRot.setIdentity(); + instPos.scale = btVector3(1, 1, 1); ECS_CreateInstance(newEntity, createInfo.entityTypeEntityHandle, instPos); } @@ -830,19 +833,21 @@ void RecordImGui_CompInstPos(bool readonly, CompInstance *component) { ImGui::Separator(); bool changed = false; - btTransform trans; - component->bt.defaultMotionState.getWorldTransform(trans); InstPos instPos; - BulletToGlm(trans.getOrigin(), instPos.pos); - BulletToGlm(trans.getRotation(), instPos.rot); - BulletToGlm(component->bt.collisionShape->getLocalScaling(), instPos.scale); + component->bt.defaultMotionState.getWorldTransform(instPos.posRot); + instPos.scale = component->bt.collisionShape->getLocalScaling(); + + btVector3 pos = instPos.posRot.getOrigin(); + btQuaternion rot = instPos.posRot.getRotation(); changed = ImGui::InputScalar("Instance Index", ImGuiDataType_U64, &component->index, nullptr, nullptr, nullptr, ImGuiInputTextFlags_ReadOnly) || changed; - changed = ImGui::InputScalarN("pos", ImGuiDataType_Float, &instPos.pos, 3, nullptr, nullptr, nullptr, inputTextFlags) || changed; - changed = ImGui::InputScalarN("rot", ImGuiDataType_Float, &instPos.rot, 4, nullptr, nullptr, nullptr, inputTextFlags) || changed; + changed = ImGui::InputScalarN("pos", ImGuiDataType_Float, &pos, 3, nullptr, nullptr, nullptr, inputTextFlags) || changed; + changed = ImGui::InputScalarN("rot", ImGuiDataType_Float, &rot, 4, nullptr, nullptr, nullptr, inputTextFlags) || changed; changed = ImGui::InputScalarN("scale", ImGuiDataType_Float, &instPos.scale, 3, nullptr, nullptr, nullptr, inputTextFlags) || changed; if (changed) { + instPos.posRot.setOrigin(pos); + instPos.posRot.setRotation(rot); ECS_UpdateInstance(component->entHandle, instPos, true); } |
