[Add] Spin keys.

[Change] Make stars render faster and use more realistic star type light
colours.
This commit is contained in:
Allanis 2018-01-23 18:54:35 +00:00
parent cb7d734e74
commit 768401686c
9 changed files with 62 additions and 37 deletions

9
README
View File

@ -29,6 +29,13 @@ X - Down thruster.
Rotation: Rotation:
~~~~~~~~~ ~~~~~~~~~
Q - Spin Left.
E - Spin Right.
<Left Cursor> - Yaw Left.
<Right Cursor> - Yaw Right.
<Up Cursor> - Pitch up.
<Down Cursor> - Pitch Down.
You can rotate your craft either with the cursor keys or by holding down the You can rotate your craft either with the cursor keys or by holding down the
right mouse button and moving the mouse. Only mouse rotation is available right mouse button and moving the mouse. Only mouse rotation is available
in the external view. in the external view.
@ -42,7 +49,7 @@ External View:
Special: Special:
~~~~~~~~ ~~~~~~~~
ESC - quit. ctrl-q - quit.
i - show some ugly debug info. i - show some ugly debug info.

View File

@ -8,6 +8,7 @@
#include <ode/ode.h> #include <ode/ode.h>
#include <float.h> #include <float.h>
#include <limits> #include <limits>
#include <time.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>

View File

