[Add] Save view state.

[Change] Reoraganize a bunch of Camera stuff.
This commit is contained in:
Allanis 2018-02-08 21:17:06 +00:00
parent 130c328d2e
commit 5663867e6b
13 changed files with 123 additions and 69 deletions

View File

@ -17,12 +17,14 @@ void DynamicBody::Save(void) {
using namespace Serializer::Write; using namespace Serializer::Write;
ModelBody::Save(); ModelBody::Save();
wr_vector3d(GetAngVelocity()); wr_vector3d(GetAngVelocity());
wr_vector3d(GetVelocity());
} }
void DynamicBody::Load(void) { void DynamicBody::Load(void) {
using namespace Serializer::Read; using namespace Serializer::Read;
ModelBody::Load(); ModelBody::Load();
SetAngVelocity(rd_vector3d()); SetAngVelocity(rd_vector3d());
SetVelocity(rd_vector3d());
} }
void DynamicBody::Enable(void) { void DynamicBody::Enable(void) {

View File

@ -27,13 +27,15 @@ GenericSystemView::GenericSystemView(void) : View() {
} }
void GenericSystemView::Draw3D(void) { void GenericSystemView::Draw3D(void) {
int playerLocSecX, playerLocSecY, playerLocSysIdx;
L3D::currentSystem->GetPos(&playerLocSecX, &playerLocSecY, &playerLocSysIdx);
StarSystem* s = L3D::GetSelectedSystem(); StarSystem* s = L3D::GetSelectedSystem();
if(s && !s->IsSystem(px, py, pidx)) { if(s && !s->IsSystem(px, py, pidx)) {
s->GetPos(&px, &py, &pidx); s->GetPos(&px, &py, &pidx);
Sector sec(px, py); Sector sec(px, py);
Sector psec(L3D::playerLocSecX, L3D::playerLocSecY); Sector psec(playerLocSecX, playerLocSecY);
const float dist = Sector::DistanceBetween(&sec,pidx, &psec, L3D::playerLocSysIdx); const float dist = Sector::DistanceBetween(&sec,pidx, &psec,playerLocSysIdx);
char buf[256]; char buf[256];
snprintf(buf, sizeof(buf), "Dist. %.2f light years.", dist); snprintf(buf, sizeof(buf), "Dist. %.2f light years.", dist);

View File

@ -67,20 +67,14 @@ public:
static MTRand rng; static MTRand rng;
static void HyperspaceTo(StarSystem* destination); static void HyperspaceTo(StarSystem* destination);
enum CamType { CAM_FRONT, CAM_REAR, CAM_EXTERNAL };
enum MapView { MAP_NOMAP, MAP_SECTOR, MAP_SYSTEM }; enum MapView { MAP_NOMAP, MAP_SECTOR, MAP_SYSTEM };
static void SetCamType(enum CamType);
static void SetMapView(enum MapView); static void SetMapView(enum MapView);
static enum CamType GetCamType(void) { return camType; }
static enum MapView GetMapView(void) { return mapView; } static enum MapView GetMapView(void) { return mapView; }
static void SetView(View* v); static void SetView(View* v);
static View* GetView(void) { return currentView; } static View* GetView(void) { return currentView; }
static StarSystem* GetSelectedSystem(void); static StarSystem* GetSelectedSystem(void);
static bool showDebugInfo; static bool showDebugInfo;
static int playerLocSecX;
static int playerLocSecY;
static int playerLocSysIdx;
static Player* player; static Player* player;
static SectorView* sectorView; static SectorView* sectorView;
static SystemInfoView* systemInfoView; static SystemInfoView* systemInfoView;
@ -101,7 +95,6 @@ private:
static double gameTime; static double gameTime;
static StarSystem* selectedSystem; static StarSystem* selectedSystem;
static enum CamType camType;
static enum MapView mapView; static enum MapView mapView;
static float timeAccel; static float timeAccel;
static float frameTime; static float frameTime;

View File

@ -32,7 +32,6 @@ sigc::signal<void, int, int, int> L3D::onMouseButtonDown;
char L3D::keyState[SDLK_LAST]; char L3D::keyState[SDLK_LAST];
char L3D::mouseButton[5]; char L3D::mouseButton[5];
int L3D::mouseMotion[2]; int L3D::mouseMotion[2];
enum L3D::CamType L3D::camType;
enum L3D::MapView L3D::mapView; enum L3D::MapView L3D::mapView;
Player* L3D::player; Player* L3D::player;
View* L3D::currentView; View* L3D::currentView;
@ -50,9 +49,6 @@ MTRand L3D::rng;
double L3D::gameTime; double L3D::gameTime;
float L3D::frameTime; float L3D::frameTime;
GLUquadric* L3D::gluQuadric; GLUquadric* L3D::gluQuadric;
int L3D::playerLocSecX;
int L3D::playerLocSecY;
int L3D::playerLocSysIdx;
bool L3D::showDebugInfo; bool L3D::showDebugInfo;
void L3D::Init(IniConfig& config) { void L3D::Init(IniConfig& config) {
@ -145,12 +141,6 @@ void L3D::SetTimeAccel(float s) {
timeAccel = s; timeAccel = s;
} }
void L3D::SetCamType(enum CamType c) {
camType = c;
mapView = MAP_NOMAP;
SetView(worldView);
}
void L3D::SetMapView(enum MapView v) { void L3D::SetMapView(enum MapView v) {
mapView = v; mapView = v;
if(v == MAP_SECTOR) if(v == MAP_SECTOR)
@ -446,7 +436,6 @@ void L3D::HyperspaceTo(StarSystem* dest) {
float ang = rng.Double(M_PI); float ang = rng.Double(M_PI);
L3D::player->SetPosition(vector3d(sin(ang)*AU, cos(ang)*AU,0)); L3D::player->SetPosition(vector3d(sin(ang)*AU, cos(ang)*AU,0));
L3D::player->SetVelocity(vector3d(0.0)); L3D::player->SetVelocity(vector3d(0.0));
dest->GetPos(&L3D::playerLocSecX, &L3D::playerLocSecY, &L3D::playerLocSysIdx);
} }
void L3D::Serialize(void) { void L3D::Serialize(void) {
@ -455,6 +444,8 @@ void L3D::Serialize(void) {
wr_double(gameTime); wr_double(gameTime);
StarSystem::Serialize(currentSystem); StarSystem::Serialize(currentSystem);
Space::Serialize(); Space::Serialize();
sectorView->Save();
worldView->Save();
} }
void L3D::Unserialize(void) { void L3D::Unserialize(void) {
@ -470,6 +461,8 @@ void L3D::Unserialize(void) {
L3D::player = 0; L3D::player = 0;
} }
Space::Unserialize(); Space::Unserialize();
sectorView->Load();
worldView->Load();
} }
IniConfig::IniConfig(const char* filename) { IniConfig::IniConfig(const char* filename) {

View File

@ -7,8 +7,6 @@
#include "space_station_view.h" #include "space_station_view.h"
Player::Player(ShipType::Type shipType) : Ship(shipType) { Player::Player(ShipType::Type shipType) : Ship(shipType) {
m_external_view_rotx = m_external_view_roty = 0;
m_external_view_dist = 200;
m_mouseCMov[0] = m_mouseCMov[1] = 0; m_mouseCMov[0] = m_mouseCMov[1] = 0;
m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS1); m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS1);
UpdateMass(); UpdateMass();
@ -20,7 +18,7 @@ Player::~Player(void) {
} }
void Player::Render(const Frame* camFrame) { void Player::Render(const Frame* camFrame) {
if(L3D::GetCamType() == L3D::CAM_EXTERNAL) { if(L3D::worldView->GetCamType() == WorldView::CAM_EXTERNAL) {
Ship::Render(camFrame); Ship::Render(camFrame);
} else { } else {
glPushMatrix(); glPushMatrix();
@ -37,22 +35,6 @@ void Player::SetDockedWith(SpaceStation* s, int port) {
} }
} }
vector3d Player::GetExternalViewTranslation(void) {
vector3d p = vector3d(0, 0, m_external_view_dist);
p = matrix4x4d::RotateXMatrix(-DEG2RAD(m_external_view_rotx)) * p;
p = matrix4x4d::RotateYMatrix(-DEG2RAD(m_external_view_roty)) * p;
matrix4x4d m;
GetRotMatrix(m);
p = m*p;
//printf("%f,%f,%f\n", p.x, p.y, p.z);
return p;
}
void Player::ApplyExternalViewRotation(matrix4x4d& m) {
m = matrix4x4d::RotateXMatrix(-DEG2RAD(m_external_view_rotx)) * m;
m = matrix4x4d::RotateYMatrix(-DEG2RAD(m_external_view_roty)) * m;
}
void Player::TimeStepUpdate(const float timeStep) { void Player::TimeStepUpdate(const float timeStep) {
if(GetFlightState() == Ship::FLYING) { if(GetFlightState() == Ship::FLYING) {
/* When world view not selected. */ /* When world view not selected. */
@ -82,18 +64,19 @@ void Player::PollControls(void) {
float ta2 = time_accel*time_accel; float ta2 = time_accel*time_accel;
polledControlsThisTurn = true; polledControlsThisTurn = true;
if(L3D::GetCamType() == L3D::CAM_EXTERNAL) { if(L3D::worldView->GetCamType() == WorldView::CAM_EXTERNAL) {
if(L3D::KeyState(SDLK_UP)) m_external_view_rotx -= 45*frameTime; if(L3D::KeyState(SDLK_UP)) L3D::worldView->m_externalViewRotX -= 45*frameTime;
if(L3D::KeyState(SDLK_DOWN)) m_external_view_rotx += 45*frameTime; if(L3D::KeyState(SDLK_DOWN)) L3D::worldView->m_externalViewRotX += 45*frameTime;
if(L3D::KeyState(SDLK_LEFT)) m_external_view_roty -= 45*frameTime; if(L3D::KeyState(SDLK_LEFT)) L3D::worldView->m_externalViewRotY -= 45*frameTime;
if(L3D::KeyState(SDLK_RIGHT)) m_external_view_roty += 45*frameTime; if(L3D::KeyState(SDLK_RIGHT)) L3D::worldView->m_externalViewRotY += 45*frameTime;
if(L3D::KeyState(SDLK_EQUALS)) m_external_view_dist -= 400*frameTime; if(L3D::KeyState(SDLK_EQUALS)) L3D::worldView->m_externalViewDist -= 400*frameTime;
if(L3D::KeyState(SDLK_MINUS)) m_external_view_dist += 400*frameTime; if(L3D::KeyState(SDLK_MINUS)) L3D::worldView->m_externalViewDist += 400*frameTime;
m_external_view_dist = MAX(50, m_external_view_dist); L3D::worldView->m_externalViewDist = MAX(50, L3D::worldView->m_externalViewDist);
/* When landed don't let external view look from below. */ /* When landed don't let external view look from below. */
if(GetFlightState() == LANDED) m_external_view_rotx = CLAMP(m_external_view_rotx, -170.0, -10); if(GetFlightState() == LANDED)
L3D::worldView->m_externalViewRotX = CLAMP(L3D::worldView->m_externalViewRotX, -170.0, -10);
} }
if((time_accel == 0) || GetDockedWith() || if((time_accel == 0) || GetDockedWith() ||
@ -127,7 +110,7 @@ void Player::PollControls(void) {
if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && L3D::MouseButtonState(1) && L3D::MouseButtonState(3))) SetGunState(0,1); if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && L3D::MouseButtonState(1) && L3D::MouseButtonState(3))) SetGunState(0,1);
else SetGunState(0,0); else SetGunState(0,0);
if(L3D::GetCamType() != L3D::CAM_EXTERNAL) { if(L3D::worldView->GetCamType() != WorldView::CAM_EXTERNAL) {
if(L3D::KeyState(SDLK_LEFT)) angThrust.y += 1; if(L3D::KeyState(SDLK_LEFT)) angThrust.y += 1;
if(L3D::KeyState(SDLK_RIGHT)) angThrust.y += -1; if(L3D::KeyState(SDLK_RIGHT)) angThrust.y += -1;
if(L3D::KeyState(SDLK_UP)) angThrust.x += -1; if(L3D::KeyState(SDLK_UP)) angThrust.x += -1;
@ -169,7 +152,7 @@ void Player::DrawHUD(const Frame* cam_frame) {
/* Object labels. */ /* Object labels. */
{ {
for(std::list<Body*>::iterator i = Space::bodies.begin(); i != Space::bodies.end(); ++i) { for(std::list<Body*>::iterator i = Space::bodies.begin(); i != Space::bodies.end(); ++i) {
if((L3D::GetCamType() != L3D::CAM_EXTERNAL) && (*i == this)) continue; if((L3D::worldView->GetCamType() != WorldView::CAM_EXTERNAL) && (*i == this)) continue;
Body* b = *i; Body* b = *i;
vector3d _pos = b->GetPositionRelTo(cam_frame); vector3d _pos = b->GetPositionRelTo(cam_frame);
if(_pos.z < 0 if(_pos.z < 0
@ -210,7 +193,7 @@ void Player::DrawHUD(const Frame* cam_frame) {
} }
/* Normal crosshairs. */ /* Normal crosshairs. */
if(L3D::GetCamType() == L3D::CAM_FRONT) { if(L3D::worldView->GetCamType() == WorldView::CAM_FRONT) {
float px = Gui::Screen::GetWidth()/2.0; float px = Gui::Screen::GetWidth()/2.0;
float py = Gui::Screen::GetHeight()/2.0; float py = Gui::Screen::GetHeight()/2.0;
glBegin(GL_LINES); glBegin(GL_LINES);

View File

@ -12,15 +12,11 @@ public:
virtual void Render(const Frame* camFrame); virtual void Render(const Frame* camFrame);
void DrawHUD(const Frame* cam_frame); void DrawHUD(const Frame* cam_frame);
virtual void SetDockedWith(SpaceStation*, int port); virtual void SetDockedWith(SpaceStation*, int port);
vector3d GetExternalViewTranslation(void);
void ApplyExternalViewRotation(matrix4x4d &m);
void TimeStepUpdate(const float timeStep); void TimeStepUpdate(const float timeStep);
private: private:
void DrawTargetSquares(); void DrawTargetSquares();
void DrawTargetSquare(const Body* const target); void DrawTargetSquare(const Body* const target);
float m_mouseCMov[2]; float m_mouseCMov[2];
float m_external_view_rotx, m_external_view_roty;
float m_external_view_dist;
bool polledControlsThisTurn; bool polledControlsThisTurn;
}; };

View File

@ -5,6 +5,7 @@
#include "sector.h" #include "sector.h"
#include "system_info_view.h" #include "system_info_view.h"
#include "player.h" #include "player.h"
#include "serializer.h"
SectorView::SectorView(void) : GenericSystemView() { SectorView::SectorView(void) : GenericSystemView() {
SetTransparency(true); SetTransparency(true);
@ -40,6 +41,30 @@ SectorView::~SectorView(void) {
glDeleteLists(m_gluDiskDlist, 1); glDeleteLists(m_gluDiskDlist, 1);
} }
void SectorView::Save(void) {
using namespace Serializer::Write;
wr_float(m_zoom);
wr_int(m_secx);
wr_int(m_secy);
wr_int(m_selected);
wr_float(m_px);
wr_float(m_py);
wr_float(m_rot_x);
wr_float(m_rot_z);
}
void SectorView::Load(void) {
using namespace Serializer::Read;
m_zoom = rd_float();
m_secx = rd_int();
m_secy = rd_int();
m_selected = rd_int();
m_px = rd_float();
m_py = rd_float();
m_rot_x = rd_float();
m_rot_z = rd_float();
}
void SectorView::OnClickSystemInfo(void) { void SectorView::OnClickSystemInfo(void) {
L3D::SetView(L3D::systemInfoView); L3D::SetView(L3D::systemInfoView);
} }
@ -109,6 +134,8 @@ void SectorView::PutText(std::string& text) {
} }
void SectorView::DrawSector(int sx, int sy) { void SectorView::DrawSector(int sx, int sy) {
int playerLocSecX, playerLocSecY, playerLocSysIdx;
L3D::currentSystem->GetPos(&playerLocSecX, &playerLocSecY, &playerLocSysIdx);
Sector s = Sector(sx, sy); Sector s = Sector(sx, sy);
glColor3f(0, .8, 0); glColor3f(0, .8, 0);
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
@ -135,7 +162,7 @@ void SectorView::DrawSector(int sx, int sy) {
glRotatef(-m_rot_x, 1, 0, 0); glRotatef(-m_rot_x, 1, 0, 0);
glCallList(m_gluDiskDlist); glCallList(m_gluDiskDlist);
/* Player location indicator. */ /* Player location indicator. */
if((sx == L3D::playerLocSecX) && (sy == L3D::playerLocSecY) && (num == L3D::playerLocSysIdx)) { if((sx == playerLocSecX) && (sy == playerLocSecY) && (num == playerLocSysIdx)) {
shipstats_t stats; shipstats_t stats;
L3D::player->CalcStats(&stats); L3D::player->CalcStats(&stats);
glColor3f(0, 0, 1); glColor3f(0, 0, 1);

View File

@ -14,6 +14,8 @@ public:
virtual void Update(void); virtual void Update(void);
virtual void Draw3D(void); virtual void Draw3D(void);
bool GetSelectedSystem(int* sector_x, int* sector_y, int* system_idx); bool GetSelectedSystem(int* sector_x, int* sector_y, int* system_idx);
virtual void Save(void);
virtual void Load(void);
private: private:
void DrawSector(int x, int y); void DrawSector(int x, int y);
void PutText(std::string& text); void PutText(std::string& text);

View File

@ -4,6 +4,7 @@
#include "space_station_view.h" #include "space_station_view.h"
#include "player.h" #include "player.h"
#include "info_view.h" #include "info_view.h"
#include "world_view.h"
ShipCpanel::ShipCpanel(void) : Gui::Fixed(640, 64) { ShipCpanel::ShipCpanel(void) : Gui::Fixed(640, 64) {
Gui::Screen::AddBaseWidget(this, 0, 0); Gui::Screen::AddBaseWidget(this, 0, 0);
@ -49,9 +50,9 @@ ShipCpanel::ShipCpanel(void) : Gui::Fixed(640, 64) {
Gui::MultiStateImageButton* cam_button = new Gui::MultiStateImageButton(); Gui::MultiStateImageButton* cam_button = new Gui::MultiStateImageButton();
g->Add(cam_button); g->Add(cam_button);
cam_button->SetSelected(true); cam_button->SetSelected(true);
cam_button->AddState(L3D::CAM_FRONT, "icons/cam_front.png"); cam_button->AddState(WorldView::CAM_FRONT, "icons/cam_front.png");
cam_button->AddState(L3D::CAM_REAR, "icons/cam_rear.png"); cam_button->AddState(WorldView::CAM_REAR, "icons/cam_rear.png");
cam_button->AddState(L3D::CAM_EXTERNAL, "icons/cam_external.png"); cam_button->AddState(WorldView::CAM_EXTERNAL, "icons/cam_external.png");
cam_button->SetShortcut(SDLK_F1, KMOD_NONE); cam_button->SetShortcut(SDLK_F1, KMOD_NONE);
cam_button->onClick.connect(sigc::mem_fun(this, &ShipCpanel::OnChangeCamView)); cam_button->onClick.connect(sigc::mem_fun(this, &ShipCpanel::OnChangeCamView));
Add(cam_button, 2, 2); Add(cam_button, 2, 2);
@ -73,9 +74,11 @@ ShipCpanel::ShipCpanel(void) : Gui::Fixed(640, 64) {
info_button->onClick.connect(sigc::mem_fun(this, &ShipCpanel::OnChangeInfoView)); info_button->onClick.connect(sigc::mem_fun(this, &ShipCpanel::OnChangeInfoView));
Add(info_button, 66, 2); Add(info_button, 66, 2);
Gui::ImageButton* comms_button = new Gui::ImageButton("icons/comms_f4.png"); Gui::MultiStateImageButton* comms_button = new Gui::MultiStateImageButton();
//g->Add(comms_button); g->Add(comms_button);
comms_button->SetSelected(false);
comms_button->SetShortcut(SDLK_F4, KMOD_NONE); comms_button->SetShortcut(SDLK_F4, KMOD_NONE);
comms_button->AddState(0, "icons/comms_f4.png");
comms_button->onClick.connect(sigc::mem_fun(this, &ShipCpanel::OnClickComms)); comms_button->onClick.connect(sigc::mem_fun(this, &ShipCpanel::OnClickComms));
Add(comms_button, 98, 2); Add(comms_button, 98, 2);
@ -118,7 +121,8 @@ void ShipCpanel::SetScannerWidget(Widget* w) {
} }
void ShipCpanel::OnChangeCamView(Gui::MultiStateImageButton* b) { void ShipCpanel::OnChangeCamView(Gui::MultiStateImageButton* b) {
L3D::SetCamType((enum L3D::CamType)b->GetState()); L3D::worldView->SetCamType((enum WorldView::CamType)b->GetState());
L3D::SetView(L3D::worldView);
} }
void ShipCpanel::OnChangeInfoView(Gui::MultiStateImageButton* b) { void ShipCpanel::OnChangeInfoView(Gui::MultiStateImageButton* b) {
@ -134,7 +138,7 @@ void ShipCpanel::OnClickTimeaccel(Gui::ISelectable* i, double step) {
L3D::SetTimeAccel(step); L3D::SetTimeAccel(step);
} }
void ShipCpanel::OnClickComms(void) { void ShipCpanel::OnClickComms(Gui::MultiStateImageButton* b) {
if(L3D::player->GetDockedWith()) L3D::SetView(L3D::spaceStationView); if(L3D::player->GetDockedWith()) L3D::SetView(L3D::spaceStationView);
} }

View File

@ -15,7 +15,7 @@ private:
void OnChangeMapView(Gui::MultiStateImageButton* b); void OnChangeMapView(Gui::MultiStateImageButton* b);
void OnChangeInfoView(Gui::MultiStateImageButton* b); void OnChangeInfoView(Gui::MultiStateImageButton* b);
void OnClickTimeaccel(Gui::ISelectable* i, double step); void OnClickTimeaccel(Gui::ISelectable* i, double step);
void OnClickComms(void); void OnClickComms(Gui::MultiStateImageButton* b);
Widget* m_scannerWidget; Widget* m_scannerWidget;
Gui::Label* m_clock; Gui::Label* m_clock;

View File

@ -37,6 +37,8 @@
virtual void Draw3D(void) = 0; virtual void Draw3D(void) = 0;
/* For checking key states, mouse stuff. */ /* For checking key states, mouse stuff. */
virtual void Update(void) = 0; virtual void Update(void) = 0;
virtual void Save(void) { }
virtual void Load(void) { }
protected: protected:
/* Each view can put some buttons in the bottom right of the cpanel. */ /* Each view can put some buttons in the bottom right of the cpanel. */
Gui::Fixed* m_rightButtonBar; Gui::Fixed* m_rightButtonBar;

View File

@ -5,6 +5,7 @@
#include "space.h" #include "space.h"
#include "space_station.h" #include "space_station.h"
#include "ship_cpanel.h" #include "ship_cpanel.h"
#include "serializer.h"
const float WorldView::PICK_OBJECT_RECT_SIZE = 20.0f; const float WorldView::PICK_OBJECT_RECT_SIZE = 20.0f;
@ -15,7 +16,10 @@ WorldView::WorldView(void): View() {
GetSize(size); GetSize(size);
labelsOn = true; labelsOn = true;
m_camType = CAM_FRONT;
SetTransparency(true); SetTransparency(true);
m_externalViewRotX = m_externalViewRotY = 0;
m_externalViewDist = 200;
commsOptions = new Fixed(size[0], size[1]/2); commsOptions = new Fixed(size[0], size[1]/2);
commsOptions->SetTransparency(true); commsOptions->SetTransparency(true);
@ -71,6 +75,41 @@ WorldView::WorldView(void): View() {
glEndList(); glEndList();
} }
void WorldView::Save(void) {
using namespace Serializer::Write;
wr_float(m_externalViewRotX);
wr_float(m_externalViewRotY);
wr_float(m_externalViewDist);
wr_int((int)m_camType);
}
void WorldView::Load(void) {
using namespace Serializer::Read;
m_externalViewRotX = rd_float();
m_externalViewRotY = rd_float();
m_externalViewDist = rd_float();
m_camType = (CamType)rd_int();
}
void WorldView::SetCamType(enum CamType c) {
m_camType = c;
}
vector3d WorldView::GetExternalViewTranslation(void) {
vector3d p = vector3d(0, 0, m_externalViewDist);
p = matrix4x4d::RotateXMatrix(-DEG2RAD(m_externalViewRotX)) * p;
p = matrix4x4d::RotateYMatrix(-DEG2RAD(m_externalViewRotY)) * p;
matrix4x4d m;
L3D::player->GetRotMatrix(m);
p = m*p;
return p;
}
void WorldView::ApplyExternalViewRotation(matrix4x4d& m) {
m = matrix4x4d::RotateXMatrix(-DEG2RAD(m_externalViewRotX)) * m;
m = matrix4x4d::RotateYMatrix(-DEG2RAD(m_externalViewRotY)) * m;
}
void WorldView::OnChangeWheelsState(Gui::MultiStateImageButton* b) { void WorldView::OnChangeWheelsState(Gui::MultiStateImageButton* b) {
if(!L3D::player->SetWheelState(b->GetState())) { if(!L3D::player->SetWheelState(b->GetState())) {
b->StatePrev(); b->StatePrev();
@ -114,15 +153,15 @@ void WorldView::Draw3D(void) {
matrix4x4d camRot = matrix4x4d::Identity(); matrix4x4d camRot = matrix4x4d::Identity();
if(L3D::GetCamType() == L3D::CAM_FRONT) { if(m_camType == CAM_FRONT) {
cam_frame.SetPosition(L3D::player->GetPosition()); cam_frame.SetPosition(L3D::player->GetPosition());
} else if(L3D::GetCamType() == L3D::CAM_REAR) { } else if(m_camType == CAM_REAR) {
camRot.RotateY(M_PI); camRot.RotateY(M_PI);
//glRotatef(180.0f, 0, 1, 0); //glRotatef(180.0f, 0, 1, 0);
cam_frame.SetPosition(L3D::player->GetPosition()); cam_frame.SetPosition(L3D::player->GetPosition());
} else { /* CAM_EXTERNAL */ } else { /* CAM_EXTERNAL */
cam_frame.SetPosition(L3D::player->GetPosition() + L3D::player->GetExternalViewTranslation()); cam_frame.SetPosition(L3D::player->GetPosition() + GetExternalViewTranslation());
L3D::player->ApplyExternalViewRotation(camRot); ApplyExternalViewRotation(camRot);
} }
{ {

View File

@ -14,6 +14,16 @@ public:
void UpdateCommsOptions(void); void UpdateCommsOptions(void);
bool GetShowLabels(void) { return labelsOn; } bool GetShowLabels(void) { return labelsOn; }
void DrawBgStars(void); void DrawBgStars(void);
vector3d GetExternalViewTranslation(void);
void ApplyExternalViewRotation(matrix4x4d& m);
virtual void Save(void);
virtual void Load(void);
enum CamType { CAM_FRONT, CAM_REAR, CAM_EXTERNAL };
void SetCamType(enum CamType);
enum CamType GetCamType(void) { return m_camType; }
float m_externalViewRotX, m_externalViewRotY;
float m_externalViewDist;
private: private:
Gui::Button* AddCommsOption(const std::string msg, int ypos); Gui::Button* AddCommsOption(const std::string msg, int ypos);
void OnClickHyperspace(void); void OnClickHyperspace(void);
@ -28,5 +38,6 @@ private:
Gui::Label* flightStatus; Gui::Label* flightStatus;
Gui::ImageButton* launchButton; Gui::ImageButton* launchButton;
bool labelsOn; bool labelsOn;
enum CamType m_camType;
}; };