rayzor

diff src/object.cc @ 12:d94a69933a71

lots of stuff, can't remember
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 12 Apr 2014 23:28:24 +0300
parents 70e332156d02
children a9a948809c6f
line diff
     1.1 --- a/src/object.cc	Thu Apr 10 08:42:33 2014 +0300
     1.2 +++ b/src/object.cc	Sat Apr 12 23:28:24 2014 +0300
     1.3 @@ -5,12 +5,25 @@
     1.4  
     1.5  Object::Object()
     1.6  {
     1.7 +	type = NODE_OBJECT;
     1.8  }
     1.9  
    1.10  Object::~Object()
    1.11  {
    1.12  }
    1.13  
    1.14 +void Object::pre_draw() const
    1.15 +{
    1.16 +	m3d_matrix_mode(M3D_MODELVIEW);
    1.17 +	m3d_push_matrix();
    1.18 +	m3d_mult_matrix(get_matrix()[0]);
    1.19 +}
    1.20 +
    1.21 +void Object::post_draw() const
    1.22 +{
    1.23 +	m3d_pop_matrix();
    1.24 +}
    1.25 +
    1.26  // ---- sphere ----
    1.27  Sphere::Sphere()
    1.28  {
    1.29 @@ -45,7 +58,7 @@
    1.30  				float theta = u * M_PI * 2.0;
    1.31  
    1.32  				float x = sin(theta) * sin(phi);
    1.33 -				float y = cos(phi);
    1.34 +				float y = -cos(phi);
    1.35  				float z = cos(theta) * sin(phi);
    1.36  
    1.37  				*vptr++ = Vector3(x, y, z);
    1.38 @@ -71,9 +84,70 @@
    1.39  		printlog("  quads: %d (%d indices, %d usub, %d vsub)\n", USUB * VSUB, num_indices, USUB, VSUB);
    1.40  	}
    1.41  
    1.42 -	m3d_color(1, 1, 1);
    1.43 +	pre_draw();
    1.44  
    1.45  	m3d_vertex_array(&varr->x);
    1.46  	m3d_draw_indexed(M3D_QUADS, iarr, num_indices);
    1.47  	m3d_vertex_array(0);
    1.48 +
    1.49 +	post_draw();
    1.50  }
    1.51 +
    1.52 +bool Sphere::intersect(const Ray &ray, float *dist) const
    1.53 +{
    1.54 +	return false;	// TODO
    1.55 +}
    1.56 +
    1.57 +// ---- box ----
    1.58 +
    1.59 +Box::Box()
    1.60 +{
    1.61 +}
    1.62 +
    1.63 +Box::~Box()
    1.64 +{
    1.65 +}
    1.66 +
    1.67 +/*
    1.68 +     3--------2
    1.69 +    /.        .\
    1.70 +   0------------1
    1.71 +   | 7--------6 |
    1.72 +   |/          \|
    1.73 +   4------------5
    1.74 +
    1.75 + */
    1.76 +void Box::draw() const
    1.77 +{
    1.78 +	static const float verts[] = {
    1.79 +		-1, 1, 1,
    1.80 +		1, 1, 1,
    1.81 +		1, 1, -1,
    1.82 +		-1, 1, -1,
    1.83 +		-1, -1, 1,
    1.84 +		1, -1, 1,
    1.85 +		1, -1, -1,
    1.86 +		-1, -1, -1
    1.87 +	};
    1.88 +	static const unsigned int indices[] = {
    1.89 +		0, 1, 2, 3,		// top
    1.90 +		4, 7, 6, 5,		// bottom
    1.91 +		0, 4, 5, 1,		// front
    1.92 +		5, 6, 2, 1,		// right
    1.93 +		6, 7, 3, 2,		// back
    1.94 +		7, 4, 0, 3		// left
    1.95 +	};
    1.96 +
    1.97 +	pre_draw();
    1.98 +
    1.99 +	m3d_vertex_array(verts);
   1.100 +	m3d_draw_indexed(M3D_QUADS, indices, sizeof indices / sizeof *indices);
   1.101 +	m3d_vertex_array(0);
   1.102 +
   1.103 +	post_draw();
   1.104 +}
   1.105 +
   1.106 +bool Box::intersect(const Ray &ray, float *dist) const
   1.107 +{
   1.108 +	return false;	// TODO
   1.109 +}