forked from phu004/JavaRTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.java
More file actions
151 lines (95 loc) · 2.8 KB
/
Copy pathcamera.java
File metadata and controls
151 lines (95 loc) · 2.8 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
package core;
import java.awt.*;
public class camera{
public static vector position;
public static vector view_Direction;
public static vector left, right, left_, right_;
public static boolean MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, TURN_LEFT, TURN_RIGHT;
public static int XZ_angle, YZ_angle;
public static float sinXZ_angle, cosXZ_angle, sinYZ_angle, cosYZ_angle;
public static final vector viewDirection = new vector(0, 0, 1);
//a rectangle that represents the screen area
public static Rectangle screen;
public static vector cameraMovement;
public static int frameIndex;
public camera(vector p, int XZ, int YZ){
screen = new Rectangle(0,0,mainThread.screen_width, mainThread.screen_height);
view_Direction = new vector(0, 0, 1);
position = p;
XZ_angle = XZ;
YZ_angle = YZ;
left = new vector(0,0,0);
right = new vector(0,0,0);
left_ = new vector(0, -1, 0);
right_ = new vector(0, 1, 0);
}
public void update(){
frameIndex++;
if(!mainThread.gameStarted) {
//when game has not started, use a "fly through" as the background for the menu
if(frameIndex == 1) {
position.z = 2.5f;
position.x = 9;
cameraMovement = new vector(-0.01f,0,0);
}
if(frameIndex > 90 && frameIndex%400 >= 0 && frameIndex%400 < 90) {
XZ_angle+=1;
cameraMovement.rotate_XZ(359);
}
position.add(cameraMovement);
}
position.add(view_Direction.x*3, 0 , view_Direction.z*3);
if(TURN_RIGHT){
XZ_angle+=1;
}
if(TURN_LEFT){
XZ_angle-=1;
}
if(MOVE_LEFT){
left.cross(view_Direction, left_);
left.unit();
position.add(left, -0.1f);
}
if(MOVE_RIGHT){
right.cross(view_Direction, right_);
right.unit();
position.add(right, -0.1f);
}
if(MOVE_UP){
vector up = new vector(view_Direction.x, 0, view_Direction.z);
up.unit();
position.add(up, 0.1f);
}
if(MOVE_DOWN){
vector down = new vector(view_Direction.x, 0, view_Direction.z);
down.unit();
position.add(down, -0.1f);
}
//make sure the camera never leaves the map
if(position.x < 0.5){
position.x = 0.5f;
}
if(position.z < 0.5){
position.z = 0.5f;
}
if(position.x > 31.5){
position.x = 31.5f;
}
if(position.z > 31.5){
position.z = 31.5f;
}
XZ_angle = (XZ_angle + 360) % 360;
YZ_angle = (YZ_angle + 360) % 360;
sinXZ_angle = gameData.sin[XZ_angle];
cosXZ_angle = gameData.cos[XZ_angle];
sinYZ_angle = gameData.sin[YZ_angle];
cosYZ_angle = gameData.cos[YZ_angle];
view_Direction.set(viewDirection);
view_Direction.rotate_YZ(YZ_angle);
view_Direction.rotate_XZ(XZ_angle);
view_Direction.y*=-1;
view_Direction.x*=-1;
view_Direction.unit();
position.add(-view_Direction.x*3, 0 , -view_Direction.z*3);
}
}