Added viewpoints feature

This allows you to set fixed viewpoints in specific location, without attaching to any object, enabling you to track the game from any location.
Proper camera handling will be implemented in next commits.
1008-fix
tomangelo2 2018-04-11 21:24:20 +02:00
parent adda82819c
commit b04d8d205b
4 changed files with 73 additions and 2 deletions

View File

@ -522,6 +522,17 @@ void InitializeEventTypeTexts()
EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_START] = "EVENT_CODE_BATTLE_START"; EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_START] = "EVENT_CODE_BATTLE_START";
EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_SPECTATOR] = "EVENT_CODE_BATTLE_SPECTATOR"; EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_SPECTATOR] = "EVENT_CODE_BATTLE_SPECTATOR";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT0] = "EVENT_VIEWPOINT0";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT1] = "EVENT_VIEWPOINT1";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT2] = "EVENT_VIEWPOINT2";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT3] = "EVENT_VIEWPOINT3";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT4] = "EVENT_VIEWPOINT4";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT5] = "EVENT_VIEWPOINT5";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT6] = "EVENT_VIEWPOINT6";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT7] = "EVENT_VIEWPOINT7";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT8] = "EVENT_VIEWPOINT8";
EVENT_TYPE_TEXT[EVENT_VIEWPOINT9] = "EVENT_VIEWPOINT9";
} }
std::string ParseEventType(EventType eventType) std::string ParseEventType(EventType eventType)

View File

@ -594,6 +594,17 @@ enum EventType
EVENT_CODE_BATTLE_START = 2200, //!< button that starts the code battle EVENT_CODE_BATTLE_START = 2200, //!< button that starts the code battle
EVENT_CODE_BATTLE_SPECTATOR = 2201, //!< button that controls the code battle spectator camera EVENT_CODE_BATTLE_SPECTATOR = 2201, //!< button that controls the code battle spectator camera
//! Buttons that switch viewpoints
EVENT_VIEWPOINT0 = 3000,
EVENT_VIEWPOINT1 = 3001,
EVENT_VIEWPOINT2 = 3002,
EVENT_VIEWPOINT3 = 3003,
EVENT_VIEWPOINT4 = 3004,
EVENT_VIEWPOINT5 = 3005,
EVENT_VIEWPOINT6 = 3006,
EVENT_VIEWPOINT7 = 3007,
EVENT_VIEWPOINT8 = 3008,
EVENT_VIEWPOINT9 = 3009,
//! Maximum value of standard events //! Maximum value of standard events
EVENT_STD_MAX, EVENT_STD_MAX,

View File

