Merge pull request #1146 from colobot/dev-scene-camera

Implement viewpoint feature
1008-fix
krzys_h 2018-05-07 20:42:18 +02:00 committed by GitHub
commit b9e2edce6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 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_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)

View File

@ -594,6 +594,17 @@ enum EventType
EVENT_CODE_BATTLE_START = 2200, //!< button that starts the code battle
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
EVENT_STD_MAX,

View File

@ -458,6 +458,8 @@ void CRobotMain::ChangePhase(Phase phase)
m_movie->Flush();
m_movieInfoIndex = -1;
m_shortCut = true;
m_viewpoints.clear();
}
ClearInterface();
@ -746,6 +748,13 @@ bool CRobotMain::ProcessEvent(Event &event)
SetCodeBattleSpectatorMode(!m_codeBattleSpectator);
}
if (event.type >= EVENT_VIEWPOINT0 && event.type <= EVENT_VIEWPOINT9)
{
m_camera->SetType(Gfx::CAM_TYPE_SCRIPT);
m_camera->SetSmooth(Gfx::CAM_SMOOTH_HARD);
m_camera->SetScriptCameraAnimate(m_viewpoints[event.type - EVENT_VIEWPOINT0].eye, m_viewpoints[event.type - EVENT_VIEWPOINT0].look);
}
// Management of the console.
if (event.type == EVENT_KEY_DOWN)
{
@ -3530,6 +3539,24 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
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)
{
auto endTake = MakeUnique<CSceneEndCondition>();
@ -5824,25 +5851,40 @@ void CRobotMain::CreateCodeBattleInterface()
if (m_phase == PHASE_SIMUL)
{
Math::Point pos, ddim;
float offset = (ceil(m_viewpoints.size() / 2.0f) * 50);
int numTeams = m_scoreboard ? GetAllTeams().size() : 0;
assert(numTeams < EVENT_SCOREBOARD_MAX-EVENT_SCOREBOARD+1);
float textHeight = m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL);
//window
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.y = 100.0f/480.0f;
Ui::CWindow* pw = m_interface->CreateWindows(pos, ddim, 3, EVENT_WINDOW6);
//label text
ddim.x = 100.0f/640.0f;
ddim.y = 16.0f/480.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;
GetResource(RES_EVENT, 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 = (130.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
ddim.x = 80.0f/640.0f;
ddim.y = ((1-titleBarSize)*100.0f-20.0f)/480.0f;
@ -5953,6 +5995,7 @@ void CRobotMain::UpdateCodeBattleInterface()
void CRobotMain::DestroyCodeBattleInterface()
{
m_viewpoints.clear();
m_interface->DeleteControl(EVENT_WINDOW6);
}

View File

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