rayzor

diff src/object.cc @ 0:2a5340a6eee4

rayzor first commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 05 Apr 2014 08:46:27 +0300
parents
children a826bf0fb169
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/object.cc	Sat Apr 05 08:46:27 2014 +0300
     1.3 @@ -0,0 +1,53 @@
     1.4 +#include "object.h"
     1.5 +#include "vmath.h"
     1.6 +#include "min3d.h"
     1.7 +
     1.8 +Object::Object()
     1.9 +{
    1.10 +}
    1.11 +
    1.12 +Object::~Object()
    1.13 +{
    1.14 +}
    1.15 +
    1.16 +// ---- sphere ----
    1.17 +Sphere::Sphere()
    1.18 +{
    1.19 +}
    1.20 +
    1.21 +Sphere::~Sphere()
    1.22 +{
    1.23 +}
    1.24 +
    1.25 +#define USUB	16
    1.26 +#define VSUB	8
    1.27 +
    1.28 +void Sphere::draw() const
    1.29 +{
    1.30 +	static Vector3 *varr;
    1.31 +	static int num_verts;
    1.32 +	if(!varr) {
    1.33 +		int uverts = USUB;
    1.34 +		int vverts = VSUB + 1;
    1.35 +		num_verts = uverts * vverts;
    1.36 +		varr = new Vector3[num_verts];
    1.37 +
    1.38 +		Vector3 *vptr = varr;
    1.39 +		for(int i=0; i<uverts; i++) {
    1.40 +			float u = (float)i / (float)USUB;
    1.41 +			float theta = u * M_PI * 2.0;
    1.42 +			for(int j=0; j<vverts; j++) {
    1.43 +				float v = (float)j / (float)VSUB;
    1.44 +				float phi = (v - 0.5) * M_PI;
    1.45 +
    1.46 +				float x = sin(theta) * cos(phi);
    1.47 +				float y = sin(phi);
    1.48 +				float z = cos(theta) * cos(phi);
    1.49 +
    1.50 +				*vptr++ = Vector3(x, y, z);
    1.51 +			}
    1.52 +		}
    1.53 +	}
    1.54 +
    1.55 +	m3d_draw(M3D_POINTS, &varr->x, num_verts);
    1.56 +}