-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ball.cpp
executable file
·112 lines (93 loc) · 1.74 KB
/
Ball.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Ball.cpp
* teapots
*
* Created by Ben Wadsworth on 26/07/2011.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include <stdlib.h>
#include "Ball.h"
Ball::Ball(float _locx, float _locy, float _locz) {
location.x = 0.0f;
location.y = 0.0f;
location.z = 0.0f;
speedx = -0.05f;
speedy = -0.02f;
size.x = 0.1f;
size.y = 0.1f;
size.z = 0.1f;
serve = 1;
}
void Ball::resetPosition() {
location.x = 0.0f;
location.y = 0.0f;
location.z = 0.0f;
rotationSpeed = 0.0f;
rotationAmount = 0.0f;
if (serve == 1) {
speedx = -0.05f;
speedy = -0.02f;
} else {
speedx = 0.05f;
speedy = 0.02f;
}
}
void Ball::updateLocation() {
location.x += speedx;
location.y += speedy;
rotationAmount += rotationSpeed;
if (rotationAmount > 360) {
rotationAmount -= 360;
} else if (rotationAmount < 0) {
rotationAmount += 360;
}
/*
if (abs(speedx) == speedx) {
speedx += abs(rotationSpeed / 50000.0f);
} else {
speedx += abs(rotationSpeed / 50000.0f);
}
*/
speedy -= rotationSpeed / 100000.0f;
}
void Ball::setSpeed(float x, float y) {
speedx = x;
speedy = y;
}
void Ball::invertx() {
speedx = -speedx;
}
void Ball::inverty() {
speedy = -speedy;
}
void Ball::setServe(int _serve) {
serve = _serve;
}
float Ball::getSpeedX() {
return speedx;
}
float Ball::getSpeedY() {
return speedy;
}
void Ball::addClockwiseRotation() {
rotationSpeed -= 10.0f;
speedx *= 1.05f;
}
void Ball::addAntiClockwiseRotation() {
rotationSpeed += 10.0f;
speedx *= 1.05f;
}
void Ball::invertRotation() {
rotationSpeed = -rotationSpeed;
}
void Ball::resetRotation() {
rotationSpeed = 0.0f;
rotationAmount = 0.0f;
}
float Ball::getRotationAmount() {
return rotationAmount;
}
float Ball::getRotationSpeed() {
return rotationSpeed;
}