-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameObject.cpp
92 lines (77 loc) · 2.21 KB
/
GameObject.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Created by rcabido on 7/11/19.
//
#include "GameObject.h"
//// MÉTODOS CLASE GAMEOBJECT ////
//* Constructores *//
GameObject::GameObject() {
this->position = Vector3D();
this->color = Color();
this->speed = Vector3D();
this->orientation = Vector3D();
this->rotationSpeed = Vector3D();
this->gravity = true;
}
GameObject::GameObject(const Vector3D& position, const Color& color, const Vector3D& speed, const Vector3D& orientation, const Vector3D& rotationSpeed, bool gravity) {
this->position = position;
this->color = color;
this->speed = speed;
this->orientation = orientation;
this->rotationSpeed = rotationSpeed;
this->gravity = gravity;
}
//* Getters *//
Vector3D GameObject::getPosition() const {
return this->position;
}
Color GameObject::getColor() const {
return this->color;
}
Vector3D GameObject::getSpeed() const {
return this->speed;
}
Vector3D GameObject::getOrientation() const {
return this->orientation;
}
Vector3D GameObject::getRotationSpeed() const {
return this->rotationSpeed;
}
bool GameObject::getGravity() const {
return this->gravity;
}
//* Setters *//
void GameObject::setPosition(const Vector3D& pos) {
this->position = pos;
}
void GameObject::setColor(const Color& color) {
this->color = color;
}
void GameObject::setSpeed(const Vector3D& speed) {
this->speed = speed;
}
void GameObject::setOrientation(const Vector3D& orientation) {
this->orientation = orientation;
}
void GameObject::setRotationSpeed(const Vector3D& rSpeed) {
this->rotationSpeed = rSpeed;
}
void GameObject::setGravity(const bool& gravity) {
this->gravity = gravity;
}
//* Otros *//
//Actualización
void GameObject::update(const float& time, const Vector3D& gravity)
{
if (this->getGravity())
{
this->setSpeed(Vector3D(this->getSpeed() + gravity * time));
}
this->setPosition(Vector3D(this->getPosition() + this->getSpeed() * time));
this->setOrientation(
Vector3D(
this->getOrientation().getX() + time * this->getRotationSpeed().getX(),
this->getOrientation().getY() + time * this->getRotationSpeed().getY(),
this->getOrientation().getZ() + time * this->getRotationSpeed().getZ()
)
);
}