Skip to content
This repository has been archived by the owner on Apr 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #142 from RegrowthStudios/feature/killPlayer
Browse files Browse the repository at this point in the history
Feature/kill player
  • Loading branch information
czaloj committed Jan 20, 2015
2 parents c754086 + 2fbcf17 commit 02b7815
Show file tree
Hide file tree
Showing 218 changed files with 10,250 additions and 7,381 deletions.
3 changes: 2 additions & 1 deletion SoA/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

#include <Vorb/graphics/Texture.h>

struct Animation {
class Animation {
public:
Animation() : fadeOutBegin(INT_MAX) {}
int duration;
int fadeOutBegin;
Expand Down
33 changes: 15 additions & 18 deletions SoA/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
#include <Vorb/graphics/SpriteBatch.h>

#include "DevScreen.h"
#include "GameManager.h"
#include "GamePlayScreen.h"
#include "InitScreen.h"
#include "LoadScreen.h"
#include "MainMenuScreen.h"
#include "GamePlayScreen.h"
#include "MeshManager.h"
#include "Options.h"
#include "GamePlayScreen.h"
#include "SpaceSystem.h"
#include "TestBlockViewScreen.h"
#include "TestConsoleScreen.h"
#include "TestDeferredScreen.h"
#include "TestMappingScreen.h"


void App::addScreens() {
scrInit = new InitScreen(this);
scrLoad = new LoadScreen(this);
scrMainMenu = new MainMenuScreen(this);
scrGamePlay = new GamePlayScreen(this);
scrMainMenu = new MainMenuScreen(this, scrLoad);
scrGamePlay = new GamePlayScreen(this, scrMainMenu);

_screenList->addScreen(scrInit);
_screenList->addScreen(scrLoad);
Expand All @@ -48,20 +52,17 @@ void App::addScreens() {
_screenList->addScreen(scrTests.back());
scrDev->addScreen(VKEY_B, scrTests.back());


// Start from dev screen for convenience
_screenList->setScreen(scrDev->getIndex());
_screenList->setScreen(scrInit->getIndex());
}

void App::onInit() {

// Load the graphical options
initializeOptions();
loadOptions();
loadOptions("Data/Options.yml");

SamplerState::initPredefined();

// Allocate resources
meshManager = new MeshManager;
}

void App::onExit() {
Expand All @@ -71,14 +72,10 @@ void App::onExit() {
}

App::~App() {
#define COND_DEL(SCR) if (SCR) { delete SCR; SCR = nullptr; }

COND_DEL(scrInit)
COND_DEL(scrLoad)
// TODO: Why do these break
//COND_DEL(scrMainMenu)
//COND_DEL(scrGamePlay)
COND_DEL(scrDev)

delete meshManager;
delete scrInit;
delete scrLoad;
delete scrMainMenu;
delete scrGamePlay;
delete scrDev;
}
13 changes: 5 additions & 8 deletions SoA/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class InitScreen;
class LoadScreen;
class MainMenuScreen;
class GamePlayScreen;
class MeshManager;
class TexturePackLoader;

class App : public MainGame {
Expand All @@ -22,15 +21,13 @@ class App : public MainGame {
virtual void onExit();

// Accessible Pointers To Screens
InitScreen* scrInit;
LoadScreen* scrLoad;
MainMenuScreen* scrMainMenu;
GamePlayScreen* scrGamePlay;
InitScreen* scrInit = nullptr;
LoadScreen* scrLoad = nullptr;
MainMenuScreen* scrMainMenu = nullptr;
GamePlayScreen* scrGamePlay = nullptr;

DevScreen* scrDev;
DevScreen* scrDev = nullptr;
std::vector<IGameScreen*> scrTests;

MeshManager* meshManager; ///< Stores chunk, terrain, particle, and physics block meshes
};

#endif // App_h_
131 changes: 131 additions & 0 deletions SoA/Atmosphere.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include "stdafx.h"
#include "Atmosphere.h"

#include "ObjectLoader.h"
#include "GameManager.h"
#include "GLProgramManager.h"

#include <glm\gtc\type_ptr.hpp>
#include <glm\gtc\quaternion.hpp>
#include <glm\gtx\quaternion.hpp>
#include <glm\gtc\matrix_transform.hpp>

Atmosphere::Atmosphere() {
m_Kr = 0.0025f; // Rayleigh scattering constant
m_Km = 0.0020f; // Mie scattering constant
m_ESun = 25.0f; // Sun brightness constant
m_g = -0.990f; // The Mie phase asymmetry factor
m_fExposure = 2.0f;
m_fRayleighScaleDepth = 0.25f; //0.25

m_fWavelength[0] = 0.650f; // 650 nm for red
m_fWavelength[1] = 0.570f; // 570 nm for green
m_fWavelength[2] = 0.475f; // 475 nm for blue
m_fWavelength4[0] = powf(m_fWavelength[0], 4.0f);
m_fWavelength4[1] = powf(m_fWavelength[1], 4.0f);
m_fWavelength4[2] = powf(m_fWavelength[2], 4.0f);

nSamples = 3;
fSamples = (float)nSamples;
}

void Atmosphere::initialize(nString filePath, float PlanetRadius) {
if (filePath.empty()) {
m_Kr = 0.0025;
m_Km = 0.0020;
m_ESun = 25.0;
m_g = -0.990;
m_fExposure = 2.0;
m_fWavelength[0] = 0.650;
m_fWavelength[1] = 0.570;
m_fWavelength[2] = 0.475;
nSamples = 3;

fSamples = (float)nSamples;
m_fWavelength4[0] = powf(m_fWavelength[0], 4.0f);
m_fWavelength4[1] = powf(m_fWavelength[1], 4.0f);
m_fWavelength4[2] = powf(m_fWavelength[2], 4.0f);
} else {
// loadProperties(filePath);
}

radius = PlanetRadius*(1.025);
planetRadius = PlanetRadius;

std::cout << "Loading Objects/icosphere.obj... ";
ObjectLoader objectLoader;
objectLoader.load("Objects/icosphere.obj", vertices, indices);
std::cout << "Done!\n";

glGenBuffers(1, &(vboID)); // Create the buffer ID
glBindBuffer(GL_ARRAY_BUFFER, vboID); // Bind the buffer (vertex array data)
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(ColorVertex), NULL, GL_STATIC_DRAW);

glGenBuffers(1, &(vboIndexID));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndexID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLushort), NULL, GL_STATIC_DRAW);

glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size() * sizeof(ColorVertex), &(vertices[0].position));
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indices.size() * sizeof(GLushort), &(indices[0]));
indexSize = indices.size();

vertices.clear();
indices.clear();
}

