-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.pde
170 lines (136 loc) · 4.69 KB
/
Camera.pde
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
class eye
{
float rot_x = 0;
float rot_y = -90;
float pos_x = 0;
float pos_y = 0;
float pos_z = 0;
float dist = 700;
void update()
{
trzyde.perspective(PI/3.0, float(trzyde.width)/float(trzyde.height), 10, 3000); // fov, screen ratio, granica najbliższych rsowanaych rzeczy, granica najdalszych rysowanych rzeczy
trzyde.camera(
sin(radians(rot_x)) * cos(radians(rot_y)) * dist + pos_x, sin(radians(rot_y)) * dist + pos_y, cos(radians(rot_x)) * cos(radians(rot_y)) * dist + pos_z, // eyeX, eyeY, eyeZ
pos_x, pos_y, pos_z, // centerX, centerY, centerZ
0.0, 1.0, 0.0); // upX, upY, upZ
//trzyde.ortho(-1000,1000,-1000,1000,10,3000);
}
void orbitX(float angle)
{
rot_x += angle;
}
void orbitY(float angle)
{
rot_y += angle;
if (rot_y >= 90) //zabezpieczenie przed oglądaniem do góry nogami
rot_y = 89.5;
else if (rot_y <= -90)
rot_y = -89.5;
}
void zooom(float move)
{
dist += move;
}
void moveX(float move)
{
pos_x += move * cos(radians(rot_x));
pos_z -= move * sin(radians(rot_x));
}
void moveY(float move)
{
pos_x -= move * sin(radians(rot_x)) * sin(radians(rot_y));
pos_z -= move * cos(radians(rot_x)) * sin(radians(rot_y));
pos_y += move * cos(radians(rot_y));
}
void moveZ(float move)
{
pos_x += move * sin(radians(rot_x)) * cos(radians(rot_y));
pos_z += move * cos(radians(rot_x)) * cos(radians(rot_y));
pos_y += move * sin(radians(rot_y));
}
}
class eye2
{
float rot_x = camera.rot_x;
float rot_y = camera.rot_y;
float dist = 50;
void update()
{
mini.perspective(PI/3.0, float(mini.width)/float(mini.height), 10, 3000); // fov, screen ratio, granica najbliższych rsowanaych rzeczy, granica najdalszych rysowanych rzeczy
mini.camera(
sin(radians(rot_x)) * cos(radians(rot_y)) * dist, sin(radians(rot_y)) * dist, cos(radians(rot_x)) * cos(radians(rot_y)) * dist, // eyeX, eyeY, eyeZ
0, -9, 0, // centerX, centerY, centerZ
0.0, 1.0, 0.0); // upX, upY, upZ
rot_x = camera.rot_x;
rot_y = camera.rot_y;
}
}
class movement
{
boolean lastPressed = false;
float lastX;
float lastY;
float movementX = 0;
float movementY = 0;
boolean legalMove = false;
boolean xfit(float x)
{
return(trzyde_x <= x && x <= trzyde_x + trzyde.width);
}
boolean yfit(float y)
{
return(trzyde_y <= y && y <= trzyde_y + trzyde.height);
}
void update()
{
if(mousePressed)
{
if(lastPressed)
{
if(legalMove)
{
movementX = mouseX - lastX;
movementY = mouseY - lastY;
}
else
{
movementX = 0;
movementY = 0;
}
}
else
{
if(xfit(mouseX)&&yfit(mouseY))
legalMove = true;
else
legalMove = false;
}
lastX = mouseX;
lastY = mouseY;
lastPressed = true;
}
else
{
movementX /= 1.2;
movementY /= 1.2;
lastPressed = false;
}
if((keyCode != SHIFT) || !keyPressed)
{
camera.orbitX(mouse.movementX * -150 / trzyde.width);
camera.orbitY(mouse.movementY * -90 / trzyde.height);
}
else
{
camera.moveX(mouse.movementX * -1200 / trzyde.width);
camera.moveY(mouse.movementY * -750 / trzyde.height);
}
}
}
void mouseWheel(MouseEvent event)
{
if((keyCode != SHIFT) || !keyPressed)
camera.zooom(event.getCount() * 10);
else
camera.moveZ(event.getCount() * 10);
}