@ -456,6 +456,8 @@ void CRobotMain::ChangePhase(Phase phase)
m_movie->Flush(); m_movie->Flush();
m_movieInfoIndex = -1; m_movieInfoIndex = -1;
m_shortCut = true; m_shortCut = true;
m_viewpoints.clear();
} }
ClearInterface(); ClearInterface();
@ -744,6 +746,11 @@ bool CRobotMain::ProcessEvent(Event &event)
SetCodeBattleSpectatorMode(!m_codeBattleSpectator); SetCodeBattleSpectatorMode(!m_codeBattleSpectator);
} }
if (event.type >= EVENT_VIEWPOINT0 && event.type <= EVENT_VIEWPOINT9)
{
m_camera->SetScriptCamera(m_viewpoints[event.type - EVENT_VIEWPOINT0].eye, m_viewpoints[event.type - EVENT_VIEWPOINT0].look);
}
// Management of the console. // Management of the console.
if (event.type == EVENT_KEY_DOWN) if (event.type == EVENT_KEY_DOWN)
{ {
@ -3528,6 +3535,24 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
continue; continue;
} }
//! Note: This feature may be changed in next releases,
//! Places new viewpoint, which can be selected later in (currently only in Code Battle) UI.
//! Usage: View eye=x; y; z lookat=x; y; z
if (line->GetCommand() == "View")
{
if(m_viewpoints.size() == 10)
{
GetLogger()->Warn("Reached limit of 10 viewpoints, next ones will be ommited.\n");
continue;
}
Viewpoint tmp;
tmp.eye = line->GetParam("eye")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit;
tmp.look = line->GetParam("lookat")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit;
m_viewpoints.push_back(tmp);
continue;
}
if (line->GetCommand() == "EndMissionTake" && !resetObject) if (line->GetCommand() == "EndMissionTake" && !resetObject)
{ {
auto endTake = MakeUnique<CSceneEndCondition>(); auto endTake = MakeUnique<CSceneEndCondition>();
@ -5814,25 +5839,40 @@ void CRobotMain::CreateCodeBattleInterface()
if (m_phase == PHASE_SIMUL) if (m_phase == PHASE_SIMUL)
{ {
Math::Point pos, ddim; Math::Point pos, ddim;
float offset = (ceil(m_viewpoints.size() / 2.0f) * 50);
int numTeams = m_scoreboard ? GetAllTeams().size() : 0; int numTeams = m_scoreboard ? GetAllTeams().size() : 0;
assert(numTeams < EVENT_SCOREBOARD_MAX-EVENT_SCOREBOARD+1); assert(numTeams < EVENT_SCOREBOARD_MAX-EVENT_SCOREBOARD+1);
float textHeight = m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL); float textHeight = m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL);
//window
ddim.x = 100.0f/640.0f; ddim.x = 100.0f/640.0f;
ddim.y = 100.0f/480.0f + numTeams * textHeight; ddim.y = (100.0f+offset)/480.0f + numTeams * textHeight;
pos.x = 540.0f/640.0f; pos.x = 540.0f/640.0f;
pos.y = 100.0f/480.0f; pos.y = 100.0f/480.0f;
Ui::CWindow* pw = m_interface->CreateWindows(pos, ddim, 3, EVENT_WINDOW6); Ui::CWindow* pw = m_interface->CreateWindows(pos, ddim, 3, EVENT_WINDOW6);
//label text
ddim.x = 100.0f/640.0f; ddim.x = 100.0f/640.0f;
ddim.y = 16.0f/480.0f; ddim.y = 16.0f/480.0f;
pos.x = 540.0f/640.0f; pos.x = 540.0f/640.0f;
pos.y = 178.0f/480.0f + numTeams * textHeight; pos.y = (178.0f+offset)/480.0f + numTeams * textHeight;
std::string text; std::string text;
GetResource(RES_EVENT, EVENT_LABEL_CODE_BATTLE, text); GetResource(RES_EVENT, EVENT_LABEL_CODE_BATTLE, text);
pw->CreateLabel(pos, ddim, 0, EVENT_LABEL_CODE_BATTLE, text); pw->CreateLabel(pos, ddim, 0, EVENT_LABEL_CODE_BATTLE, text);
//viewpoint selection section
ddim.x = 40.0f/640.0f;
ddim.y = 50.0f/640.0f;
for(unsigned int i = 0; i<m_viewpoints.size(); i++)
{
//create button
pos.x = (550.0f+40.0f*(i%2))/640.0f;
pos.y = (120.0f+offset)/480.0f + numTeams * textHeight - 45.0f*(i/2)/480.0f;
pw->CreateButton(pos,ddim, 13, EventType(EVENT_VIEWPOINT0 + i));
}
//start/camera button
float titleBarSize = (11.0f/64.0f); // this is from the texture float titleBarSize = (11.0f/64.0f); // this is from the texture
ddim.x = 80.0f/640.0f; ddim.x = 80.0f/640.0f;
ddim.y = ((1-titleBarSize)*100.0f-20.0f)/480.0f; ddim.y = ((1-titleBarSize)*100.0f-20.0f)/480.0f;
@ -5930,6 +5970,7 @@ void CRobotMain::UpdateCodeBattleInterface()
void CRobotMain::DestroyCodeBattleInterface() void CRobotMain::DestroyCodeBattleInterface()
{ {
m_viewpoints.clear();
m_interface->DeleteControl(EVENT_WINDOW6); m_interface->DeleteControl(EVENT_WINDOW6);
} }

View File

@ -150,6 +150,11 @@ struct MinMax
int max = -1; int max = -1;
}; };
struct Viewpoint
{
Math::Vector eye;
Math::Vector look;
};
const int SATCOM_HUSTON = 0; const int SATCOM_HUSTON = 0;
const int SATCOM_SAT = 1; const int SATCOM_SAT = 1;
@ -717,4 +722,7 @@ protected:
std::deque<std::string> m_commandHistory; std::deque<std::string> m_commandHistory;
//! Index of currently selected element in command history //! Index of currently selected element in command history
int m_commandHistoryIndex; int m_commandHistoryIndex;
//! Vector of available viewpoints
std::vector<Viewpoint> m_viewpoints;
}; };