-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphere.cpp
More file actions
78 lines (57 loc) · 1.29 KB
/
Sphere.cpp
File metadata and controls
78 lines (57 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "Sphere.h"
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
Sphere::Sphere(double radius, int slices, int stacks) : Drawable()
{
this->radius = radius;
this->slices = slices;
this->stacks = stacks;
float xCenter = (maxX + minX) / 2;
float yCenter = (maxY + minY) / 2;
float zCenter = (maxZ + minZ) / 2;
toWorld.set(3, 0, -xCenter);
toWorld.set(3, 1, -yCenter);
toWorld.set(3, 2, -zCenter);
}
void Sphere::draw(DrawData& data)
{
material.apply();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glMultMatrixf(toWorld.ptr());
maxX = radius;
maxY = radius;
maxZ = radius;
minX = -radius;
minY = -radius;
minZ = -radius;
glutSolidSphere(radius, slices, stacks);
glPopMatrix();
}
void Sphere::update(UpdateData& data)
{
//
}
void Sphere::scaleUp() {
Matrix4 scale;
scale.makeScale(1.1);
toWorld = toWorld * scale;
}
void Sphere::scaleDown() {
Matrix4 scale;
scale.makeScale(.9);
toWorld = toWorld * scale;
}
void Sphere::translate(Vector3 dir) {
Matrix4 translation;
translation.makeTranslate(dir[0], dir[1], dir[2]);
toWorld = translation * toWorld;
}
void Sphere::rotate(Vector3 axis, float angle) {
Matrix4 rotate;
rotate.makeRotateArbitrary(axis, angle);
toWorld = rotate * toWorld;
}