summaryrefslogtreecommitdiff
path: root/player.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-06-12 17:52:31 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-06-12 17:52:31 +0200
commitd289e0eacbd00538ee2bcaedeba4366cc1e98231 (patch)
tree16d49421b24520c1728149f96a63635340e2e4a2 /player.cpp
parentd94e9e78af4e59e27524556b828291c1dfb72407 (diff)
Handle and render players with a placeholder texture.
Diffstat (limited to 'player.cpp')
-rw-r--r--player.cpp92
1 files changed, 92 insertions, 0 deletions
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 <cmath>
+
+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
+}