Repository navigation
Expand file tree
/
Copy pathTargetBox.cpp
More file actions
71 lines (54 loc) · 1.39 KB
/
Copy pathTargetBox.cpp
File metadata and controls
71 lines (54 loc) · 1.39 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
#include "TargetBox.h"
#include "cube.h"
TargetBox::TargetBox(Vector3 pos, Vector3 direction, double s, double l){
dir = direction;
scale = s;
limit = l - scale / 2;
speed = 0.004;
cube = new Sphere();
px = pos.m[0];
py = pos.m[1];
pz = pos.m[2];
dx = dir.m[0];
dy = dir.m[1];
dz = dir.m[2];
//cout << "pos[0] = " << pos.m[0] << " pos[1] = " << pos.m[1] << " pos[2] = " << pos.m[2] << endl;
//cout << "dir[0] = " << dir.m[0] << " dir[1] = " << dir.m[1] << " dir[2] = " << dir.m[2] << endl;
}
void TargetBox::draw(Matrix4 matrix){
updatePosition();
Matrix4 translate;
translate.makeTranslate(px,py,pz);
Matrix4 shrink;
shrink.makeScale(scale, scale, scale);
cube->draw(matrix * translate * shrink);
}
void TargetBox::updatePosition(){
double x = px + dx * speed;
double y = py + dy * speed;
double z = pz + dz * speed;
if (x < -limit || x > limit){
dx = 0-dx;
}
if (y < 0.02 || y > 2*limit){
dy = -dy;
}
if (z < -limit || z > limit){
dz = -dz;
}
px = px + dx * speed;
py = py + dy * speed;
pz = pz + dz * speed;
}
void TargetBox::update(Matrix4 aa){}
void TargetBox::drawBoundingSpheres(Matrix4 aa){
Matrix4 translate;
translate.makeTranslate(px, py, pz);
Matrix4 shrink;
shrink.makeScale(scale, scale, scale);
cube->drawBoundingSpheres(aa * translate * shrink);
}
void TargetBox::render(){}
Vector3 TargetBox::getPos(){
return Vector3(px, py, pz);
}