tavli
annotate src/object.cc @ 4:b41ceead1708
procedural playing field texture mask
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 25 Jun 2015 05:58:35 +0300 |
parents | 94aff2ff1934 |
children | a0d30f6f20d4 |
rev | line source |
---|---|
nuclear@1 | 1 #include "object.h" |
nuclear@1 | 2 #include "opengl.h" |
nuclear@1 | 3 |
nuclear@1 | 4 Object::Object() |
nuclear@1 | 5 { |
nuclear@1 | 6 mesh = 0; |
nuclear@4 | 7 tex = 0; |
nuclear@1 | 8 } |
nuclear@1 | 9 |
nuclear@1 | 10 Object::~Object() |
nuclear@1 | 11 { |
nuclear@1 | 12 delete mesh; |
nuclear@1 | 13 } |
nuclear@1 | 14 |
nuclear@1 | 15 Matrix4x4 &Object::xform() |
nuclear@1 | 16 { |
nuclear@1 | 17 return matrix; |
nuclear@1 | 18 } |
nuclear@1 | 19 |
nuclear@1 | 20 const Matrix4x4 &Object::xform() const |
nuclear@1 | 21 { |
nuclear@1 | 22 return matrix; |
nuclear@1 | 23 } |
nuclear@1 | 24 |
nuclear@1 | 25 void Object::set_mesh(Mesh *m) |
nuclear@1 | 26 { |
nuclear@1 | 27 this->mesh = m; |
nuclear@1 | 28 } |
nuclear@1 | 29 |
nuclear@1 | 30 Mesh *Object::get_mesh() const |
nuclear@1 | 31 { |
nuclear@1 | 32 return mesh; |
nuclear@1 | 33 } |
nuclear@1 | 34 |
nuclear@4 | 35 void Object::set_texture(unsigned int tex) |
nuclear@4 | 36 { |
nuclear@4 | 37 this->tex = tex; |
nuclear@4 | 38 } |
nuclear@4 | 39 |
nuclear@1 | 40 void Object::draw() const |
nuclear@1 | 41 { |
nuclear@1 | 42 if(!mesh) return; |
nuclear@1 | 43 |
nuclear@4 | 44 if(tex) { |
nuclear@4 | 45 glBindTexture(GL_TEXTURE_2D, tex); |
nuclear@4 | 46 glEnable(GL_TEXTURE_2D); |
nuclear@4 | 47 } else { |
nuclear@4 | 48 glDisable(GL_TEXTURE_2D); |
nuclear@4 | 49 } |
nuclear@4 | 50 |
nuclear@1 | 51 glMatrixMode(GL_MODELVIEW); |
nuclear@1 | 52 glPushMatrix(); |
nuclear@2 | 53 glMultTransposeMatrixf(matrix[0]); |
nuclear@1 | 54 |
nuclear@1 | 55 mesh->draw(); |
nuclear@1 | 56 |
nuclear@1 | 57 glPopMatrix(); |
nuclear@4 | 58 |
nuclear@4 | 59 if(tex) { |
nuclear@4 | 60 glDisable(GL_TEXTURE_2D); |
nuclear@4 | 61 } |
nuclear@1 | 62 } |
nuclear@3 | 63 |
nuclear@3 | 64 bool Object::intersect(const Ray &ray, HitPoint *hit) const |
nuclear@3 | 65 { |
nuclear@3 | 66 return false; // TODO |
nuclear@3 | 67 } |