-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCam.pde
More file actions
executable file
·161 lines (150 loc) · 3.51 KB
/
Cam.pde
File metadata and controls
executable file
·161 lines (150 loc) · 3.51 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
class Cam{
//sensibility
final float sensZ=5,sensRotation=PI/30;
//dragging variable
boolean isDragging=false;
int posMousePressedX,posMousePressedY;
int deltaX,deltaY;
//rotation variable
boolean leftRotation=false,upRotation=false,rightRotation=false,downRotation=false;
boolean rightFrontRotation=false,leftFrontRotation=false;
//actual variable of graphics sketch
int actualX=0,actualY=0,actualZ=0;
int verticalRotation=0,orizontalRotation=0,frontalRotation=0;
//initial variable
int initX,initY;
public Cam(int initX,int initY){
this.initX = initX;
this.initY = initY;
actualX=initX;
actualY=initY;
}
void control(boolean drawAxis){
//change prespective
if(isDragging)
translate(deltaX,deltaY);
translate(actualX,actualY,actualZ);
//change rotation
if(upRotation)
verticalRotation++;
if(downRotation)
verticalRotation--;
if(rightRotation)
orizontalRotation++;
if(leftRotation)
orizontalRotation--;
if(rightFrontRotation)
frontalRotation--;
if(leftFrontRotation)
frontalRotation++;
rotateX(verticalRotation*sensRotation);
rotateY(orizontalRotation*sensRotation);
rotateZ(frontalRotation*sensRotation);
if(drawAxis){
stroke(0,0,255);
fill(0,0,255);
line(0,0,300,0);
text("X",301,0);
stroke(255,0,0);
line(0,0,0,-300);
fill(255,0,0);
text("Y",0,-301);
}
//println("w:",actualX,"h:",actualY,"z:",frontalRotation*sensRotation);
//635
//println("actualz:",actualZ,"width:",width,"height:",height);
}
void restore(){
actualX = initX;
actualY = initY;
actualZ=0;
verticalRotation=0;
orizontalRotation=0;
frontalRotation=0;
}
void mousePressed(){
println("Pressed on");
posMousePressedX=mouseX;
posMousePressedY=mouseY;
}
void mouseReleased(){
if(isDragging){
actualX+=deltaX;
actualY+=deltaY;
}
isDragging=false;
println("Released");
}
void mouseDragged(){
isDragging=true;
deltaX=mouseX-posMousePressedX;
deltaY=mouseY-posMousePressedY;
}
int gg=0;
void mouseWheel(MouseEvent event) {
if(event.getCount()!=0){
actualZ-=(event.getCount()*sensZ);
println(++gg);
}
}
void keyPressed() {
switch(Character.toLowerCase(key)){
case 'w':{
upRotation=true;
break;
}
case 'a':{
leftRotation=true;
break;
}
case 's':{
downRotation=true;
break;
}
case 'd':{
rightRotation=true;
break;
}
case 'z':{
rightFrontRotation=true;
break;
}
case 'x':{
leftFrontRotation=true;
break;
}
case 'r':{
restore();
break;
}
}
}
void keyReleased() {
switch(key){
case 'w':{
upRotation=false;
break;
}
case 'a':{
leftRotation=false;
break;
}
case 's':{
downRotation=false;
break;
}
case 'd':{
rightRotation=false;
break;
}
case 'z':{
rightFrontRotation=false;
break;
}
case 'x':{
leftFrontRotation=false;
break;
}
}
}
}