positioning with shaders working, normals not
This commit is contained in:
parent
4a6d38ddb9
commit
cfa2850292
@ -110,18 +110,22 @@ void Client::run()
|
||||
update(elapsed_time);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
double dir_x = cos(m_player->direction);
|
||||
double dir_y = sin(m_player->direction);
|
||||
glLoadIdentity();
|
||||
gluLookAt(m_player->x - dir_x * 100, m_player->y - dir_y * 100, 150,
|
||||
m_player->x, m_player->y, 100,
|
||||
0, 0, 1);
|
||||
|
||||
m_modelview.load_identity();
|
||||
m_modelview.look_at(
|
||||
m_player->x - dir_x * 100, m_player->y - dir_y * 100, 150,
|
||||
m_player->x, m_player->y, 100,
|
||||
0, 0, 1);
|
||||
|
||||
draw_players();
|
||||
draw_map();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
m_window->display();
|
||||
last_time = current_time;
|
||||
}
|
||||
@ -144,9 +148,10 @@ void Client::resize_window(int width, int height)
|
||||
float aspect = (float)width / (float)height;
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60.0f, aspect, 0.01, 5000.0);
|
||||
gluPerspective(60.0f, aspect, 1.0f, 5000.0f);
|
||||
m_projection.load_identity();
|
||||
m_projection.perspective(60.0f, aspect, 1.0f, 5000.0f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
void Client::update(double elapsed_time)
|
||||
@ -183,12 +188,12 @@ void Client::update(double elapsed_time)
|
||||
|
||||
void Client::draw_players()
|
||||
{
|
||||
GLint uniform_locations[5];
|
||||
const char *uniforms[] = { "ambient", "diffuse", "specular", "shininess", "scale" };
|
||||
m_obj_program.get_uniform_locations(uniforms, 5, uniform_locations);
|
||||
glPushMatrix();
|
||||
glTranslatef(m_player->x, m_player->y, 40);
|
||||
glRotatef(m_player->direction * 180.0 / M_PI, 0, 0, 1);
|
||||
GLint uniform_locations[7];
|
||||
const char *uniforms[] = { "ambient", "diffuse", "specular", "shininess", "scale", "projection", "modelview" };
|
||||
m_obj_program.get_uniform_locations(uniforms, 7, uniform_locations);
|
||||
m_modelview.push();
|
||||
m_modelview.translate(m_player->x, m_player->y, 40);
|
||||
m_modelview.rotate(m_player->direction * 180.0 / M_PI, 0, 0, 1);
|
||||
glUseProgram(m_obj_program.get_id());
|
||||
m_tank_obj.bindBuffers();
|
||||
glEnableVertexAttribArray(0);
|
||||
@ -199,6 +204,8 @@ void Client::draw_players()
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
|
||||
stride, (GLvoid *) m_tank_obj.getNormalOffset());
|
||||
glUniform1f(uniform_locations[4], 20.0f);
|
||||
m_projection.to_uniform(uniform_locations[5]);
|
||||
m_modelview.to_uniform(uniform_locations[6]);
|
||||
for (map<string, WFObj::Material>::iterator it =
|
||||
m_tank_obj.getMaterials().begin();
|
||||
it != m_tank_obj.getMaterials().end();
|
||||
@ -228,7 +235,7 @@ void Client::draw_players()
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
glUseProgram(0);
|
||||
glPopMatrix();
|
||||
m_modelview.pop();
|
||||
}
|
||||
|
||||
void Client::draw_map()
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "Player.h"
|
||||
#include "GLProgram.h"
|
||||
#include "WFObj.h"
|
||||
#include "GLMatrix.h"
|
||||
|
||||
class Client
|
||||
{
|
||||
@ -29,6 +30,8 @@ class Client
|
||||
int m_height;
|
||||
GLProgram m_obj_program;
|
||||
WFObj m_tank_obj;
|
||||
GLMatrix m_projection;
|
||||
GLMatrix m_modelview;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -148,13 +148,13 @@ void GLMatrix::look_at(GLfloat eye_x, GLfloat eye_y, GLfloat eye_z,
|
||||
cross(up, side, forward);
|
||||
GLMatrix mult;
|
||||
mult.m_mat[0][0] = side[0];
|
||||
mult.m_mat[0][1] = side[1];
|
||||
mult.m_mat[0][2] = side[2];
|
||||
mult.m_mat[1][0] = up[0];
|
||||
mult.m_mat[1][0] = side[1];
|
||||
mult.m_mat[2][0] = side[2];
|
||||
mult.m_mat[0][1] = up[0];
|
||||
mult.m_mat[1][1] = up[1];
|
||||
mult.m_mat[1][2] = up[2];
|
||||
mult.m_mat[2][0] = -forward[0];
|
||||
mult.m_mat[2][1] = -forward[1];
|
||||
mult.m_mat[2][1] = up[2];
|
||||
mult.m_mat[0][2] = -forward[0];
|
||||
mult.m_mat[1][2] = -forward[1];
|
||||
mult.m_mat[2][2] = -forward[2];
|
||||
multiply(mult);
|
||||
translate(-eye_x, -eye_y, -eye_z);
|
||||
@ -194,7 +194,7 @@ void GLMatrix::ortho(GLfloat left, GLfloat right,
|
||||
|
||||
void GLMatrix::to_uniform(GLint uniform)
|
||||
{
|
||||
glUniformMatrix4fv(uniform, 1, GL_TRUE, &m_mat[0][0]);
|
||||
glUniformMatrix4fv(uniform, 1, GL_FALSE, &m_mat[0][0]);
|
||||
}
|
||||
|
||||
void GLMatrix::push()
|
||||
|
Loading…
x
Reference in New Issue
Block a user