rotations working :)
This commit is contained in:
parent
07437fac3c
commit
3b5b5da02f
2 changed files with 16 additions and 12 deletions
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#define QUICK_TEST
|
||||||
|
|
||||||
Game::Game()
|
Game::Game()
|
||||||
{
|
{
|
||||||
// advance simulation in fixed steps with 100 Hz
|
// advance simulation in fixed steps with 100 Hz
|
||||||
|
@ -46,7 +48,7 @@ bool Game::cycle(float dt)
|
||||||
while (acc > spawnInterval) {
|
while (acc > spawnInterval) {
|
||||||
acc -= spawnInterval;
|
acc -= spawnInterval;
|
||||||
|
|
||||||
float angle = 2.0 * M_PI * util::randf_0_1();
|
float angle = 360.0 * util::randf_0_1();
|
||||||
float speed = 0.005;
|
float speed = 0.005;
|
||||||
|
|
||||||
m_state->players[0]->addCommand(new game::SetSpeedCommand(speed));
|
m_state->players[0]->addCommand(new game::SetSpeedCommand(speed));
|
||||||
|
|
|
@ -39,18 +39,17 @@ namespace endofthejedi {
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
//"uniform mat4 model;\n"
|
|
||||||
//" vec3 p = position + scale*(model*vec4(gl_Vertex.xyz, 0.0));\n"
|
|
||||||
|
|
||||||
std::string vss_game_objects =
|
std::string vss_game_objects =
|
||||||
"#version 120\n"
|
"#version 120\n"
|
||||||
"uniform vec3 position;\n"
|
"uniform vec3 position;\n"
|
||||||
"uniform float scale;\n"
|
"uniform float scale;\n"
|
||||||
"varying vec3 vertex;\n"
|
"varying vec3 vertex;\n"
|
||||||
|
"uniform mat4 model;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec3 p = position + scale*gl_Vertex.xyz;\n"
|
//" vec3 p = position + scale*gl_Vertex.xyz;\n"
|
||||||
" gl_Position = vec4(p, gl_Vertex.w);\n"
|
" vec3 p = position + scale*(model*gl_Vertex).xyz;\n"
|
||||||
|
" gl_Position = vec4(p, 1.0);\n"
|
||||||
" vertex = p.xyz;\n"
|
" vertex = p.xyz;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
|
@ -88,9 +87,6 @@ namespace endofthejedi {
|
||||||
|
|
||||||
// TODO :Z?
|
// TODO :Z?
|
||||||
|
|
||||||
glm::mat4 model(1.0f);
|
|
||||||
glUniformMatrix3fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
|
||||||
|
|
||||||
renderPlanets(state);
|
renderPlanets(state);
|
||||||
renderShips(state);
|
renderShips(state);
|
||||||
renderMissiles(state);
|
renderMissiles(state);
|
||||||
|
@ -112,6 +108,9 @@ namespace endofthejedi {
|
||||||
glm::vec3 c = glm::vec3(0.7, 0.2, 0.1);
|
glm::vec3 c = glm::vec3(0.7, 0.2, 0.1);
|
||||||
const auto &p = planet->position;
|
const auto &p = planet->position;
|
||||||
|
|
||||||
|
glm::mat4 model(1.0f);
|
||||||
|
glUniformMatrix4fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
||||||
|
|
||||||
glUniform3f(m_shader.location("position"), p.x, p.y, 0.0);
|
glUniform3f(m_shader.location("position"), p.x, p.y, 0.0);
|
||||||
glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
|
glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
|
||||||
glUniform1f(m_shader.location("scale"), planet->radius);
|
glUniform1f(m_shader.location("scale"), planet->radius);
|
||||||
|
@ -132,15 +131,15 @@ namespace endofthejedi {
|
||||||
glm::mat4 model(1.0f);
|
glm::mat4 model(1.0f);
|
||||||
|
|
||||||
static float a = 0.0;
|
static float a = 0.0;
|
||||||
a += 2.0*M_PI * 0.1;
|
a += 2.0*M_PI * 0.01;
|
||||||
|
|
||||||
model = glm::rotate(model, a, glm::vec3(0.0f, 1.0f, 0.0f));
|
model = glm::rotate(model, a, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
glUniform3f(m_shader.location("position"), p.x, p.y, 0.0);
|
glUniform3f(m_shader.location("position"), p.x, p.y, 0.0);
|
||||||
glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
|
glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
|
||||||
glUniform1f(m_shader.location("scale"), 0.05);
|
glUniform1f(m_shader.location("scale"), 0.05);
|
||||||
|
|
||||||
glUniformMatrix3fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
glUniformMatrix4fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
||||||
|
|
||||||
m_missileModel->render();
|
m_missileModel->render();
|
||||||
}
|
}
|
||||||
|
@ -155,6 +154,9 @@ namespace endofthejedi {
|
||||||
glm::vec3 c = glm::vec3(0.1, 1.0, 0.2);
|
glm::vec3 c = glm::vec3(0.1, 1.0, 0.2);
|
||||||
const auto &p = ship->position;
|
const auto &p = ship->position;
|
||||||
|
|
||||||
|
glm::mat4 model(1.0f);
|
||||||
|
glUniformMatrix4fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
||||||
|
|
||||||
glUniform3f(m_shader.location("position"), p.x, p.y, 0.0);
|
glUniform3f(m_shader.location("position"), p.x, p.y, 0.0);
|
||||||
glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
|
glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
|
||||||
glUniform1f(m_shader.location("scale"), 0.02);
|
glUniform1f(m_shader.location("scale"), 0.02);
|
||||||
|
|
Loading…
Reference in a new issue