-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuRotor.CC
162 lines (134 loc) · 2.62 KB
/
nuRotor.CC
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
// Pelsmajer 13jan04
// Greg Kaiser
//
// CS290 with Prof. Francis
// 4D Tetris
//
// Rotor.C
// Last modified: April 25, 1996
//
// (C) 1996 Board of Trustees University of Illinois
#include <iostream>
#include "Rotor.h"
#define ABS(x) ((x>0)?x:-x)
#define IFSHIFT if(getbutton(LEFTSHIFTKEY)||getbutton(RIGHTSHIFTKEY))
#define PRESS(K,A,b) if(getbutton(K)){IFSHIFT{A;}else{b;}}
/* static float **id = {{1.,0.,0.,0.},
{0.,1.,0.,0.},
{0.,0.,1.,0.},
{0.,0.,0.,1.}};
Matrix aff = {{1.,0.,0.,0.},
{0.,1.,0.,0.},
{0.,0.,1.,0.},
{0.,0.,0.,1.}};
*/
Rotor::Rotor()
{
active = 1;
mouseX = mouseY = 0;
isMouseLeftDown = isMouseRightDown = isShiftDown =0;
aff = new float[16];
for(int i=0; i<16;i++)
{
if((i%5)==0)
aff[i]=1;
else
aff[i]=0;
}
}
Rotor::~Rotor()
{
delete aff;
}
void Rotor::Rotate()
{
float dx = (active ? mouseX : 0.0);
float dy = (active ? mouseY : 0.0);
if (active) {
int xt, yt;
//get the window size
xt = glutGet(GLUT_WINDOW_WIDTH);
yt = glutGet(GLUT_WINDOW_HEIGHT);
// getsize(&xt,&yt);
//determine where the mose is in relation to the center or "origin" of the window
if(dx != 0.0)
dx -= xt/2;
if(dy!= 0.0)
dy -= yt/2;
// dx = ((-20 < dx) &&(20 > dx) ? 0 : dx);
// dy = ((-20 < dy) &&(20 > dy) ? 0 : dy);
if( -20 >= dx)dx+=19;
else if(20<=dx)dx-=19;
else dx=0;
if( -20 >= dy)dy+=19;
else if(20<=dy)dy-=19;
else dy=0;
//
dy = -dy;
}
pushmatrix();
glLoadIdentity();
// loadmatrix(id); //replaces what's there by the identity
translate(aff[12],aff[13],aff[14]);
if (active) {
float torq = .005;
rot((int)(dx*torq),'y'); rot(-(int)(dy*torq), 'x');
if(isMouseRightDown)
{
if(isShiftDown)
rot(-10, 'z');
else
rot(-1, 'z');
}
if(isMouseLeftDown)
{
if(isShiftDown)
rot(10, 'z');
else
rot(1,'z');
}
}
translate(-aff[12],-aff[13],-aff[14]);
multmatrix(aff); getmatrix(aff); //x = x+dx aff<- daff*aff
popmatrix();
multmatrix(aff); //replaces rotate turn tilt
}
void Rotor::CurrentMousePosition(int x, int y)
{
mouseX = x;
mouseY = y;
}
void Rotor::Activate()
{
active = 1;
}
void Rotor::Deactivate()
{
active = 0;
}
void Rotor::MouseLeftDown()
{
isMouseLeftDown =1;
}
int Rotor::MouseLeftUp()
{
isMouseLeftDown =0;
return isMouseRightDown;
}
void Rotor::MouseRightDown()
{
isMouseRightDown =1;
}
int Rotor::MouseRightUp()
{
isMouseRightDown =0;
return isMouseLeftDown;
}
void Rotor::ShiftDown()
{
isShiftDown = 1;
}
void Rotor::ShiftUp()
{
isShiftDown =0;
}