-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStick.cpp
More file actions
90 lines (77 loc) · 1.92 KB
/
Copy pathStick.cpp
File metadata and controls
90 lines (77 loc) · 1.92 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
79
80
81
82
83
84
85
86
87
88
89
90
#include <math.h>
#include <GL/glut.h>
#include "Stick.h"
#include "Color.h"
const double Stick::IMPULSE_FACTOR = 0.04;
const int Stick::POWER_GRADES = 7;
const int Stick::MIN_POWER = 1;
const double Stick::JUMP = 0.05;
Stick::Stick(double length)
: angle(0), power(MIN_POWER), itsLength(length)
{}
Stick::Stick()
{
Stick(1.0);
}
void Stick::setAngle(double a)
{
angle = a;
}
int Stick::shiftPower()
{
return power = MIN_POWER + power % POWER_GRADES;
}
void Stick::resetPower()
{
power = MIN_POWER;
}
void Stick::hit(Ball &ball)
{
ball.applyImpulse(Vector(cos(angle), sin(angle), 0.0) * (power * IMPULSE_FACTOR));
hide();
}
int Stick::getPower() const
{
return power;
}
double Stick::getImpulse() const
{
return power * IMPULSE_FACTOR;
}
double Stick::getAngle() const
{
return angle;
}
void Stick::render()
{
if (isVisible())
{
GLUquadricObj *qObj;
qObj = gluNewQuadric();
//glMaterialfv(GL_FRONT, GL_AMBIENT, Color(Color::WHITE).toArray());
//glMaterialfv(GL_FRONT, GL_DIFFUSE, Color(Color::WHITE).toArray());
glColor3f(0.0, 0.0, 0.0);
glPushMatrix();
glTranslatef(getLocation().getX(), getLocation().getY(), getLocation().getZ() + 0.0002);
glRotatef((180.0 / PI) * angle - 90, 0, 0, 1);
glTranslatef(0.0, -JUMP * (power + 1), 0.0);
glRotatef(88, 1, 0, 0);
gluCylinder(qObj, 0.01, 0.02, itsLength, 16, 16);
/*
glBegin(GL_LINES);
glVertex2f(-0.01, 0.0); // left top
glVertex2f(-0.02, -itsLength); // left bottom
glVertex2f(+0.02, -itsLength); // right bottom
glVertex2f(+0.01, 0.0); // right top
glEnd();
glBegin(GL_POLYGON);
//glColor3f(0.0, 0.0, 0.0);
glVertex2f(+0.01, 0.0); // right top
glVertex2f(-0.01, 0.0); // left top
//glColor3f(0.5, 0.5, 0.5);
glVertex2f(-0.02, -itsLength); // left bottom
glVertex2f(+0.02, -itsLength); // right bottom
glEnd();*/
glPopMatrix();
}
}