-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.cpp
More file actions
204 lines (168 loc) · 3.54 KB
/
interface.cpp
File metadata and controls
204 lines (168 loc) · 3.54 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*!
* Defination of interface methods
*
* Copyright (c) 2010 by sidharth
*/
#include "variables.h"
#include "model.h"
#include "interface.h"
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
int strikerSet = NOT_SET;
/*!
* \brief
* Method to process mouse action to move from one screen to another
*
* \param button
* Tells which button is pressed
*
* \param stateMouse
* Tells the state of the mouse button .
*
* \param x
* coordinate x of screen
*
* \param y
* coordinate y of screen
*
*
* Method to process mouse action to move from one screen to another
*
*/
void processMouse(int button, int stateMouse, int x, int y)
{
if(state == STATE_BOARD_SIMULATION)
{
if (stateMouse == GLUT_DOWN) {
state = STATE_BOARD_SIMULATION;
glutPostRedisplay();
}
}
if(state == STATE_BOARD_PLACE_STRIKER)
{
if(button == GLUT_LEFT_BUTTON)
{
int i = cdObjectVector.size();
CarromMen *carromMen = (CarromMen *)cdObjectVector[i-1];
carromMen->visible = true;
x=x-h/2;
y=y-w/2;
if(((x > -130)&&(x< 130))&&((y>134)&&(y<154)))
{if(x< -123 )
x=-123;
if( x > 123)
x=123;
carromMen->position.Set(x * 370 /186.0, -145 * 370 /186.0, 0);
ALenum soundState;
//check if there is a sound playing currently
alGetSourcei(AudioSource[SOUND_CARROMMEN_COLLISION], AL_SOURCE_STATE, &soundState);
//setting up board sound for placing the striker
if(soundState != AL_PLAYING)
{
alSourcePlay(AudioSource[SOUND_STRIKER_WALL]);
}
strikerSet = SET;
}
}
if(button == GLUT_RIGHT_BUTTON && strikerSet == 1 && stateMouse == GLUT_UP)
{
state = STATE_BOARD_STRIKER_DIRECTION;
strikerSet = NOT_SET;
}
glutPostRedisplay();
}
if(state == STATE_BOARD_STRIKER_DIRECTION)
{
if (stateMouse == GLUT_DOWN)
{
state = STATE_BOARD_STRIKER_POWER;
strikerSpeed = 0.0;
glutPostRedisplay();
alSourcePlay(AudioSource[SOUND_POWER_BAR]);
}
return;
}
if(state == STATE_BOARD_STRIKER_POWER)
{
if (stateMouse == GLUT_UP)
{//code for giving velocity to the carrom striker
int i = cdObjectVector.size();
alSourceStop(AudioSource[SOUND_POWER_BAR]);
CarromMen *carromMen = (CarromMen *)cdObjectVector[i-1];
carromMen->velocity.Set(-sin(angle * 3.141 /180), cos(angle * 3.141 /180), 0);
carromMen->velocity = carromMen->velocity * strikerSpeed;
state = STATE_BOARD_SIMULATION;
glutPostRedisplay();
}
}
}
/*!
* \brief
* Function to process the mouse movement and convert it to the angle of the striker
*
* \param x
* location x of mouse
*
* \param y
* location y of mouse
*
*
* Function to process the mouse movement and convert it to the angle of the striker
*
* \remarks
* none
*
*/
void processMouseActiveMotion(int x, int y)
{
if(state == 2)
{
x = x - w /2;
angle = -x/300.0 * 75;
glutPostRedisplay();
}
}
/*!
* \brief
* Method used to process keyboard functionalities
*
* \param key
* which key is pressed
*
* \param x
* Description of parameter x.
*
* \param y
* Description of parameter y.
*
*
* Method used to process keyboard functionalities
*
* \remarks
* none
*/
void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
//reinitialize the board if state is place striker and key pressed is r
case 'r':
if(state == STATE_BOARD_PLACE_STRIKER)
{
//glutPostWindowRedisplay(1);
for(unsigned int i=0;i< objectVector.size();i++)
delete objectVector[i];
objectVector.clear();
initCarromBoardModel();
glutPostRedisplay();
}
break;
//handling esc key
case 27 :
exit(0);
break;
default:
break;
}
}