/
Body.cpp
66 lines (54 loc) · 1.27 KB
/
Body.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
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
//
// Body.cpp
// OpenGLGLUTApp
//
// Created by Marcus Johansson on 4/4/13.
//
//
#include "Body.h"
Body::Body(GLfloat x, GLfloat y, GLfloat z)
: Particle(x, y, z), _rotation(IdentityMatrix()), _rotationVelocity(IdentityMatrix()), _rotationAcceleration(IdentityMatrix()), _scaling(IdentityMatrix())
{}
void Body::setRot(GLfloat x, GLfloat y, GLfloat z, GLfloat a)
{
_rotation = ArbRotate(vec3(x, y, z), a);
}
void Body::setRotVelocity(GLfloat x, GLfloat y, GLfloat z, GLfloat da)
{
_rotationVelocity = ArbRotate(vec3(x, y, z), da);
}
void Body::setRotAcceleration(GLfloat x, GLfloat y, GLfloat z, GLfloat dda)
{
_rotationAcceleration = ArbRotate(vec3(x, y, z), dda);
}
void Body::setScaling(GLfloat x, GLfloat y, GLfloat z)
{
setScaling(vec3(x, y, z));
}
void Body::setScaling(vec3 v)
{
_scaling = S(v.x, v.y, v.z);
}
mat4 Body::getRot() const
{
return _rotation;
}
mat4 Body::getRotVelocity() const
{
return _rotationVelocity;
}
mat4 Body::getRotAcceleration() const
{
return _rotationAcceleration;
}
mat4 Body::getModelMatrix() const
{
return Particle::getModelMatrix() * _rotation * _scaling;
}
int Body::update_function(unsigned int time)
{
Particle::update_function(time);
_rotation *= _rotationVelocity;
_rotationVelocity *= _rotationAcceleration;
return 0;
}