-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSphere.cpp
37 lines (31 loc) · 815 Bytes
/
Sphere.cpp
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
/*
* Sphere.cpp
*
* Created on: 18/10/2014
* Author: sam
*/
#include "Sphere.h"
Sphere::Sphere(glm::vec3 position, float radius, glm::vec4 color) {
this->pos = position;
this->radius = radius;
this->color = color;
}
Sphere::~Sphere() {
// TODO Auto-generated destructor stub
}
void Sphere::collision(std::vector<Particle> *particles) {
for (std::vector<Particle>::size_type i = 0; i < particles->size(); i++) {
glm::vec3 v = (*particles)[i].pos - pos;
float distance = glm::length(v);
if (distance < radius)
(*particles)[i].pos += glm::normalize(v)*(radius-distance);
}
}
void Sphere::display(Shader *shader) {
shader->setModelMatrix(glm::translate(pos));
glColor3fv(glm::value_ptr(color));
glutSolidSphere(radius, 30, 30);
}
void Sphere::move(glm::vec3 delta) {
pos += delta;
}