-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCannon.cpp
More file actions
78 lines (67 loc) · 1.74 KB
/
Cannon.cpp
File metadata and controls
78 lines (67 loc) · 1.74 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
72
73
74
75
76
77
78
//
// Cannon.cpp
// Project
//
// Created by Inês on 10/20/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#include "Cannon.h"
namespace CastleBlast {
Cannon::Cannon() :cg::Entity("CANNON") {}
Cannon::~Cannon() {}
void Cannon::init()
{
_position = cg::Vector3d(0,0,0);
_wheelRotation = 0;
_cannonRotation = 0;
_cannon = new Model();
_wheels = new Model();
#ifdef __APPLE__
_cannon->loadModelData("Models/cannon.obj");
_wheels->loadModelData("Models/wheels.obj");
#else
_cannon->loadModelData("..\\..\\src\\Models\\cannon.obj");
_wheel1->loadModelData("..\\..\\src\\Models\\wheels.obj");
#endif
}
void Cannon::draw()
{
glPushMatrix();
{
glScaled(2, 2, 2);
glPushMatrix();
{
glTranslatef(_position[0]+.5, _position[1]+1.7, _position[2]);
glRotatef(_wheelRotation, 0, 0, 1);
_wheels->drawModel();
}
glPopMatrix();
glPushMatrix();
{
glTranslatef(_position[0], _position[1], _position[2]);
glRotatef(_cannonRotation, 0, 0, 1);
_cannon->drawModel();
}
glPopMatrix();
}
glPopMatrix();
}
void Cannon::update(unsigned long elapsed_millis)
{
if(cg::KeyBuffer::instance()->isKeyDown('w')) {
_position[0] = _position[0] + 0.0002*elapsed_millis;
_wheelRotation = _wheelRotation - 0.01*elapsed_millis;
}
if(cg::KeyBuffer::instance()->isKeyDown('s')) {
_position[0] = _position[0] - 0.0002*elapsed_millis;
_wheelRotation = _wheelRotation + 0.01*elapsed_millis;
}
if(cg::KeyBuffer::instance()->isKeyDown('a')) {
_cannonRotation = _cannonRotation + 0.01*elapsed_millis;
}
if(cg::KeyBuffer::instance()->isKeyDown('d')) {
_cannonRotation = _cannonRotation - 0.01*elapsed_millis;
}
//std::cout << "" << _wheelRotation << std::endl;
}
}