@ -169,7 +169,7 @@ void L3D::HandleEvents(void) {
Gui::HandleSDLEvent(&event); Gui::HandleSDLEvent(&event);
switch(event.type) { switch(event.type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_ESCAPE) L3D::Quit(); if(KeyState(SDLK_LCTRL) && (event.key.keysym.sym == SDLK_q)) L3D::Quit();
if(event.key.keysym.sym == SDLK_i) L3D::showDebugInfo = !L3D::showDebugInfo; if(event.key.keysym.sym == SDLK_i) L3D::showDebugInfo = !L3D::showDebugInfo;
#ifdef DEBUG #ifdef DEBUG
if(event.key.keysym.sym == SDLK_F12) { if(event.key.keysym.sym == SDLK_F12) {

View File

@ -133,6 +133,8 @@ void Player::PollControls(void) {
if(L3D::KeyState(SDLK_UP)) angThrust.x += -1; if(L3D::KeyState(SDLK_UP)) angThrust.x += -1;
if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1; if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1;
} }
if(L3D::KeyState(SDLK_q)) angThrust.z += 1;
if(L3D::KeyState(SDLK_e)) angThrust.z -= 1;
/* Rotation damping. */ /* Rotation damping. */
vector3d damping = time_accel*CalcRotDamping(); vector3d damping = time_accel*CalcRotDamping();

View File

@ -175,10 +175,10 @@ void SectorView::Update(void) {
if(L3D::KeyState(SDLK_RIGHT)) m_px += 1*frameTime; if(L3D::KeyState(SDLK_RIGHT)) m_px += 1*frameTime;
if(L3D::KeyState(SDLK_UP)) m_py += 1*frameTime; if(L3D::KeyState(SDLK_UP)) m_py += 1*frameTime;
if(L3D::KeyState(SDLK_DOWN)) m_py -= 1*frameTime; if(L3D::KeyState(SDLK_DOWN)) m_py -= 1*frameTime;
if(L3D::KeyState(SDLK_EQUALS)) m_zoom *= pow(0.5, frameTime); if(L3D::KeyState(SDLK_EQUALS)) m_zoom *= pow(0.5f, frameTime);
if(L3D::KeyState(SDLK_MINUS)) m_zoom *= pow(2.0, frameTime); if(L3D::KeyState(SDLK_MINUS)) m_zoom *= pow(2.0f, frameTime);
if(m_zoomInButton->IsPressed()) m_zoom *= pow(0.5, frameTime); if(m_zoomInButton->IsPressed()) m_zoom *= pow(0.5f, frameTime);
if(m_zoomOutButton->IsPressed()) m_zoom *= pow(2.0, frameTime); if(m_zoomOutButton->IsPressed()) m_zoom *= pow(2.0f, frameTime);
m_zoom = CLAMP(m_zoom, 0.1, 5.0); m_zoom = CLAMP(m_zoom, 0.1, 5.0);
if(L3D::MouseButtonState(3)) { if(L3D::MouseButtonState(3)) {

View File

@ -17,37 +17,11 @@ void Star::SetPosition(vector3d p) {
pos = p; pos = p;
} }
static void DrawCorona(double rad, vector3d& pos, const float col[3]) {
glPushMatrix();
/* Face the camera damnit! */
vector3d zaxis = vector3d::Normalize(pos);
vector3d xaxis = vector3d::Normalize(vector3d::Cross(zaxis, vector3d(0, 1, 0)));
vector3d yaxis = vector3d::Cross(zaxis, xaxis);
matrix4x4d rot = matrix4x4d::MakeRotMatrix(xaxis, yaxis, zaxis).InverseOf();
glMultMatrixd(&rot[0]);
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
glBegin(GL_TRIANGLE_FAN);
glColor4f(col[0], col[1], col[2], 1);
glVertex3f(0, 0, 0);
glColor4f(0, 0, 0, 0);
for(float ang = 0; ang < 2*M_PI; ang += 0.2) {
glVertex3f(rad*sin(ang), rad*cos(ang), 0);
}
glVertex3f(0, rad, 0);
glEnd();
glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
glPopMatrix();
}
void Star::Render(const Frame* a_camFrame) { void Star::Render(const Frame* a_camFrame) {
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glPushMatrix(); glPushMatrix();
/* TODO duplicates code from Planet.cpp, not good. */
double rad = radius; double rad = radius;
vector3d fpos = GetPositionRelTo(a_camFrame); vector3d fpos = GetPositionRelTo(a_camFrame);
double len = fpos.Length(); double len = fpos.Length();
@ -60,9 +34,37 @@ void Star::Render(const Frame* a_camFrame) {
glTranslatef(fpos.x, fpos.y, fpos.z); glTranslatef(fpos.x, fpos.y, fpos.z);
glColor3fv(StarSystem::starColors[type]); {
gluSphere(L3D::gluQuadric, rad, 100, 100); const float* col = StarSystem::starRealColors[type];
DrawCorona(rad*4, fpos, StarSystem::starColors[type]); /* Face the darn camera. */
vector3d zaxis = vector3d::Normalize(fpos);
vector3d xaxis = vector3d::Normalize(vector3d::Cross(vector3d(0, 1, 0), zaxis));
vector3d yaxis = vector3d::Cross(zaxis, xaxis);
matrix4x4d rot = matrix4x4d::MakeRotMatrix(xaxis, yaxis, zaxis).InverseOf();
glMultMatrixd(&rot[0]);
glEnable(GL_BLEND);
glBegin(GL_TRIANGLE_FAN);
glColor4f(col[0], col[1], col[2], 1);
glVertex3f(0, 0, 0);
glColor4f(0, 0, 0, 0);
for(float ang = 0; ang < 2*M_PI; ang += 0.2) {
glVertex3f(4*rad*sin(ang), 4*rad*cos(ang), 0);
}
glVertex3f(0, 4*rad, 0);
glEnd();
glDisable(GL_BLEND);
glBegin(GL_TRIANGLE_FAN);
glColor4f(col[0], col[1], col[2], 1);
glVertex3f(0, 0, 0);
for(float ang = 0; ang < 2*M_PI; ang += 0.1) {
glVertex3f(rad*sin(ang), rad*cos(ang), 0);
}
glVertex3f(0, rad, 0);
glEnd();
}
glPopMatrix(); glPopMatrix();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);

View File

@ -18,6 +18,19 @@ float StarSystem::starColors[][3] = {
{ 0.4, 0.4, 0.8 } /* White dwarf. */ { 0.4, 0.4, 0.8 } /* White dwarf. */
}; };
/* Indexed by enum type. */
float StarSystem::starRealColors[][3] = {
{ 0, 0, 0 }, /* Gravpoint. */
{ 1.0, 0.2, 0.0 }, /* M */
{ 1.0, 0.7, 0.1 }, /* K */
{ 1.0, 1.0, 0.9 }, /* G */
{ 1.0, 1.0, 1.0 }, /* F */
{ 1.0, 1.0, 1.0 }, /* A */
{ 0.7, 0.7, 1.0 }, /* B */
{ 1.0, 0.7, 1.0 }, /* O */
{ 1.0, 1.0, 1.0 }, /* White Dwarf. */
};
static const struct SBodySubTypeInfo { static const struct SBodySubTypeInfo {
StarSystem::BodySuperType supertype; StarSystem::BodySuperType supertype;
int mass[2]; /* Min, max % sol for stars, unused for planets. */ int mass[2]; /* Min, max % sol for stars, unused for planets. */

View File

@ -29,6 +29,7 @@ public:
int GetNumStars(void) const { return m_numStars; } int GetNumStars(void) const { return m_numStars; }
static float starColors[][3]; static float starColors[][3];
static float starRealColors[][3];
struct Orbit { struct Orbit {
void KeplerPosAtTime(double t, double* dist, double* ang); void KeplerPosAtTime(double t, double* dist, double* ang);

View File

@ -145,11 +145,10 @@ void WorldView::Draw3D(void) {
lightPos[2] = lpos.z; lightPos[2] = lpos.z;
lightPos[3] = 0; lightPos[3] = 0;
const float* col = StarSystem::starColors[L3D::currentSystem->rootBody->type]; const float* col = StarSystem::starRealColors[L3D::currentSystem->rootBody->type];
float lightCol[4] = { col[0], col[1], col[2], 0 }; float lightCol[4] = { col[0], col[1], col[2], 0 };
float ambCol[4] = { col[0]*0.1, col[1]*0.1, col[2]*0.1, 0 }; float ambCol[4] = { col[0]*0.1, col[1]*0.1, col[2]*0.1, 0 };
//glColor3fv(StarSystem::starColors[(*i).primaryStarClass]);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightCol); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightCol);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambCol); glLightfv(GL_LIGHT0, GL_AMBIENT, ambCol);