tavli

diff src/object.cc @ 6:a0d30f6f20d4

- texture coordinate generation in class Mesh - wood texture
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 26 Jun 2015 04:22:06 +0300
parents b41ceead1708
children a8e26f163f99
line diff
     1.1 --- a/src/object.cc	Thu Jun 25 20:43:34 2015 +0300
     1.2 +++ b/src/object.cc	Fri Jun 26 04:22:06 2015 +0300
     1.3 @@ -5,6 +5,11 @@
     1.4  {
     1.5  	mesh = 0;
     1.6  	tex = 0;
     1.7 +
     1.8 +	mtl.diffuse = Vector3(1, 1, 1);
     1.9 +	mtl.specular = Vector3(0, 0, 0);
    1.10 +	mtl.shininess = 60.0;
    1.11 +	mtl.alpha = 1.0;
    1.12  }
    1.13  
    1.14  Object::~Object()
    1.15 @@ -22,6 +27,16 @@
    1.16  	return matrix;
    1.17  }
    1.18  
    1.19 +Matrix4x4 &Object::tex_xform()
    1.20 +{
    1.21 +	return tex_matrix;
    1.22 +}
    1.23 +
    1.24 +const Matrix4x4 &Object::tex_xform() const
    1.25 +{
    1.26 +	return tex_matrix;
    1.27 +}
    1.28 +
    1.29  void Object::set_mesh(Mesh *m)
    1.30  {
    1.31  	this->mesh = m;
    1.32 @@ -44,6 +59,10 @@
    1.33  	if(tex) {
    1.34  		glBindTexture(GL_TEXTURE_2D, tex);
    1.35  		glEnable(GL_TEXTURE_2D);
    1.36 +
    1.37 +		glMatrixMode(GL_TEXTURE);
    1.38 +		glPushMatrix();
    1.39 +		glLoadTransposeMatrixf(tex_matrix[0]);
    1.40  	} else {
    1.41  		glDisable(GL_TEXTURE_2D);
    1.42  	}
    1.43 @@ -52,13 +71,23 @@
    1.44  	glPushMatrix();
    1.45  	glMultTransposeMatrixf(matrix[0]);
    1.46  
    1.47 +	float dcol[] = {mtl.diffuse.x, mtl.diffuse.y, mtl.diffuse.z, mtl.alpha};
    1.48 +	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dcol);
    1.49 +	float scol[] = {mtl.specular.x, mtl.specular.y, mtl.specular.z, 1.0f};
    1.50 +	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, scol);
    1.51 +	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mtl.shininess);
    1.52 +
    1.53  	mesh->draw();
    1.54  
    1.55 -	glPopMatrix();
    1.56 -
    1.57  	if(tex) {
    1.58  		glDisable(GL_TEXTURE_2D);
    1.59 +
    1.60 +		glMatrixMode(GL_TEXTURE);
    1.61 +		glPopMatrix();
    1.62  	}
    1.63 +
    1.64 +	glMatrixMode(GL_MODELVIEW);
    1.65 +	glPopMatrix();
    1.66  }
    1.67  
    1.68  bool Object::intersect(const Ray &ray, HitPoint *hit) const