tavli

view 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
line source
1 #include "object.h"
2 #include "opengl.h"
4 Object::Object()
5 {
6 mesh = 0;
7 tex = 0;
8 }
10 Object::~Object()
11 {
12 delete mesh;
13 }
15 Matrix4x4 &Object::xform()
16 {
17 return matrix;
18 }
20 const Matrix4x4 &Object::xform() const
21 {
22 return matrix;
23 }
25 void Object::set_mesh(Mesh *m)
26 {
27 this->mesh = m;
28 }
30 Mesh *Object::get_mesh() const
31 {
32 return mesh;
33 }
35 void Object::set_texture(unsigned int tex)
36 {
37 this->tex = tex;
38 }
40 void Object::draw() const
41 {
42 if(!mesh) return;
44 if(tex) {
45 glBindTexture(GL_TEXTURE_2D, tex);
46 glEnable(GL_TEXTURE_2D);
47 } else {
48 glDisable(GL_TEXTURE_2D);
49 }
51 glMatrixMode(GL_MODELVIEW);
52 glPushMatrix();
53 glMultTransposeMatrixf(matrix[0]);
55 mesh->draw();
57 glPopMatrix();
59 if(tex) {
60 glDisable(GL_TEXTURE_2D);
61 }
62 }
64 bool Object::intersect(const Ray &ray, HitPoint *hit) const
65 {
66 return false; // TODO
67 }