void Atmosphere::draw(float theta, const glm::mat4 &MVP, glm::vec3 lightPos, const glm::dvec3 &ppos) {
vg::GLProgram* shader = nullptr; // GameManager::glProgramManager->getProgram("Sky");
shader->use();

glm::mat4 GlobalModelMatrix(1.0);
GlobalModelMatrix[0][0] = radius;
GlobalModelMatrix[1][1] = radius;
GlobalModelMatrix[2][2] = radius;
GlobalModelMatrix[3][0] = (f32)-ppos.x;
GlobalModelMatrix[3][1] = (f32)-ppos.y;
GlobalModelMatrix[3][2] = (f32)-ppos.z;

// Have to rotate it and draw it again to make a sphere
f32v3 EulerAngles(M_PI, 0, 0);
f32m4 RotationMatrix = glm::toMat4(glm::quat(EulerAngles));
f32m4 MVPr = MVP * GlobalModelMatrix;
f32m4 M = GlobalModelMatrix;

f32 m_Kr4PI = m_Kr * 4.0f* M_PI;
f32 m_Km4PI = m_Km * 4.0f* M_PI;
f32 m_fScale = 1.0 / (radius - planetRadius);

glUniformMatrix4fv(shader->getUniform("unWVP"), 1, GL_FALSE, &MVPr[0][0]);
glUniform3f(shader->getUniform("unCameraPos"), (float)ppos.x, (float)ppos.y, (float)ppos.z);
glUniform3f(shader->getUniform("unLightPos"), lightPos.x, lightPos.y, lightPos.z);
glUniform3f(shader->getUniform("unInvWavelength"), 1 / m_fWavelength4[0], 1 / m_fWavelength4[1], 1 / m_fWavelength4[2]);
glUniform1f(shader->getUniform("unCameraHeight2"), glm::length(ppos) * glm::length(ppos));
glUniform1f(shader->getUniform("unOuterRadius"), radius);
glUniform1f(shader->getUniform("unOuterRadius2"), radius * radius);
glUniform1f(shader->getUniform("unInnerRadius"), planetRadius);
glUniform1f(shader->getUniform("unKrESun"), m_Kr*m_ESun);
glUniform1f(shader->getUniform("unKmESun"), m_Km*m_ESun);
glUniform1f(shader->getUniform("unKr4PI"), m_Kr4PI);
glUniform1f(shader->getUniform("unKm4PI"), m_Km4PI);
glUniform1f(shader->getUniform("unScale"), m_fScale);
glUniform1f(shader->getUniform("unScaleDepth"), m_fRayleighScaleDepth);
glUniform1f(shader->getUniform("unScaleOverScaleDepth"), m_fScale / m_fRayleighScaleDepth);
glUniform1f(shader->getUniform("unG"), m_g);
glUniform1f(shader->getUniform("unG2"), m_g*m_g);
glUniform1i(shader->getUniform("unNumSamples"), nSamples);
glUniform1f(shader->getUniform("unNumSamplesF"), fSamples);

glBindBuffer(GL_ARRAY_BUFFER, vboID);

shader->enableVertexAttribArrays();

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ColorVertex), (void*)0);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndexID);

