rayzor
annotate 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 |
rev | line source |
---|---|
nuclear@0 | 1 #include "object.h" |
nuclear@0 | 2 #include "vmath.h" |
nuclear@0 | 3 #include "min3d.h" |
nuclear@0 | 4 |
nuclear@0 | 5 Object::Object() |
nuclear@0 | 6 { |
nuclear@0 | 7 } |
nuclear@0 | 8 |
nuclear@0 | 9 Object::~Object() |
nuclear@0 | 10 { |
nuclear@0 | 11 } |
nuclear@0 | 12 |
nuclear@0 | 13 // ---- sphere ---- |
nuclear@0 | 14 Sphere::Sphere() |
nuclear@0 | 15 { |
nuclear@0 | 16 } |
nuclear@0 | 17 |
nuclear@0 | 18 Sphere::~Sphere() |
nuclear@0 | 19 { |
nuclear@0 | 20 } |
nuclear@0 | 21 |
nuclear@0 | 22 #define USUB 16 |
nuclear@0 | 23 #define VSUB 8 |
nuclear@0 | 24 |
nuclear@0 | 25 void Sphere::draw() const |
nuclear@0 | 26 { |
nuclear@0 | 27 static Vector3 *varr; |
nuclear@0 | 28 static int num_verts; |
nuclear@0 | 29 if(!varr) { |
nuclear@0 | 30 int uverts = USUB; |
nuclear@0 | 31 int vverts = VSUB + 1; |
nuclear@0 | 32 num_verts = uverts * vverts; |
nuclear@0 | 33 varr = new Vector3[num_verts]; |
nuclear@0 | 34 |
nuclear@0 | 35 Vector3 *vptr = varr; |
nuclear@0 | 36 for(int i=0; i<uverts; i++) { |
nuclear@0 | 37 float u = (float)i / (float)USUB; |
nuclear@0 | 38 float theta = u * M_PI * 2.0; |
nuclear@0 | 39 for(int j=0; j<vverts; j++) { |
nuclear@0 | 40 float v = (float)j / (float)VSUB; |
nuclear@0 | 41 float phi = (v - 0.5) * M_PI; |
nuclear@0 | 42 |
nuclear@0 | 43 float x = sin(theta) * cos(phi); |
nuclear@0 | 44 float y = sin(phi); |
nuclear@0 | 45 float z = cos(theta) * cos(phi); |
nuclear@0 | 46 |
nuclear@0 | 47 *vptr++ = Vector3(x, y, z); |
nuclear@0 | 48 } |
nuclear@0 | 49 } |
nuclear@0 | 50 } |
nuclear@0 | 51 |
nuclear@0 | 52 m3d_draw(M3D_POINTS, &varr->x, num_verts); |
nuclear@0 | 53 } |