-
Notifications
You must be signed in to change notification settings - Fork 0
/
CameraScript.gd
91 lines (75 loc) · 2.58 KB
/
CameraScript.gd
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
extends Node2D
#Custom freakin rotation system!
var camera = null
var z = 100
var angle = 0 #IN DEGREES
var pitch = 0;
var m00 = 0
var m01 = 0
var m10 = 0
var m11 = 0
var x;
var y
var yscale = 0;
var zscale = 0
var size = Vector2()
var uiLabel = null
var near = 0.0
var far = 100.0
var fov = 2
var zoom = 2
var farnear_comp = 1 / (far - near);
# Called when the node enters the scene tree for the first time.
func _ready():
camera = get_node("/root/Node2D/Camera2D")
uiLabel = get_node("/root/Node2D/Camera2D/Control/RichTextLabel")
print(lendir_port(Vector2(500,500),45,1))
# Replace with function body.
func _draw():
size= get_viewport().get_size()
#Equivalent to the lendir_x/_y functions in GML but takes vectors instead. The "start" vector does nothing by the way, but it makes more sense in my head, so cry harder.
func lendir_port(start,dir,mag):
var radians = dir*(PI/180)
var directionVector = Vector2(cos(radians),sin(radians))
#print(directionVector)
#directionVector.x = abs(directionVector.x)
#directionVector.y = abs(directionVector.y)
directionVector *=mag
var result = directionVector
return result
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_pressed("rotateLeft"):
angle-=1
elif Input.is_action_pressed("rotateRight"):
angle+=1
if Input.is_action_pressed("rotateUp"):
pitch-=1
elif Input.is_action_pressed("rotateDown"):
pitch+=1
m00 = lendir_port(position,angle,1).x
m10 = lendir_port(position,angle,-1).y
m01 = lendir_port(position,angle,1).y
m11 = lendir_port(position,angle,1).x
var scaleVector = lendir_port(position,pitch,1)
yscale = scaleVector.y
zscale=scaleVector.x
#yscale = lendir_port()
var rawAxisX = 0
var rawAxisY = 0
if Input.is_action_pressed("move_left"):
rawAxisX-=1
if Input.is_action_pressed("move_right"):
rawAxisX+=1
if Input.is_action_pressed("move_down"):
rawAxisY -=1
if Input.is_action_pressed("move_up"):
rawAxisY +=1
var forVector = lendir_port(position,-angle+90,1) #Vector2(rawAxisX,rawAxisY)
forVector.y = -forVector.y
var sideVector = lendir_port(position,-angle,1)
sideVector.y = -sideVector.y
uiLabel.set_text(str(forVector) + " " +str(sideVector) +" "+str(angle)+str(camera.position))
camera.position.x += rawAxisX*4#((rawAxisY * forVector.x )+(rawAxisX * sideVector.x))*4;#rawAxisX*4#((rawAxisY * forVector.x )+(rawAxisX * sideVector.x))*4;#rawAxisX*4#
camera.position.y -= rawAxisY*4#(((rawAxisY * forVector.y) + (rawAxisX * sideVector.y))*12);#rawAxisY*12#((rawAxisY * forVector.y) + (rawAxisX * sideVector.y))*4;#rawAxisY*4#
pass