tavli

view src/object.cc @ 9:8a167149985d

unused var
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 26 Jun 2015 05:34:01 +0300
parents b41ceead1708
children a8e26f163f99
line source
1 #include "object.h"
2 #include "opengl.h"
4 Object::Object()
5 {
6 mesh = 0;
7 tex = 0;
9 mtl.diffuse = Vector3(1, 1, 1);
10 mtl.specular = Vector3(0, 0, 0);
11 mtl.shininess = 60.0;
12 mtl.alpha = 1.0;
13 }
15 Object::~Object()
16 {
17 delete mesh;
18 }
20 Matrix4x4 &Object::xform()
21 {
22 return matrix;
23 }
25 const Matrix4x4 &Object::xform() const
26 {
27 return matrix;
28 }
30 Matrix4x4 &Object::tex_xform()
31 {
32 return tex_matrix;
33 }
35 const Matrix4x4 &Object::tex_xform() const
36 {
37 return tex_matrix;
38 }
40 void Object::set_mesh(Mesh *m)
41 {
42 this->mesh = m;
43 }
45 Mesh *Object::get_mesh() const
46 {
47 return mesh;
48 }
50 void Object::set_texture(unsigned int tex)
51 {
52 this->tex = tex;
53 }
55 void Object::draw() const
56 {
57 if(!mesh) return;
59 if(tex) {
60 glBindTexture(GL_TEXTURE_2D, tex);
61 glEnable(GL_TEXTURE_2D);
63 glMatrixMode(GL_TEXTURE);
64 glPushMatrix();
65 glLoadTransposeMatrixf(tex_matrix[0]);
66 } else {
67 glDisable(GL_TEXTURE_2D);
68 }
70 glMatrixMode(GL_MODELVIEW);
71 glPushMatrix();
72 glMultTransposeMatrixf(matrix[0]);
74 float dcol[] = {mtl.diffuse.x, mtl.diffuse.y, mtl.diffuse.z, mtl.alpha};
75 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dcol);
76 float scol[] = {mtl.specular.x, mtl.specular.y, mtl.specular.z, 1.0f};
77 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, scol);
78 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mtl.shininess);
80 mesh->draw();
82 if(tex) {
83 glDisable(GL_TEXTURE_2D);
85 glMatrixMode(GL_TEXTURE);
86 glPopMatrix();
87 }
89 glMatrixMode(GL_MODELVIEW);
90 glPopMatrix();
91 }
93 bool Object::intersect(const Ray &ray, HitPoint *hit) const
94 {
95 return false; // TODO
96 }