From 898e67850637a8886901688dbb9fe97334f99c7f Mon Sep 17 00:00:00 2001 From: Unreal Karaulov Date: Sun, 10 Dec 2023 08:33:18 +0300 Subject: [PATCH] Tried to fix ANGLES in GOTO --- cfg/language.ini | 4 ++-- src/bsp/Bsp.cpp | 2 ++ src/editor/BspRenderer.cpp | 8 ++------ src/editor/Gui.cpp | 27 ++++++++++++++++++--------- src/editor/Renderer.cpp | 13 +++---------- src/util/vectors.cpp | 9 +++++++++ src/util/vectors.h | 2 ++ 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/cfg/language.ini b/cfg/language.ini index b6b866b9..f4d9bf72 100644 --- a/cfg/language.ini +++ b/cfg/language.ini @@ -365,7 +365,7 @@ LANG_0363 = Model {}: swap mins/maxs\n LANG_0364 = Fix texture data buffer overrun in {} texture. {} data size to {}.\n LANG_0365 = Found unnamed texture in face {}. Replaced by aaatrigger.\n LANG_0366 = Origin: {} {} {} -LANG_0367 = Angles: {} {} {} +LANG_0367 = GL Angles: {} {} {} LANG_0368 = Selected faces: {} LANG_0369 = PickMode: {} LANG_0370 = Name: {} @@ -679,7 +679,7 @@ LANG_0677 = Coordinates LANG_0678 = ##xpos LANG_0679 = ##ypos LANG_0680 = ##zpos -LANG_0681 = Angles +LANG_0681 = HL Angles LANG_0682 = ##xangles LANG_0683 = ##yangles LANG_0684 = ##zangles diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 558574f3..d71edd82 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -341,6 +341,8 @@ void Bsp::get_bounding_box(vec3& mins, vec3& maxs) void Bsp::get_model_vertex_bounds(int modelIdx, vec3& mins, vec3& maxs) { + if (modelIdx < 0) + return; mins = vec3(FLT_MAX_COORD, FLT_MAX_COORD, FLT_MAX_COORD); maxs = vec3(-FLT_MAX_COORD, -FLT_MAX_COORD, -FLT_MAX_COORD); diff --git a/src/editor/BspRenderer.cpp b/src/editor/BspRenderer.cpp index 481d68a3..4788e07a 100644 --- a/src/editor/BspRenderer.cpp +++ b/src/editor/BspRenderer.cpp @@ -33,7 +33,8 @@ BspRenderer::BspRenderer(Bsp* _map, PointEntRenderer* _pointEntRenderer) this->renderClipnodes = NULL; renderCameraOrigin = renderCameraAngles = vec3(); - + renderCameraAngles.flip(); + renderCameraAngles.z += 90.0f; // Setup Deafult Camera if (g_settings.start_at_entity) @@ -105,14 +106,9 @@ BspRenderer::BspRenderer(Bsp* _map, PointEntRenderer* _pointEntRenderer) } } - - renderCameraAngles = renderCameraAngles.flip(); - renderCameraAngles.z = renderCameraAngles.z + 90.0f; - renderCameraAngles = renderCameraAngles.normalize_angles(); - } diff --git a/src/editor/Gui.cpp b/src/editor/Gui.cpp index 856445f0..4cab6129 100644 --- a/src/editor/Gui.cpp +++ b/src/editor/Gui.cpp @@ -4645,6 +4645,11 @@ void Gui::drawGOTOWidget() entid = g_app->pickInfo.GetSelectedEnt(); coordinates = cameraOrigin; angles = cameraAngles; + angles.normalize_angles(); + angles.z -= 90.0f; + angles.y = angles.z; + angles.y = 0.0f; + angles.unflip(); showGOTOWidget_update = false; } ImGui::Text(get_localized_string(LANG_0677).c_str()); @@ -4657,13 +4662,11 @@ void Gui::drawGOTOWidget() ImGui::PopItemWidth(); ImGui::Text(get_localized_string(LANG_0681).c_str()); ImGui::PushItemWidth(inputWidth); - ImGui::DragFloat(get_localized_string(LANG_0683).c_str(), &angles.x, 0.1f, 0, 0, "X: %.0f"); + ImGui::DragFloat(get_localized_string(LANG_0683).c_str(), &angles.x, 0.1f, 0, 0, "PITCH: %.0f"); ImGui::SameLine(); - ImGui::BeginDisabled(); - ImGui::DragFloat(get_localized_string(LANG_0682).c_str(), &angles_y, 0.0f, 0, 0, "Z: %.0f"); - ImGui::EndDisabled(); + ImGui::DragFloat(get_localized_string(LANG_0682).c_str(), &angles.z, 0.1f, 0, 0, "YAW: %.0f"); ImGui::SameLine(); - ImGui::DragFloat(get_localized_string(LANG_0684).c_str(), &angles.z, 0.1f, 0, 0, "Y: %.0f"); + ImGui::DragFloat(get_localized_string(LANG_0684).c_str(), &angles.y, 0.1f, 0, 0, "ROLL: %.0f"); ImGui::PopItemWidth(); Bsp* map = app->getSelectedMap(); @@ -4673,11 +4676,17 @@ void Gui::drawGOTOWidget() if (ImGui::Button("Go to")) { cameraOrigin = coordinates; - cameraAngles = angles; - map->getBspRender()->renderCameraAngles = cameraAngles; map->getBspRender()->renderCameraOrigin = cameraOrigin; - //cameraAngles.z += 90.0f; - makeVectors(angles, app->cameraForward, app->cameraRight, app->cameraUp); + + + + cameraAngles = angles.flip(); + cameraAngles.z = cameraAngles.y + 90.0f; + cameraAngles.y = 0.0f; + cameraAngles = cameraAngles.normalize_angles(); + map->getBspRender()->renderCameraAngles = cameraAngles; + + makeVectors(cameraAngles, app->cameraForward, app->cameraRight, app->cameraUp); } ImGui::PopStyleColor(3); if (map && !map->is_mdl_model) diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index 6cc39b7e..c3b7f149 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -528,13 +528,12 @@ void Renderer::renderLoop() } + colorShader->bind(); if (SelectedMap) { if (debugClipnodes && modelIdx > 0) { - colorShader->bind(); matmodel.loadIdentity(); - colorShader->pushMatrix(MAT_MODEL); vec3 offset = (SelectedMap->getBspRender()->mapOffset + (entIdx > 0 ? SelectedMap->ents[entIdx]->getOrigin() : vec3())).flip(); matmodel.translate(offset.x, offset.y, offset.z); colorShader->updateMatrixes(); @@ -544,14 +543,11 @@ void Renderer::renderLoop() drawClipnodes(SelectedMap, pickModel.iHeadnodes[1], currentPlane, debugInt, pickModel.vOrigin); glEnable(GL_CULL_FACE); debugIntMax = currentPlane - 1; - colorShader->popMatrix(MAT_MODEL); } if (debugNodes && modelIdx > 0) { - colorShader->bind(); matmodel.loadIdentity(); - colorShader->pushMatrix(MAT_MODEL); vec3 offset = (SelectedMap->getBspRender()->mapOffset + (entIdx > 0 ? SelectedMap->ents[entIdx]->getOrigin() : vec3())).flip(); matmodel.translate(offset.x, offset.y, offset.z); colorShader->updateMatrixes(); @@ -561,14 +557,11 @@ void Renderer::renderLoop() drawNodes(SelectedMap, pickModel.iHeadnodes[0], currentPlane, debugNode, pickModel.vOrigin); glEnable(GL_CULL_FACE); debugNodeMax = currentPlane - 1; - colorShader->popMatrix(MAT_MODEL); } if (g_render_flags & RENDER_ORIGIN) { - colorShader->bind(); matmodel.loadIdentity(); - colorShader->pushMatrix(MAT_MODEL); vec3 offset = SelectedMap->getBspRender()->mapOffset.flip(); matmodel.translate(offset.x, offset.y, offset.z); colorShader->updateMatrixes(); @@ -581,7 +574,6 @@ void Renderer::renderLoop() p1 = debugPoint - vec3(0.0f, 0.0f, 32.0f); p2 = debugPoint + vec3(0.0f, 0.0f, 32.0f); drawLine(p1, p2, { 0, 0, 255, 255 }); - colorShader->popMatrix(MAT_MODEL); } } @@ -969,6 +961,7 @@ void Renderer::drawTransformAxes() { if (SelectedMap->ents[pickInfo.selectedEnts[0]]->getBspModelIdx() > 0) { + matmodel.loadIdentity(); glDepthMask(GL_FALSE); glDepthFunc(GL_ALWAYS); updateDragAxes(); @@ -986,6 +979,7 @@ void Renderer::drawTransformAxes() { if (transformTarget != TRANSFORM_VERTEX || (anyVertSelected || anyEdgeSelected)) { + matmodel.loadIdentity(); glDepthMask(GL_FALSE); glDepthFunc(GL_ALWAYS); updateDragAxes(); @@ -2322,7 +2316,6 @@ void Renderer::updateDragAxes(vec3 delta) { if (ent && ent->isBspModel()) { - map->get_model_vertex_bounds(ent->getBspModelIdx(), entMin, entMax); vec3 modelOrigin = entMin + (entMax - entMin) * 0.5f; diff --git a/src/util/vectors.cpp b/src/util/vectors.cpp index 4c2a32d3..4a25a0eb 100644 --- a/src/util/vectors.cpp +++ b/src/util/vectors.cpp @@ -264,6 +264,15 @@ vec3 vec3::flipUV() return vec3(x, -z, y); } +vec3 vec3::unflip() +{ + return vec3(x, -z, y); +} + +vec3 vec3::unflipUV() +{ + return vec3(x, z, -y); +} bool operator==(const vec2& v1, const vec2& v2) { diff --git a/src/util/vectors.h b/src/util/vectors.h index d3ab443e..3a03cccc 100644 --- a/src/util/vectors.h +++ b/src/util/vectors.h @@ -57,6 +57,8 @@ struct vec3 std::string toString(); vec3 flip(); // flip from opengl to Half-life coordinate system and vice versa vec3 flipUV(); // flip from opengl to Half-life coordinate system and vice versa + vec3 unflip(); + vec3 unflipUV(); void operator-=(const vec3& v); void operator+=(const vec3& v);