Line data Source code
1 : /* Copyright (C) 2026 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #include "precompiled.h" 19 : 20 : // TODO: organise things better, rather than sticking them in Misc 21 : 22 : #include "graphics/Camera.h" 23 : #include "graphics/GameView.h" 24 : #include "lib/debug.h" 25 : #include "maths/Vector2D.h" 26 : #include "maths/Vector3D.h" 27 : #include "ps/Game.h" 28 : #include "tools/atlas/GameInterface/SharedTypes.h" 29 : 30 0 : CVector3D AtlasMessage::Position::GetWorldSpace(bool floating) const 31 : { 32 0 : switch (type) 33 : { 34 0 : case 0: 35 0 : return CVector3D(type0.x, type0.y, type0.z); 36 0 : break; 37 : 38 0 : case 1: 39 0 : return g_Game->GetView()->GetCamera().GetWorldCoordinates(type1.x, type1.y, floating); 40 0 : break; 41 : 42 0 : case 2: 43 0 : debug_warn(L"Invalid Position acquisition (unchanged without previous)"); 44 0 : return CVector3D(0.f, 0.f, 0.f); 45 0 : break; 46 : 47 0 : default: 48 0 : debug_warn(L"Invalid Position type"); 49 0 : return CVector3D(0.f, 0.f, 0.f); 50 : } 51 : } 52 : 53 0 : CVector3D AtlasMessage::Position::GetWorldSpace(float h, bool floating) const 54 : { 55 0 : switch (type) 56 : { 57 0 : case 1: 58 0 : return g_Game->GetView()->GetCamera().GetWorldCoordinates(type1.x, type1.y, h); 59 : 60 0 : default: 61 0 : return GetWorldSpace(floating); 62 : } 63 : } 64 : 65 0 : CVector3D AtlasMessage::Position::GetWorldSpace(const CVector3D& prev, bool floating) const 66 : { 67 0 : switch (type) 68 : { 69 0 : case 2: 70 0 : return prev; 71 : 72 0 : default: 73 0 : return GetWorldSpace(floating); 74 : } 75 : } 76 : 77 0 : void AtlasMessage::Position::GetScreenSpace(float& x, float& y) const 78 : { 79 0 : switch (type) 80 : { 81 0 : case 0: 82 0 : { 83 0 : const CVector2D screenPos{g_Game->GetView()->GetCamera().GetScreenCoordinates( 84 0 : CVector3D{type0.x, type0.y, type0.x})}; 85 0 : x = screenPos.X; 86 0 : y = screenPos.Y; 87 0 : break; 88 : } 89 0 : case 1: 90 0 : x = type1.x; 91 0 : y = type1.y; 92 0 : break; 93 : 94 0 : default: 95 0 : debug_warn(L"Invalid Position type"); 96 0 : x = y = 0.f; 97 : } 98 0 : }