-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdanmakuEquation.txt
116 lines (106 loc) · 3.16 KB
/
danmakuEquation.txt
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
originalSpeed: constant number
lowerSpeedLimit: constant number, possibly originalSpeed
upperSpeedLimit: constant number, possibly originalSpeed
acceleration: constant number, possibly 0
rotation: constant quaternion, probably identity
rotationEnd: constant number, probably infinite
gravity: constant vector, probably 0
delay: number probably 0
pos: vector
orientation: quaternion
direction: unit vector
age: number
valueAt(target: constant number) = {
motion := direction * originalSpeed
while(age < target) {
if(delay > 0) then {
delay := delay - 1
if(delay = 0) then motion := direction * originalSpeed
}
else {
if(age < rotationEnd) then {
direction := rotation * direction
orientation = orientation * rotation
}
motion := accelerate(motion, direction) + gravity
pos := pos + motion
age := age + 1
}
}
return what's of interest(pos, direction, motion, orientation)
}
accelerate(motion: vector, direction: unit vector) = {
len := ||motion||
if(len >= upperSpeedLimit && acceleration >= 0) then return direction * upperSpeedLimit
else if(len <= lowerSpeedLimit && acceleration <= 0) then return direction * lowerSpeedLimit
else {
newMotion := motion + direction * acceleration
newLen := ||newMotion||
if(newLen > upperSpeedLimit) then return direction * upperSpeedLimit
else if(newLen < lowerSpeedLimit) then return direction * lowerSpeedLimit
else return newMotion
}
}
recValueAt(delay: number probably 0, pos: vector, orientation: quaternion, direction: unit vector, age: number,
motion: vector = direction * originalSpeed, target: constant number) = {
if(age < target) then {
if(delay > 0) then {
return recValueAt(
delay - 1,
pos,
orientation,
direction,
age,
if(delay = 0) then direction * originalSpeed else motion,
target
)
}
else {
newMotion := accelerate(motion, direction) + gravity
return recValueAt(
delay,
pos + newMotion,
if(age < rotationEnd) then orientation * rotation else orientation,
if(age < rotationEnd) then direction * rotation else direction,
age + 1,
newMotion,
target
)
}
}
else {
return what's of interest(pos, direction, motion, orientation)
}
}
valueAt2(target: constant number) = {
recValueAt(delay: number probably 0, pos: vector, orientation: quaternion, direction: unit vector, age: number,
motion: vector = direction * originalSpeed) = {
if(age < target) then {
if(delay > 0) then {
return recValueAt(
delay - 1,
pos,
orientation,
direction,
age,
if(delay = 0) then direction * originalSpeed else motion
)
}
else {
newMotion := accelerate(motion, direction) + gravity
return recValueAt(
delay,
pos + newMotion,
if(age < rotationEnd) then orientation * rotation else orientation,
if(age < rotationEnd) then direction * rotation else direction,
age + 1,
newMotion
)
}
}
else {
return what's of interest(pos, direction, motion, orientation)
}
}
return recValueAt(delay, pos, orientation, direction, age)
}