glDrawElements(GL_TRIANGLES, indexSize, GL_UNSIGNED_SHORT, 0);

shader->disableVertexAttribArrays();

shader->unuse();
}
46 changes: 46 additions & 0 deletions SoA/Atmosphere.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
///
/// Atmosphere.h
/// Seed of Andromeda
///
/// Created by Benjamin Arnold on 30 Nov 2014
/// Copyright 2014 Regrowth Studios
/// All Rights Reserved
///
/// Summary:
/// Defines an atmosphere for planet rendering
///

#pragma once

#ifndef Atmosphere_h__
#define Atmosphere_h__

#include "OpenGLStructs.h"

class Atmosphere {
public:
Atmosphere();

void initialize(nString filePath, f32 PlanetRadius);
void draw(f32 theta, const f32m4& MVP, f32v3 lightPos, const f64v3& ppos);

std::vector<ColorVertex> vertices;
std::vector<ui16> indices;
ui32 vboID, vbo2ID, vboIndexID, vboIndexID2;
ui32 indexSize;
f64 radius;
f64 planetRadius;

f32 m_fWavelength[3], m_fWavelength4[3];
f32 m_Kr; // Rayleigh scattering constant
f32 m_Km; // Mie scattering constant
f32 m_ESun; // Sun brightness constant
f32 m_g; // The Mie phase asymmetry factor
f32 m_fExposure;
f32 m_fRayleighScaleDepth;
f32 fSamples;
i32 nSamples;
i32 debugIndex;
};

#endif // Atmosphere_h__
21 changes: 21 additions & 0 deletions SoA/AtmosphereComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "stdafx.h"
#include "AtmosphereComponent.h"


AtmosphereComponent::AtmosphereComponent() {
}

AtmosphereComponent::~AtmosphereComponent() {
}

void AtmosphereComponent::init() {

}

void AtmosphereComponent::draw() {

}

void AtmosphereComponent::loadProperties(const nString& filePath) {

}
32 changes: 32 additions & 0 deletions SoA/AtmosphereComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
///
/// AtmosphereComponent.h
/// Seed of Andromeda
///
/// Created by Benjamin Arnold on 31 Dec 2014
/// Copyright 2014 Regrowth Studios
/// All Rights Reserved
///
/// Summary:
/// Atmosphere component for planets
///

#pragma once

#ifndef AtmosphereComponent_h__
#define AtmosphereComponent_h__

class AtmosphereComponent {
public:
AtmosphereComponent();
~AtmosphereComponent();

void init();

void draw();

void loadProperties(const nString& filePath);

private:
};

#endif // AtmosphereComponent_h__
11 changes: 11 additions & 0 deletions SoA/AxisRotationComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "stdafx.h"
#include "AxisRotationComponent.h"

#include <glm/gtc/quaternion.hpp>

void AxisRotationComponent::init(f64 AngularSpeed_RS, f64 CurrentRotation, f64q AxisOrientation) {
angularSpeed_RS = AngularSpeed_RS;
currentRotation = CurrentRotation;
invCurrentOrientation = glm::inverse(currentOrientation);
axisOrientation = AxisOrientation;
}
32 changes: 32 additions & 0 deletions SoA/AxisRotationComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
///
/// AxisRotationComponent.h
/// Seed of Andromeda
///
/// Created by Benjamin Arnold on 3 Dec 2014
/// Copyright 2014 Regrowth Studios
/// All Rights Reserved
///
/// Summary:
/// Defines a component for axis rotation
///

#pragma once

#ifndef AxisRotationComponent_h__
#define AxisRotationComponent_h__

#include "stdafx.h"

class AxisRotationComponent {
public:
/// Initializes the component
void init(f64 AngularSpeed_RS, f64 CurrentRotation, f64q AxisOrientation);

f64q axisOrientation; ///< Axis of rotation
f64q currentOrientation; ///< Current orientation with axis and rotation
f64q invCurrentOrientation; ///< Inverse of currentOrientation
f64 angularSpeed_RS = 0.0; ///< Rotational speed about axis in radians per second
f64 currentRotation = 0.0; ///< Current rotation about axis in radians
};

#endif // AxisRotationComponent_h__
Loading

0 comments on commit 02b7815

Please sign in to comment.