-
Notifications
You must be signed in to change notification settings - Fork 0
/
mover.cpp
72 lines (51 loc) · 1.93 KB
/
mover.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: mover.cpp
* Author: lsdfusion
*
* Created on 17 March 2017, 10:48
*/
#include "mover.h"
const float Mover::gravity = 9.8; // m/s^2
Mover::Mover(double time) : Object() {
this->time = time;
}
Mover::~Mover() {
}
void Mover::idle() {
if (!this->active) {
return;
}
////////////////////////////////////
// Numerical integration
this->velocity.x = this->velocity_i.x + (this->acceleration_i.x * this->time);
this->velocity.y = this->velocity_i.y + (this->acceleration_i.y * this->time);
this->velocity.z = this->velocity_i.z + (this->acceleration_i.z * this->time);
this->position.x = this->position_i.x + (this->velocity.x * this->time);
this->position.y = this->position_i.y + (this->velocity.y * this->time);
this->position.z = this->position_i.z + (this->velocity.z * this->time);
////////////////////////////////////
// Collision test
this->collisionDetection();
////////////////////////////////////
// Acceleration calculation: ajouter la viscosité
this->acceleration.x = -(this->velocity.x * this->damping);
this->acceleration.y = -Mover::gravity - (this->velocity.y * this->damping);
this->acceleration.z = -(this->velocity.z * this->damping);
////////////////////////////////////
// System update
this->acceleration_i.x = this->acceleration.x;
this->acceleration_i.y = this->acceleration.y;
this->acceleration_i.z = this->acceleration.z;
this->velocity_i.x = this->velocity.x;
this->velocity_i.y = this->velocity.y;
this->velocity_i.z = this->velocity.z;
this->position_i.x = this->position.x;
this->position_i.y = this->position.y;
this->position_i.z = this->position.z;
////////////////////////////////////
}