Skip to content

Commit

Permalink
set rotations of copy objects too
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Sep 10, 2021
1 parent 634cecd commit 7edcf33
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 23 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ This is still in alpha stage. There might be a lot of bugs present. I'll add a r

## Projects used
1. [ImGui](https://github.com/ocornut/imgui)
2. [MinHook](https://github.com/TsudaKageyu/minhook)
3. [Plugin SDK](https://github.com/DK22Pac/plugin-sdk)
2. [Plugin SDK](https://github.com/DK22Pac/plugin-sdk)
1 change: 1 addition & 0 deletions src/filemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void FileMgr::ImportIPL(std::string fileName)
Utils::GetDegreeInRange(&rot.z);
data.SetRotation(rot);
data.SetQuat({rx, ry, rz, rw});
data.m_modelName = ObjManager::FindNameFromModel(pObj->m_nModelIndex);

// Setting quat messes with z coord?
Command<Commands::SET_OBJECT_COORDINATES>(hObj, pos.x, pos.y, pos.z);
Expand Down
1 change: 0 additions & 1 deletion src/filemgr.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#define RAD_TO_DEG(x) x*-57.2958f

class FileMgr
{
Expand Down
12 changes: 6 additions & 6 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void Interface::SearchContextMenu(std::string& root, std::string& key, std::stri

if (ImGui::MenuItem("Copy"))
{
Viewport::copiedModel = std::stoi(value);
Viewport::COPY_MODEL::m_nModel = std::stoi(value);
CHud::SetHelpMessage("Object Copied", false, false, false);
};
}
Expand Down Expand Up @@ -642,15 +642,15 @@ void Interface::DrawInfoMenu()
}
if (ImGui::SliderFloat("Rot X##Obj", &rot.x, 0.0f, 360.0f))
{
data.SetRotation(rot, true);
data.SetRotation(rot);
}
if (ImGui::SliderFloat("Rot Y##Obj", &rot.y, 0.0f, 360.0f))
{
data.SetRotation(rot, true);
data.SetRotation(rot);
}
if (ImGui::SliderFloat("Rot Z##Obj", &rot.z, 0.0f, 360.0f))
{
data.SetRotation(rot, true);
data.SetRotation(rot);
}
ImGui::Spacing();
}
Expand Down Expand Up @@ -936,7 +936,7 @@ void Interface::DrawInfoMenu()
ImGui::Spacing();
if (ImGui::Button("Copy render object", Utils::GetSize()))
{
Viewport::copiedModel = m_nBrowserSelectedModelId;
Viewport::COPY_MODEL::m_nModel = m_nBrowserSelectedModelId;
CHud::SetHelpMessage("Object Copied", false, false, false);
}
ImGui::Spacing();
Expand Down Expand Up @@ -1061,7 +1061,7 @@ void Interface::DrawInfoMenu()
{
if (ImGui::MenuItem("Copy"))
{
Viewport::copiedModel = std::stoi(value);
Viewport::COPY_MODEL::m_nModel = std::stoi(value);
CHud::SetHelpMessage("Object Copied", false, false, false);
}
if (ImGui::MenuItem("Remove"))
Expand Down
8 changes: 4 additions & 4 deletions src/objmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ void ObjManager::HighlightSelectedObj(CObject *pObj)
DrawColModel(*matrix, *pColModel);
}

void ObjManager::ExData::SetRotation(CVector rot, bool updateQuat)
void ObjManager::ExData::SetRotation(CVector rot)
{
m_vecRot = rot;
Command<Commands::SET_OBJECT_ROTATION>(handle, rot.x, rot.y, rot.z);

// CAREFUL ABOUT ITS USAGE
if (updateQuat)
if (!pObj->m_pRwObject)
{
Command<Commands::GET_OBJECT_QUATERNION>(handle, &m_fQuat.x, &m_fQuat.y, &m_fQuat.z, &m_fQuat.w);
pObj->CreateRwObject();
}
Command<Commands::GET_OBJECT_QUATERNION>(handle, &m_fQuat.x, &m_fQuat.y, &m_fQuat.z, &m_fQuat.w);
}

CVector ObjManager::ExData::GetRotation()
Expand Down
2 changes: 1 addition & 1 deletion src/objmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ObjManager
* Game crashes to get or set quats of far away objects
* So we're basically storing them here with custom functions
*/
void SetRotation(CVector rot, bool updateQuat = false);
void SetRotation(CVector rot);
CVector GetRotation();
QUAT GetQuat();
void SetQuat(QUAT quat);
Expand Down
1 change: 1 addition & 0 deletions src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define DISCORD_INVITE "https://discord.gg/ZzW7kmf"
#define GITHUB_LINK "https://github.com/user-grinch/Map-Editor"
#define HRESULT int
#define RAD_TO_DEG(x) x*-57.2958f

#include <d3d9.h>
#include <sstream>
Expand Down
31 changes: 23 additions & 8 deletions src/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,32 +478,47 @@ static void ContextMenu_Copy()
{
if (Viewport::m_HoveredEntity)
{
Viewport::copiedModel = Viewport::m_HoveredEntity->m_nModelIndex;
Viewport::COPY_MODEL::m_nModel = Viewport::m_HoveredEntity->m_nModelIndex;

CVector &rot = Viewport::COPY_MODEL::m_vecRot;
// Store rotation
CallMethod<0x59A840, int>((int)Viewport::m_HoveredEntity->GetMatrix(),
&rot.x, &rot.y, &rot.z, 0); //void __thiscall CMatrix::ConvertToEulerAngles(CMatrix *this, float *pX, float *pY, float *pZ, unsigned int flags)

rot.x = RAD_TO_DEG(rot.x);
rot.y = RAD_TO_DEG(rot.y);
rot.z = RAD_TO_DEG(rot.z);

// 0 -> 360
Utils::GetDegreeInRange(&rot.x);
Utils::GetDegreeInRange(&rot.y);
Utils::GetDegreeInRange(&rot.z);
CHud::SetHelpMessage("Object Copied", false, false, false);
}
}

static void ContextMenu_Paste()
{
if (!Viewport::copiedModel)
if (!Viewport::COPY_MODEL::m_nModel)
{
return;
}

CEntity *pEntity;
CVector pos;
if (Command<Commands::IS_MODEL_AVAILABLE>(Viewport::copiedModel)
if (Command<Commands::IS_MODEL_AVAILABLE>(Viewport::COPY_MODEL::m_nModel)
&& Utils::TraceEntity(pEntity, pos))
{
int hObj;
Command<Commands::REQUEST_MODEL>(Viewport::copiedModel);
Command<Commands::REQUEST_MODEL>(Viewport::COPY_MODEL::m_nModel);
Command<Commands::LOAD_ALL_MODELS_NOW>();
Command<Commands::CREATE_OBJECT>(Viewport::copiedModel, pos.x, pos.y, pos.z, &hObj);
Command<Commands::MARK_MODEL_AS_NO_LONGER_NEEDED>(Viewport::copiedModel);
Command<Commands::CREATE_OBJECT>(Viewport::COPY_MODEL::m_nModel, pos.x, pos.y, pos.z, &hObj);
Command<Commands::MARK_MODEL_AS_NO_LONGER_NEEDED>(Viewport::COPY_MODEL::m_nModel);

CObject *pEntity = CPools::GetObject(hObj);
auto &data = ObjManager::m_objData.Get(pEntity);
data.m_modelName = ObjManager::FindNameFromModel(Viewport::copiedModel);
data.m_modelName = ObjManager::FindNameFromModel(Viewport::COPY_MODEL::m_nModel);
data.SetRotation(Viewport::COPY_MODEL::m_vecRot);

ObjManager::m_pVecEntities.push_back(pEntity);
ObjManager::m_pSelected = pEntity;
Expand Down Expand Up @@ -670,7 +685,7 @@ void Viewport::ProcessSelectedObjectInputs()
auto &data = ObjManager::m_objData.Get(ObjManager::m_pSelected);
CVector rot = data.GetRotation();
rot.z += 3*wheel;
data.SetRotation(rot, true);
data.SetRotation(rot);
}
else
{
Expand Down
6 changes: 5 additions & 1 deletion src/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ class Viewport
static inline float m_fFOV = 70.0f; // camera field of view
static inline CVector m_vecWorldPos;
static inline CEntity *m_HoveredEntity;
static inline int copiedModel = 0;
static inline CVector m_vecRenderRot;
static inline bool m_bObjBrowserAutoRot;
static inline ImVec2 m_fViewportSize;
struct COPY_MODEL
{
static inline int m_nModel;
static inline CVector m_vecRot;
};

Viewport() = delete;
Viewport(Viewport&) = delete;
Expand Down

0 comments on commit 7edcf33

Please sign in to comment.