-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTank.cpp
87 lines (70 loc) · 1.49 KB
/
Tank.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
//
// Tank.cpp
// CGXcode
//
// Created by Philipp Lensing on 16.11.16.
// Copyright © 2016 Philipp Lensing. All rights reserved.
//
#include "Tank.h"
Tank::Tank()
{
this->TM = new Matrix;
this->RM = new Matrix;
this->TM->rotationY(0);
this->RM->rotationY(0);
rt = 0;
way = Vector(0,0,0);
aim_angle = 0;
}
Tank::~Tank()
{
// TODO: Add your code
}
bool Tank::loadModels(const char* ChassisFile, const char* CannonFile)
{
this->pTankBot = new Model(ChassisFile, false);
this->pTankBot->shader(new PhongShader(), true);
this->pTankTop = new Model(CannonFile, false);
this->pTankTop->shader(new PhongShader(), true);
return true;
}
void Tank::steer( float ForwardBackward, float LeftRight)
{
this->fb = ForwardBackward;
this->lr = LeftRight;
}
void Tank::aim(const Vector& Target )
{
Vector test = Vector(1, 0, 0);
float test2 = atan2(test.Z, test.X) - atan2(Target.Z, Target.Y);
float tesat = acos(way.dot(Target));
printf("%f\n", tesat+rt);
}
void Tank::update(float dtime)
{
Vector dir = Vector(
cos(-rt),
0,
sin(-rt)
);
// -->needs dtime
if (this->lr != 0) {
rt = fmod(
double(
rt + this->lr*.01
),
2*M_PI);
}
if (this->fb != 0) {
way += dir*0.01*fb;
}
this->TM->translation(way);
this->RM->rotationY(rt);
this->pTankBot->transform(*this->TM * *this->RM);
this->pTankTop->transform(*this->TM * *this->RM * Matrix().rotationY(-aim_angle));
}
void Tank::draw(const BaseCamera& Cam)
{
this->pTankTop->draw(Cam);
this->pTankBot->draw(Cam);
}