rayzor
view src/object.cc @ 1:a826bf0fb169
fixed line endings
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 05 Apr 2014 09:05:26 +0300 |
parents | 2a5340a6eee4 |
children | 5fcf72837b69 |
line source
1 #include "object.h"
2 #include "vmath.h"
3 #include "min3d.h"
5 Object::Object()
6 {
7 }
9 Object::~Object()
10 {
11 }
13 // ---- sphere ----
14 Sphere::Sphere()
15 {
16 }
18 Sphere::~Sphere()
19 {
20 }
22 #define USUB 16
23 #define VSUB 8
25 void Sphere::draw() const
26 {
27 static Vector3 *varr;
28 static int num_verts;
29 if(!varr) {
30 int uverts = USUB;
31 int vverts = VSUB + 1;
32 num_verts = uverts * vverts;
33 varr = new Vector3[num_verts];
35 Vector3 *vptr = varr;
36 for(int i=0; i<uverts; i++) {
37 float u = (float)i / (float)USUB;
38 float theta = u * M_PI * 2.0;
39 for(int j=0; j<vverts; j++) {
40 float v = (float)j / (float)VSUB;
41 float phi = (v - 0.5) * M_PI;
43 float x = sin(theta) * cos(phi);
44 float y = sin(phi);
45 float z = cos(theta) * cos(phi);
47 *vptr++ = Vector3(x, y, z);
48 }
49 }
50 }
52 m3d_draw(M3D_POINTS, &varr->x, num_verts);
53 }