+ added line width of 2
This commit is contained in:
parent
70b0fee526
commit
9e4bda9242
1 changed files with 451 additions and 452 deletions
|
@ -9,11 +9,10 @@
|
||||||
#include "developer_console.hpp"
|
#include "developer_console.hpp"
|
||||||
|
|
||||||
namespace endofthejedi {
|
namespace endofthejedi {
|
||||||
void RendererPolygon3d::setup()
|
void RendererPolygon3d::setup() {
|
||||||
{
|
|
||||||
m_lastTime = -1.0;
|
m_lastTime = -1.0;
|
||||||
|
|
||||||
//std::cout << "setup polygon 3d" << std::endl;
|
// std::cout << "setup polygon 3d" << std::endl;
|
||||||
|
|
||||||
m_shader_game_objects.init();
|
m_shader_game_objects.init();
|
||||||
m_shader_game_objects.loadFile("../data/shader/gameobjects.vert",
|
m_shader_game_objects.loadFile("../data/shader/gameobjects.vert",
|
||||||
|
@ -33,7 +32,7 @@ namespace endofthejedi {
|
||||||
m_shader_background.loadFile("../data/shader/background.frag",
|
m_shader_background.loadFile("../data/shader/background.frag",
|
||||||
GL_FRAGMENT_SHADER);
|
GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
//addModel("../data/mesh/small_atomic_bomb.stl", &m_missileModel);
|
// addModel("../data/mesh/small_atomic_bomb.stl", &m_missileModel);
|
||||||
addModel("../data/mesh/rocket.stl", &m_missileModel);
|
addModel("../data/mesh/rocket.stl", &m_missileModel);
|
||||||
addModel("../data/mesh/planet_128.stl", &m_planetModel);
|
addModel("../data/mesh/planet_128.stl", &m_planetModel);
|
||||||
addModel("../data/mesh/ship_ufo.stl", &m_shipModel);
|
addModel("../data/mesh/ship_ufo.stl", &m_shipModel);
|
||||||
|
@ -73,13 +72,12 @@ namespace endofthejedi {
|
||||||
loadBackgroundTexture();
|
loadBackgroundTexture();
|
||||||
return developer::resultOkay();
|
return developer::resultOkay();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::loadBackgroundTexture()
|
void RendererPolygon3d::loadBackgroundTexture() {
|
||||||
{
|
// m_texture = new ImageTexture("../data/img/test.png");
|
||||||
//m_texture = new ImageTexture("../data/img/test.png");
|
|
||||||
if (m_texture != nullptr) {
|
if (m_texture != nullptr) {
|
||||||
delete(m_texture);
|
delete (m_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
//"../data/img/stars_nebular.png");
|
//"../data/img/stars_nebular.png");
|
||||||
|
@ -88,28 +86,28 @@ namespace endofthejedi {
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
m_texture->loadPng();
|
m_texture->loadPng();
|
||||||
|
|
||||||
std::cout<<"texture loading: " << m_texture->valid() << std::endl;
|
std::cout << "texture loading: " << m_texture->valid() << std::endl;
|
||||||
if (!m_texture->valid()) {
|
if (!m_texture->valid()) {
|
||||||
std::cout<<"loading failed!";
|
std::cout << "loading failed!";
|
||||||
return;
|
return;
|
||||||
//exit(-1);
|
// exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 s = m_texture->size();
|
glm::vec2 s = m_texture->size();
|
||||||
std::cout<<"texture size is " << s.x << " X " << s.y << std::endl;
|
std::cout << "texture size is " << s.x << " X " << s.y << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::renderBackgroundImage()
|
void RendererPolygon3d::renderBackgroundImage() {
|
||||||
{
|
|
||||||
m_shader_background.bind();
|
m_shader_background.bind();
|
||||||
|
|
||||||
glUniform2fv(m_shader_background.location("uvScale"), 1, glm::value_ptr(m_texture->uvScale()));
|
glUniform2fv(m_shader_background.location("uvScale"), 1,
|
||||||
|
glm::value_ptr(m_texture->uvScale()));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_texture->textureId());
|
glBindTexture(GL_TEXTURE_2D, m_texture->textureId());
|
||||||
|
|
||||||
//drawNdcQuad();
|
// drawNdcQuad();
|
||||||
glColor3f(1.0, 0.0, 0.0);
|
glColor3f(1.0, 0.0, 0.0);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex2f(-1.0f, -1.0f);
|
glVertex2f(-1.0f, -1.0f);
|
||||||
|
@ -117,10 +115,9 @@ namespace endofthejedi {
|
||||||
glVertex2f(1.0f, 1.0f);
|
glVertex2f(1.0f, 1.0f);
|
||||||
glVertex2f(-1.0f, 1.0f);
|
glVertex2f(-1.0f, 1.0f);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::render(const game::State *state)
|
void RendererPolygon3d::render(const game::State *state) {
|
||||||
{
|
|
||||||
if (m_lastTime == -1.0) {
|
if (m_lastTime == -1.0) {
|
||||||
m_lastTime = state->timestamp();
|
m_lastTime = state->timestamp();
|
||||||
}
|
}
|
||||||
|
@ -138,7 +135,7 @@ namespace endofthejedi {
|
||||||
// TODO: add little rocks flying around
|
// TODO: add little rocks flying around
|
||||||
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
m_postprocess_fbo.bind();
|
m_postprocess_fbo.bind();
|
||||||
|
|
||||||
|
@ -156,18 +153,10 @@ namespace endofthejedi {
|
||||||
m_postprocess_tex0.getName());
|
m_postprocess_tex0.getName());
|
||||||
renderBackgroundImage();
|
renderBackgroundImage();
|
||||||
|
|
||||||
//float s = 0.1;
|
|
||||||
//glClearColor(s, s, 1.2*s, 1.0);
|
|
||||||
|
|
||||||
m_shader_game_objects.bind();
|
m_shader_game_objects.bind();
|
||||||
|
|
||||||
// TODO: add ONE sun planet
|
|
||||||
// TODO: add lights for explosions
|
|
||||||
|
|
||||||
configureLightningInShader(&m_shader_game_objects);
|
configureLightningInShader(&m_shader_game_objects);
|
||||||
|
|
||||||
//std::cout<<"setting aspect ratio: " << m_aspectRatio << std::endl;
|
|
||||||
|
|
||||||
renderPlanets();
|
renderPlanets();
|
||||||
renderShips();
|
renderShips();
|
||||||
renderMissiles();
|
renderMissiles();
|
||||||
|
@ -180,7 +169,7 @@ namespace endofthejedi {
|
||||||
m_postprocess_tex1.bind();
|
m_postprocess_tex1.bind();
|
||||||
m_postprocess_fbo.attachTexture(GL_COLOR_ATTACHMENT0,
|
m_postprocess_fbo.attachTexture(GL_COLOR_ATTACHMENT0,
|
||||||
m_postprocess_tex1.getName());
|
m_postprocess_tex1.getName());
|
||||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
m_shader_game_objects.bind();
|
m_shader_game_objects.bind();
|
||||||
configureLightningInShader(&m_shader_game_objects);
|
configureLightningInShader(&m_shader_game_objects);
|
||||||
|
@ -195,7 +184,6 @@ namespace endofthejedi {
|
||||||
|
|
||||||
// postprocessing
|
// postprocessing
|
||||||
m_postprocess_shader.bind();
|
m_postprocess_shader.bind();
|
||||||
//glColor3f(1.0, 0.0, 0.0);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
m_postprocess_tex1.bind();
|
m_postprocess_tex1.bind();
|
||||||
|
|
||||||
|
@ -203,19 +191,17 @@ namespace endofthejedi {
|
||||||
glUniform2f(m_postprocess_shader.location("uvScale"), 1, 1);
|
glUniform2f(m_postprocess_shader.location("uvScale"), 1, 1);
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
glUniform2f(m_postprocess_shader.location("scale"), 2.0f / m_w,
|
glUniform2f(m_postprocess_shader.location("scale"), 2.0f / m_w, 0.0f);
|
||||||
0.0f);
|
|
||||||
//glVertex2f(1.0f, -1.0f);
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex2f(-1.0f, -1.0f);
|
glVertex2f(-1.0f, -1.0f);
|
||||||
glVertex2f(1.0f, -1.0f);
|
glVertex2f(1.0f, -1.0f);
|
||||||
glVertex2f(1.0f, 1.0f);
|
glVertex2f(1.0f, 1.0f);
|
||||||
glVertex2f(-1.0f, 1.0f);
|
glVertex2f(-1.0f, 1.0f);
|
||||||
glEnd();
|
glEnd();
|
||||||
//glVertex2f(1.0f, 1.0f);
|
|
||||||
glUniform2f(m_postprocess_shader.location("scale"), 0.0f,
|
glUniform2f(m_postprocess_shader.location("scale"), 0.0f, 2.0f / m_h);
|
||||||
2.0f / m_h);
|
|
||||||
//glVertex2f(-1.0f, 1.0f);
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex2f(-1.0f, -1.0f);
|
glVertex2f(-1.0f, -1.0f);
|
||||||
glVertex2f(1.0f, -1.0f);
|
glVertex2f(1.0f, -1.0f);
|
||||||
|
@ -238,7 +224,7 @@ namespace endofthejedi {
|
||||||
m_postprocess_tex0.bind();
|
m_postprocess_tex0.bind();
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
m_postprocess_tex1.bind();
|
m_postprocess_tex1.bind();
|
||||||
//glEnd();
|
|
||||||
glColor3f(1.0, 0.0, 0.0);
|
glColor3f(1.0, 0.0, 0.0);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex2f(-1.0f, -1.0f);
|
glVertex2f(-1.0f, -1.0f);
|
||||||
|
@ -248,10 +234,9 @@ namespace endofthejedi {
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
m_lastTime = state->timestamp();
|
m_lastTime = state->timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::renderParticles()
|
void RendererPolygon3d::renderParticles() {
|
||||||
{
|
|
||||||
m_shader_particles.bind();
|
m_shader_particles.bind();
|
||||||
|
|
||||||
glUniform1f(m_shader_particles.location("aspectRatio"), m_aspectRatio);
|
glUniform1f(m_shader_particles.location("aspectRatio"), m_aspectRatio);
|
||||||
|
@ -260,15 +245,15 @@ namespace endofthejedi {
|
||||||
batch->bind();
|
batch->bind();
|
||||||
batch->render(&m_shader_particles);
|
batch->render(&m_shader_particles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::addExplosionEffect(
|
void RendererPolygon3d::addExplosionEffect(size_t id,
|
||||||
size_t id, const glm::vec2 &explCenter, const glm::vec2 &missileVelocity,
|
const glm::vec2 &explCenter,
|
||||||
bool isPlanetHit,
|
const glm::vec2 &missileVelocity,
|
||||||
size_t n, float duration)
|
bool isPlanetHit, size_t n,
|
||||||
{
|
float duration) {
|
||||||
//float particleRadius = 0.005;
|
// float particleRadius = 0.005;
|
||||||
//float particleRadius = 0.003;
|
// float particleRadius = 0.003;
|
||||||
float particleRadius = 0.02;
|
float particleRadius = 0.02;
|
||||||
|
|
||||||
// TODO: use this as shader input too and make the area 2x around this
|
// TODO: use this as shader input too and make the area 2x around this
|
||||||
|
@ -281,18 +266,19 @@ namespace endofthejedi {
|
||||||
batch->setCenter(glm::vec3(explCenter, 0.0));
|
batch->setCenter(glm::vec3(explCenter, 0.0));
|
||||||
batch->setMaxVelocity(maxVelocity);
|
batch->setMaxVelocity(maxVelocity);
|
||||||
|
|
||||||
for (size_t i=0; i<n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
// distribute in a circle
|
// distribute in a circle
|
||||||
//float t = 2.0 * M_PI * i / (float) n;
|
// float t = 2.0 * M_PI * i / (float) n;
|
||||||
//t += 0.2*util::randf_m1_1();
|
// t += 0.2*util::randf_m1_1();
|
||||||
|
|
||||||
// with random velocities
|
// with random velocities
|
||||||
// this is 3d because it looks better if some particles leave/enter
|
// this is 3d because it looks better if some particles leave/enter
|
||||||
// the space and they are not all on one plane.
|
// the space and they are not all on one plane.
|
||||||
// especially in 3d this would look bad without 3d velocity vector.
|
// especially in 3d this would look bad without 3d velocity vector.
|
||||||
//glm::vec3 v = 0.5f*glm::vec3(sin(t), cos(t), util::randf_m1_1());
|
// glm::vec3 v = 0.5f*glm::vec3(sin(t), cos(t), util::randf_m1_1());
|
||||||
|
|
||||||
glm::vec3 pos = glm::vec3(explCenter, 0.0) + glm::ballRand(explCoreSize);
|
glm::vec3 pos =
|
||||||
|
glm::vec3(explCenter, 0.0) + glm::ballRand(explCoreSize);
|
||||||
|
|
||||||
glm::vec3 v = glm::ballRand(maxVelocity);
|
glm::vec3 v = glm::ballRand(maxVelocity);
|
||||||
|
|
||||||
|
@ -305,8 +291,8 @@ namespace endofthejedi {
|
||||||
|
|
||||||
// find collisions with planetns and limit max distance so particles
|
// find collisions with planetns and limit max distance so particles
|
||||||
// won't fly through planets
|
// won't fly through planets
|
||||||
//float maxDist = 0.1;
|
// float maxDist = 0.1;
|
||||||
//float maxDist = 0.1*util::randf_0_1();
|
// float maxDist = 0.1*util::randf_0_1();
|
||||||
bool isInsidePlanet = false;
|
bool isInsidePlanet = false;
|
||||||
float maxParticleDist = INFINITY;
|
float maxParticleDist = INFINITY;
|
||||||
|
|
||||||
|
@ -329,7 +315,7 @@ namespace endofthejedi {
|
||||||
}
|
}
|
||||||
// TODO: if inside, move position so that it looks like
|
// TODO: if inside, move position so that it looks like
|
||||||
// reflecting the particle from the planet
|
// reflecting the particle from the planet
|
||||||
bool fliesInPlanetDirection = glm::dot(v, ppos3-pos) > 0.0f;
|
bool fliesInPlanetDirection = glm::dot(v, ppos3 - pos) > 0.0f;
|
||||||
if (dist < maxParticleDist && fliesInPlanetDirection) {
|
if (dist < maxParticleDist && fliesInPlanetDirection) {
|
||||||
nearestPlanet = planet;
|
nearestPlanet = planet;
|
||||||
maxParticleDist = dist;
|
maxParticleDist = dist;
|
||||||
|
@ -340,19 +326,21 @@ namespace endofthejedi {
|
||||||
|
|
||||||
if (isInsidePlanet && isPlanetHit) {
|
if (isInsidePlanet && isPlanetHit) {
|
||||||
util::IntersectionTest intersect;
|
util::IntersectionTest intersect;
|
||||||
if (!intersect.raySphere(
|
if (!intersect.raySphere(glm::vec3(explCenter, 0.0f), v,
|
||||||
glm::vec3(explCenter, 0.0f), v,
|
glm::vec3(nearestPlanet->position, 0.0f),
|
||||||
glm::vec3(nearestPlanet->position, 0.0f), nearestPlanet->radius))
|
nearestPlanet->radius)) {
|
||||||
{
|
|
||||||
makeStationary = true;
|
makeStationary = true;
|
||||||
//std::cout<<"warning: intersection should be valid!" << std::endl;
|
// std::cout<<"warning: intersection should be valid!" <<
|
||||||
|
// std::endl;
|
||||||
// TODO: must be as they lie on a plane and the dist is < as
|
// TODO: must be as they lie on a plane and the dist is < as
|
||||||
// the radius.
|
// the radius.
|
||||||
// handle if this is wrong.
|
// handle if this is wrong.
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// simple reflection, ignoring the missile velocity: this looks good enough
|
// simple reflection, ignoring the missile velocity: this looks
|
||||||
glm::vec3 planetNormal = glm::normalize(pos - glm::vec3(nearestPlanet->position, 0.0f));
|
// good enough
|
||||||
|
glm::vec3 planetNormal = glm::normalize(
|
||||||
|
pos - glm::vec3(nearestPlanet->position, 0.0f));
|
||||||
v = glm::length(v) * planetNormal;
|
v = glm::length(v) * planetNormal;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -360,20 +348,24 @@ namespace endofthejedi {
|
||||||
|
|
||||||
// set position to the intersection point between explosion
|
// set position to the intersection point between explosion
|
||||||
// center and planet surface
|
// center and planet surface
|
||||||
//pos = intersect.pointAtDistance(intersect.distance());
|
// pos = intersect.pointAtDistance(intersect.distance());
|
||||||
//v = glm::vec3(missileVelocity, 0.0f);
|
// v = glm::vec3(missileVelocity, 0.0f);
|
||||||
//v = v - 2.0f*glm::dot(v, planetNormal) * planetNormal;
|
// v = v - 2.0f*glm::dot(v, planetNormal) * planetNormal;
|
||||||
//v *= 4.0;
|
// v *= 4.0;
|
||||||
//maxParticleDist = 100.0;
|
// maxParticleDist = 100.0;
|
||||||
//v = -v;
|
// v = -v;
|
||||||
|
|
||||||
//pos = glm::vec3(nearestPlanet->position, 0.0f) + nearestPlanet->radius*planetNormal;
|
// pos = glm::vec3(nearestPlanet->position, 0.0f) +
|
||||||
|
// nearestPlanet->radius*planetNormal;
|
||||||
|
|
||||||
// set position to the intersection point between explosion
|
// set position to the intersection point between explosion
|
||||||
// center and planet surface
|
// center and planet surface
|
||||||
//const glm::vec3 planetNormal = glm::vec3(glm::normalize(explCenter - nearestPlanet->position), 0.0f);
|
// const glm::vec3 planetNormal =
|
||||||
|
// glm::vec3(glm::normalize(explCenter -
|
||||||
|
// nearestPlanet->position), 0.0f);
|
||||||
|
|
||||||
//pos = glm::vec3(nearestPlanet->position, 0.0f) + nearestPlanet->radius*planetNormal;
|
// pos = glm::vec3(nearestPlanet->position, 0.0f) +
|
||||||
|
// nearestPlanet->radius*planetNormal;
|
||||||
|
|
||||||
// build new velocity by reflecting the old velocity on the
|
// build new velocity by reflecting the old velocity on the
|
||||||
// planet normal
|
// planet normal
|
||||||
|
@ -383,17 +375,20 @@ namespace endofthejedi {
|
||||||
// TODO: add material exhaust that is specific for the planet.
|
// TODO: add material exhaust that is specific for the planet.
|
||||||
// TODO: spawn waves on water planet
|
// TODO: spawn waves on water planet
|
||||||
// TODO: start fire on gas planet
|
// TODO: start fire on gas planet
|
||||||
//v = glm::length(v) * planetNormal;
|
// v = glm::length(v) * planetNormal;
|
||||||
//v = v - 2.0f*glm::dot(v, planetNormal) * planetNormal;
|
// v = v - 2.0f*glm::dot(v, planetNormal) * planetNormal;
|
||||||
//v = glm::length(v) * planetNormal;
|
// v = glm::length(v) * planetNormal;
|
||||||
|
|
||||||
//glm::vec3 r = v - 2.0f*glm::dot(v, planetNormal) * planetNormal;
|
// glm::vec3 r = v - 2.0f*glm::dot(v, planetNormal) *
|
||||||
//glm::vec3 vn = glm::length(v) * planetNormal;
|
// planetNormal;
|
||||||
//v = (r+vn) / 2.0f;
|
// glm::vec3 vn = glm::length(v) * planetNormal;
|
||||||
|
// v = (r+vn) / 2.0f;
|
||||||
|
|
||||||
//glm::vec3 vc = glm::vec3(nearestPlanet->position-explCenter, 0.0f);
|
// glm::vec3 vc = glm::vec3(nearestPlanet->position-explCenter,
|
||||||
//glm::vec3 r = vc - 2.0f*glm::dot(vc, planetNormal) * planetNormal;
|
// 0.0f);
|
||||||
//v = r;
|
// glm::vec3 r = vc - 2.0f*glm::dot(vc, planetNormal) *
|
||||||
|
// planetNormal;
|
||||||
|
// v = r;
|
||||||
}
|
}
|
||||||
} else if (isInsidePlanet && !isPlanetHit) {
|
} else if (isInsidePlanet && !isPlanetHit) {
|
||||||
// if a planet is just hit by explosions particles but not the
|
// if a planet is just hit by explosions particles but not the
|
||||||
|
@ -404,7 +399,8 @@ namespace endofthejedi {
|
||||||
|
|
||||||
if (makeStationary) {
|
if (makeStationary) {
|
||||||
v = glm::vec3(0.0f, 0.0f, 0.0f);
|
v = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
pos = glm::vec3(explCenter, 0.0f);;
|
pos = glm::vec3(explCenter, 0.0f);
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
batch->setParticle(i, pos, v, maxParticleDist);
|
batch->setParticle(i, pos, v, maxParticleDist);
|
||||||
|
@ -413,10 +409,9 @@ namespace endofthejedi {
|
||||||
batch->upload();
|
batch->upload();
|
||||||
|
|
||||||
m_particles.push_back(batch);
|
m_particles.push_back(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::advanceGraphicObjects(float dt)
|
void RendererPolygon3d::advanceGraphicObjects(float dt) {
|
||||||
{
|
|
||||||
#if 0
|
#if 0
|
||||||
for (const game::Explosion *expl : m_state->explosions) {
|
for (const game::Explosion *expl : m_state->explosions) {
|
||||||
bool gotIt = false;
|
bool gotIt = false;
|
||||||
|
@ -443,49 +438,54 @@ namespace endofthejedi {
|
||||||
|
|
||||||
if (type == game::EventType::Explosion) {
|
if (type == game::EventType::Explosion) {
|
||||||
if (cycle == game::LifeCycle::Create) {
|
if (cycle == game::LifeCycle::Create) {
|
||||||
game::ExplosionEvent *ee = static_cast<game::ExplosionEvent*>(evt);
|
game::ExplosionEvent *ee =
|
||||||
game::Explosion *expl = static_cast<game::Explosion*>(ee->object());
|
static_cast<game::ExplosionEvent *>(evt);
|
||||||
|
game::Explosion *expl =
|
||||||
|
static_cast<game::Explosion *>(ee->object());
|
||||||
|
|
||||||
addExplosionEffect(
|
addExplosionEffect(expl->id, expl->position,
|
||||||
expl->id, expl->position,
|
glm::vec3(expl->missileVelocity, 1.0),
|
||||||
glm::vec3(expl->missileVelocity,1.0),
|
(expl->hit == game::Hit::Planet), 1000, 1.0);
|
||||||
(expl->hit == game::Hit::Planet),
|
|
||||||
1000, 1.0);
|
|
||||||
}
|
}
|
||||||
} else if (type == game::EventType::Ship) {
|
} else if (type == game::EventType::Ship) {
|
||||||
game::ShipEvent *me = static_cast<game::ShipEvent*>(evt);
|
game::ShipEvent *me = static_cast<game::ShipEvent *>(evt);
|
||||||
game::Ship *ship = static_cast<game::Ship*>(me->object());
|
game::Ship *ship = static_cast<game::Ship *>(me->object());
|
||||||
|
|
||||||
// is always modificated
|
// is always modificated
|
||||||
if (cycle == game::LifeCycle::Create) {
|
if (cycle == game::LifeCycle::Create) {
|
||||||
//std::cout<<"[renderer] adding missile #" << missile->id << std::endl;
|
// std::cout<<"[renderer] adding missile #" << missile->id <<
|
||||||
|
// std::endl;
|
||||||
m_ships.push_back(ship);
|
m_ships.push_back(ship);
|
||||||
|
|
||||||
} else if (cycle == game::LifeCycle::Destroy) {
|
} else if (cycle == game::LifeCycle::Destroy) {
|
||||||
//std::cout<<"[renderer] removing missile #" << missile->id << std::endl;
|
// std::cout<<"[renderer] removing missile #" << missile->id <<
|
||||||
|
// std::endl;
|
||||||
m_ships.remove(ship);
|
m_ships.remove(ship);
|
||||||
}
|
}
|
||||||
} else if (type == game::EventType::Missile) {
|
} else if (type == game::EventType::Missile) {
|
||||||
game::MissileEvent *me = static_cast<game::MissileEvent*>(evt);
|
game::MissileEvent *me = static_cast<game::MissileEvent *>(evt);
|
||||||
game::Missile *missile = static_cast<game::Missile*>(me->object());
|
game::Missile *missile = static_cast<game::Missile *>(me->object());
|
||||||
|
|
||||||
// is always modificated
|
// is always modificated
|
||||||
if (cycle == game::LifeCycle::Create) {
|
if (cycle == game::LifeCycle::Create) {
|
||||||
//std::cout<<"[renderer] adding missile #" << missile->id << std::endl;
|
// std::cout<<"[renderer] adding missile #" << missile->id <<
|
||||||
|
// std::endl;
|
||||||
m_missiles.push_back(missile);
|
m_missiles.push_back(missile);
|
||||||
|
|
||||||
} else if (cycle == game::LifeCycle::Destroy) {
|
} else if (cycle == game::LifeCycle::Destroy) {
|
||||||
//std::cout<<"[renderer] removing missile #" << missile->id << std::endl;
|
// std::cout<<"[renderer] removing missile #" << missile->id <<
|
||||||
|
// std::endl;
|
||||||
m_missiles.remove(missile);
|
m_missiles.remove(missile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (m_particles.size() == 0) {
|
// if (m_particles.size() == 0) {
|
||||||
// addExplosionEffect(0, glm::vec2(0.0, 0.0), glm::vec2(0.0, 0.0), false, 10000, 2.0);
|
// addExplosionEffect(0, glm::vec2(0.0, 0.0), glm::vec2(0.0, 0.0), false,
|
||||||
|
// 10000, 2.0);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
std::vector<ParticleBatch*> rm;
|
std::vector<ParticleBatch *> rm;
|
||||||
|
|
||||||
for (ParticleBatch *batch : m_particles) {
|
for (ParticleBatch *batch : m_particles) {
|
||||||
batch->tick(dt);
|
batch->tick(dt);
|
||||||
|
@ -498,7 +498,7 @@ namespace endofthejedi {
|
||||||
m_particles.remove(batch);
|
m_particles.remove(batch);
|
||||||
delete (batch);
|
delete (batch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::renderPlanets() {
|
void RendererPolygon3d::renderPlanets() {
|
||||||
m_planetModel->bind();
|
m_planetModel->bind();
|
||||||
|
@ -520,7 +520,7 @@ void RendererPolygon3d::renderPlanets() {
|
||||||
|
|
||||||
m_planetModel->render();
|
m_planetModel->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::renderSun() {
|
void RendererPolygon3d::renderSun() {
|
||||||
m_planetModel->bind();
|
m_planetModel->bind();
|
||||||
|
@ -555,35 +555,38 @@ void RendererPolygon3d::renderMissiles() {
|
||||||
|
|
||||||
for (const game::Missile *missile : m_missiles) {
|
for (const game::Missile *missile : m_missiles) {
|
||||||
glm::vec3 c = glm::vec3(1.0, 1.0, 0.3);
|
glm::vec3 c = glm::vec3(1.0, 1.0, 0.3);
|
||||||
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z);
|
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y,
|
||||||
|
c.z);
|
||||||
|
|
||||||
// TODO: rename functions so their name represents what args they
|
// TODO: rename functions so their name represents what args they
|
||||||
// take
|
// take
|
||||||
glm::mat4 model = computeModelMatrix(missile);
|
glm::mat4 model = computeModelMatrix(missile);
|
||||||
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE,
|
||||||
|
glm::value_ptr(model));
|
||||||
|
|
||||||
m_missileModel->render();
|
m_missileModel->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::renderShips()
|
void RendererPolygon3d::renderShips() {
|
||||||
{
|
|
||||||
m_shipModel->bind();
|
m_shipModel->bind();
|
||||||
|
|
||||||
for (const game::Ship *ship : m_ships) {
|
for (const game::Ship *ship : m_ships) {
|
||||||
glm::mat4 model = computeModelMatrix(ship);
|
glm::mat4 model = computeModelMatrix(ship);
|
||||||
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE,
|
||||||
|
glm::value_ptr(model));
|
||||||
|
|
||||||
glm::vec3 c = glm::vec3(0.1, 1.0, 0.2);
|
glm::vec3 c = glm::vec3(0.1, 1.0, 0.2);
|
||||||
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z);
|
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y,
|
||||||
|
c.z);
|
||||||
|
|
||||||
m_shipModel->render();
|
m_shipModel->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::addModel(const std::string &filename, PolygonModel **dest)
|
void RendererPolygon3d::addModel(const std::string &filename,
|
||||||
{
|
PolygonModel **dest) {
|
||||||
//std::cout<<"adding a model: " << filename << std::endl;
|
// std::cout<<"adding a model: " << filename << std::endl;
|
||||||
|
|
||||||
*dest = new PolygonModel(filename);
|
*dest = new PolygonModel(filename);
|
||||||
if (!(*dest)->import()) {
|
if (!(*dest)->import()) {
|
||||||
|
@ -606,15 +609,13 @@ void RendererPolygon3d::renderMissiles() {
|
||||||
(*dest)->uploadToOpenGl();
|
(*dest)->uploadToOpenGl();
|
||||||
|
|
||||||
m_models.push_back(*dest);
|
m_models.push_back(*dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 RendererPolygon3d::computeModelMatrix(const game::Planet *planet)
|
glm::mat4 RendererPolygon3d::computeModelMatrix(const game::Planet *planet) {
|
||||||
{
|
|
||||||
return computeModelMatrix(planet->position, planet->radius);
|
return computeModelMatrix(planet->position, planet->radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 RendererPolygon3d::computeModelMatrix(const game::Missile *missile)
|
glm::mat4 RendererPolygon3d::computeModelMatrix(const game::Missile *missile) {
|
||||||
{
|
|
||||||
glm::vec2 vn = glm::normalize(missile->velocity);
|
glm::vec2 vn = glm::normalize(missile->velocity);
|
||||||
float a = std::atan2(vn.y, vn.x);
|
float a = std::atan2(vn.y, vn.x);
|
||||||
|
|
||||||
|
@ -622,28 +623,27 @@ void RendererPolygon3d::renderMissiles() {
|
||||||
|
|
||||||
// TODO: which visual size has the rocket? in game its just a point with
|
// TODO: which visual size has the rocket? in game its just a point with
|
||||||
// no size because all others have size.
|
// no size because all others have size.
|
||||||
//for atomic bomb
|
// for atomic bomb
|
||||||
//return computeModelMatrix(missile->position, 0.03f, a);
|
// return computeModelMatrix(missile->position, 0.03f, a);
|
||||||
|
|
||||||
// flipped too
|
// flipped too
|
||||||
mat = glm::rotate(mat, (float) M_PI/2.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
mat = glm::rotate(mat, (float)M_PI / 2.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 RendererPolygon3d::computeModelMatrix(const game::Ship *ship)
|
glm::mat4 RendererPolygon3d::computeModelMatrix(const game::Ship *ship) {
|
||||||
{
|
|
||||||
// TODO: rotate them before shooting, that looks better
|
// TODO: rotate them before shooting, that looks better
|
||||||
glm::mat4 mat = computeModelMatrix(ship->position, m_state->shipRadius());
|
glm::mat4 mat = computeModelMatrix(ship->position, m_state->shipRadius());
|
||||||
|
|
||||||
// XXX model is flipped
|
// XXX model is flipped
|
||||||
//glm::mat4 mat = computeModelMatrix(ship->position, 0.3);
|
// glm::mat4 mat = computeModelMatrix(ship->position, 0.3);
|
||||||
mat = glm::rotate(mat, (float) M_PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
mat = glm::rotate(mat, (float)M_PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 RendererPolygon3d::computeModelMatrix(const glm::vec2 &pos, float scale, float angle)
|
glm::mat4 RendererPolygon3d::computeModelMatrix(const glm::vec2 &pos,
|
||||||
{
|
float scale, float angle) {
|
||||||
// init as identity matrix
|
// init as identity matrix
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
|
|
||||||
|
@ -658,33 +658,33 @@ void RendererPolygon3d::renderMissiles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::renderTraces()
|
void RendererPolygon3d::renderTraces() {
|
||||||
{
|
|
||||||
// revert to default
|
// revert to default
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
|
|
||||||
// TODO dont use line mode. make that with own quads
|
// TODO dont use line mode. make that with own quads
|
||||||
glPolygonMode(GL_FRONT, GL_LINE);
|
glPolygonMode(GL_FRONT, GL_LINE);
|
||||||
|
glLineWidth(2.0f);
|
||||||
for (const game::Trace *trace : m_state->traces) {
|
for (const game::Trace *trace : m_state->traces) {
|
||||||
float fade_out = 1.0;
|
float fade_out = 1.0;
|
||||||
if (trace->missile == nullptr) {
|
if (trace->missile == nullptr) {
|
||||||
fade_out = 1.0 - (trace->age / trace->maxAge);
|
fade_out = 1.0 - (trace->age / trace->maxAge);
|
||||||
}
|
}
|
||||||
|
|
||||||
glColor3f(0.0, 0.5*fade_out, 0.5*fade_out);
|
glColor3f(0.0, 0.5 * fade_out, 0.5 * fade_out);
|
||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
for (const game::Trace::TracePoint &tp : trace->points) {
|
for (const game::Trace::TracePoint &tp : trace->points) {
|
||||||
glVertex2f(tp.position.x, tp.position.y);
|
glVertex2f(tp.position.x, tp.position.y);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
glLineWidth(1.0f);
|
||||||
glPolygonMode(GL_FRONT, GL_FILL);
|
glPolygonMode(GL_FRONT, GL_FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::configureLightningInShader(Shader *shader) const
|
void RendererPolygon3d::configureLightningInShader(Shader *shader) const {
|
||||||
{
|
|
||||||
// TODO: add a few small lights for explosions so they lit the
|
// TODO: add a few small lights for explosions so they lit the
|
||||||
// surroundsings
|
// surroundsings
|
||||||
|
|
||||||
|
@ -715,7 +715,7 @@ void RendererPolygon3d::renderMissiles() {
|
||||||
// /\__
|
// /\__
|
||||||
// _/ \--____
|
// _/ \--____
|
||||||
|
|
||||||
float intensity = 1.0-age;
|
float intensity = 1.0 - age;
|
||||||
glm::vec3 p = batch->explosionCenter();
|
glm::vec3 p = batch->explosionCenter();
|
||||||
|
|
||||||
intensities.push_back(intensity);
|
intensities.push_back(intensity);
|
||||||
|
@ -728,22 +728,21 @@ void RendererPolygon3d::renderMissiles() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform1i( shader->location("explLightsNum"), numExplLights);
|
glUniform1i(shader->location("explLightsNum"), numExplLights);
|
||||||
|
|
||||||
if (numExplLights != 0) {
|
if (numExplLights != 0) {
|
||||||
glUniform3fv(shader->location("explLightsPos"), numExplLights, glm::value_ptr(positions[0]));
|
glUniform3fv(shader->location("explLightsPos"), numExplLights,
|
||||||
glUniform1fv(shader->location("explLightsIntensities"), numExplLights, intensities.data());
|
glm::value_ptr(positions[0]));
|
||||||
}
|
glUniform1fv(shader->location("explLightsIntensities"), numExplLights,
|
||||||
|
intensities.data());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::setWindowSize(int px, int py) {
|
void RendererPolygon3d::setWindowSize(int px, int py) {
|
||||||
m_aspectRatio = (float)px / (float)py;
|
m_aspectRatio = (float)px / (float)py;
|
||||||
m_w = px;
|
m_w = px;
|
||||||
m_h = py;
|
m_h = py;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::setCameraMatrix(const glm::mat4 &cam)
|
void RendererPolygon3d::setCameraMatrix(const glm::mat4 &cam) { (void)cam; }
|
||||||
{
|
|
||||||
(void) cam;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue