This repository has been archived by the owner on Apr 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from RegrowthStudios/feature/killPlayer
Feature/kill player
- Loading branch information
Showing
218 changed files
with
10,250 additions
and
7,381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
Oops, something went wrong.