try to get rotation model matrix working.

This commit is contained in:
Andreas Ortmann 2016-09-28 15:10:57 +02:00
parent 35cbd01a52
commit 07437fac3c
3 changed files with 29 additions and 10 deletions

View file

@ -15,11 +15,16 @@ Game::Game()
m_state = new game::State(); m_state = new game::State();
m_state->init(); m_state->init();
// XXX
// one dummy ship for testing
#ifdef QUICK_TEST
m_state->addPlayer();
#endif
} }
bool Game::cycle(float dt) bool Game::cycle(float dt)
{ {
#if 0 #ifdef QUICK_TEST
// XXX the following is just testing code to do things // XXX the following is just testing code to do things
static float total = 0.0; static float total = 0.0;
@ -33,12 +38,11 @@ bool Game::cycle(float dt)
// m_state->players[0]->addCommand(new game::ShootCommand(a)); // m_state->players[0]->addCommand(new game::ShootCommand(a));
// } // }
//} //}
m_state->addPlayer();
acc += dt; acc += dt;
total += dt; total += dt;
float spawnInterval = 0.1; float spawnInterval = 1.0;
while (acc > spawnInterval) { while (acc > spawnInterval) {
acc -= spawnInterval; acc -= spawnInterval;

View file

@ -202,7 +202,8 @@ class PolygonModel {
} }
size_t totalBytes = 3*m_numVertices*sizeof(float); size_t totalBytes = 3*m_numVertices*sizeof(float);
std::cout<<"[polygonmodel] loaded " << m_numVertices << " vertices (" std::cout<<"[polygonmodel] loaded file " << m_filename
<< " with " << m_numVertices << " vertices ("
<< totalBytes << " bytes)" << std::endl; << totalBytes << " bytes)" << std::endl;
return true; return true;

View file

@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
#include "glm/gtc/type_ptr.hpp" #include "glm/gtc/type_ptr.hpp"
#include <glm/gtc/matrix_transform.hpp>
#include "polygon_model.hpp" #include "polygon_model.hpp"
@ -38,6 +39,9 @@ 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"
@ -45,10 +49,9 @@ namespace endofthejedi {
"varying vec3 vertex;\n" "varying vec3 vertex;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" vec3 p = scale*gl_Vertex.xyz;\n" " vec3 p = position + scale*gl_Vertex.xyz;\n"
" p += position;\n"
" gl_Position = vec4(p, gl_Vertex.w);\n" " gl_Position = vec4(p, gl_Vertex.w);\n"
" vertex = p;\n" " vertex = p.xyz;\n"
"}\n" "}\n"
; ;
@ -85,11 +88,13 @@ 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);
//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);
@ -124,9 +129,18 @@ namespace endofthejedi {
glm::vec3 c = glm::vec3(1.0, 1.0, 0.3); glm::vec3 c = glm::vec3(1.0, 1.0, 0.3);
const auto &p = missile->position; const auto &p = missile->position;
glm::mat4 model(1.0f);
static float a = 0.0;
a += 2.0*M_PI * 0.1;
model = glm::rotate(model, a, glm::vec3(0.0f, 1.0f, 0.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"), 1.0); glUniform1f(m_shader.location("scale"), 0.05);
glUniformMatrix3fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model));
m_missileModel->render(); m_missileModel->render();
} }
@ -151,7 +165,7 @@ namespace endofthejedi {
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()) {