-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.pde
More file actions
97 lines (82 loc) · 2.48 KB
/
Copy pathcamera.pde
File metadata and controls
97 lines (82 loc) · 2.48 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
//-------- CAMERA ----------
class Camera {
float posX, posY, posZ;
PVector target = new PVector(0, 0, 0);
Camera(float pX, float pY, float pZ, float tarX, float tarY, float tarZ) {
//println("Camera");
posX = pX;
posY = pY;
posZ = pZ;
target.x = tarX;
target.y = tarY;
target.z = tarZ;
camera(posX, posY, posZ, target.x, target.y, target.z, 0, 1, 0);
}
void update(float mX, float mY) {
//Check current target
PVector paux = c.elementAt(indexTarget);
target.x = paux.x;
target.y = paux.y;
target.z = paux.z;
//Get radius: offset between camera and target (RANGE: 30 to 200)
float radius = (posX - target.x)*(posX - target.x) + (posY - target.y)*(posY - target.y) + (posZ - target.z)*(posZ - target.z);
radius = sqrt(radius);
//Set range for radius
if (radius < 30) {
radius = 30;
}
if (radius > 200) {
radius = 200;
}
//println("radius is:" + radius);
//Get Phi: depends on MouseX (RANGE MAP: 0 to 360)
float phi = map(mX, 0, width-1, 0, 360);
//println("phi is:" + phi);
//Get Theta: depends on MouseY (RANGE MAP: 0 to 179)
float theta = map(mY, 0, height-1, 0, 179);
//println("theta is:" + theta);
//Calculate derivedXYZ
float derivedX = radius * cos(phi * (PI/180)) * sin(theta * (PI/180));
//println("dX is:" + derivedX);
float derivedY = radius * cos(theta * (PI/180));
//println("dY is:" + derivedY);
float derivedZ = radius * sin(phi * (PI/180)) * sin(theta * (PI/180));
//println("dZ is:" + derivedZ);
//Calculate new values for camera
posX = target.x + derivedX;
posY = target.y + derivedY;
posZ = target.z + derivedZ;
//println("posX is: " + posX + " posY is: " + posY + "posZ is: " + posZ);
//Update Camera
camera(posX, posY, posZ, target.x, target.y, target.z, 0, 1, 0);
}
void addLookTarget(PVector newTarget) {
//Add to list
c.addNodeAtStart(newTarget);
sizeList++;
}
void cycleTarget() {
//Update current Target to next in list
//print("TARGET IS: " + indexTarget);
indexTarget++;
if(indexTarget > sizeList){
indexTarget = 1;
}
//println(" & NEW TARGET IS: " + indexTarget);
}
void zoom (float val) {
//println(val);
if (val < 0) {
view--;
if(view < 10){
view = 10;
}
} else {
view++;
if(view > 90){
view = 90;
}
}
perspective(radians(view), width/(float)height, 0.1, 1000);
}
}