From d289e0eacbd00538ee2bcaedeba4366cc1e98231 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 12 Jun 2011 17:52:31 +0200 Subject: Handle and render players with a placeholder texture. --- player.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 player.cpp (limited to 'player.cpp') diff --git a/player.cpp b/player.cpp new file mode 100644 index 0000000..a65e8fa --- /dev/null +++ b/player.cpp @@ -0,0 +1,92 @@ +#include "player.h" + +#include + +Player::Player(uint32_t id, Vector3& pos, std::string name) { + this->id = id; + this->pos = pos; + this->name = name; + + t = 0.0; +} + +uint32_t Player::get_id() { + return id; +} + +std::string Player::get_name() { + return name; +} + +Vector3 Player::get_pos() { + return pos; +} + +void Player::set_pos(Vector3& pos) { + this->pos = pos; +} + +// TODO: find a sane way to do this +void Player::render(FTFont *font, unsigned int steps, GLuint texture) { + glPushMatrix(); + glTranslatef(pos.x, pos.y, pos.z); + + // billboarding setup + float modelview[16]; + glGetFloatv(GL_MODELVIEW_MATRIX, modelview); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + modelview[i*4+j] = i == j ? 1 : 0; + glLoadMatrixf(modelview); + + // text rendering + glPushMatrix(); + // probably not the best way to do calculate the text position, but it's accurate enough + FTBBox box = font->BBox(name.c_str()); + FTPoint l = box.Lower(); + FTPoint u = box.Upper(); + float len = (Vector3(l.Xf(), l.Yf(), l.Zf()) - Vector3(u.Xf(), u.Yf(), u.Zf())).length(); + // simplified from -len/72/2 + len/72/8 + glTranslatef(-len/192, 2.1, 0); + glScalef(.01, .01, .01); + + // make the text visible through terrain + glDisable(GL_DEPTH_TEST); + font->Render(name.c_str()); + glEnable(GL_DEPTH_TEST); + glPopMatrix(); + + // GL_COLOR_BUFFER_BIT saves blending function + glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); + glBlendFunc(GL_ONE, GL_ONE); + glEnable(GL_BLEND); + t -= 0.0002 * steps; + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture); + + // quad with scrolling texture + glBegin(GL_QUADS); + glTexCoord2f(fmodf(t, 1) + .16, 1); + glVertex3f(-1, 0, 0); + + glTexCoord2f(fmodf(t, 1), 1); + glVertex3f(1, 0, 0); + + glTexCoord2f(fmodf(t, 1), 0); + glVertex3f(1, 2, 0); + + glTexCoord2f(fmodf(t, 1) + .16, 0); + glVertex3f(-1, 2, 0); + glEnd(); + + glPopAttrib(); + + glBegin(GL_LINE_LOOP); + glVertex3f(-1, 0, .01); + glVertex3f(1, 0, .01); + glVertex3f(1, 2, .01); + glVertex3f(-1, 2, .01); + glEnd(); + + glPopMatrix(); // position translate +} -- cgit v1.2.3