-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcftVec2D.cxs
222 lines (179 loc) · 5.46 KB
/
cftVec2D.cxs
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
Strict
'#DOCON#
#rem
Title: fantomCX
Description: A 2D game framework for the Cerberus X programming language
Author: Michael Hartlef
Contact: [email protected]
Website: http://www.fantomgl.com
License: MIT
#End
Import fantomCX
'nav:<blockquote><nav><b>fantomCX documentation</b> | <a href="index.html">Home</a> | <a href="classes.html">Classes</a> | <a href="3rdpartytools.html">3rd party tools</a> | <a href="examples.html">Examples</a> | <a href="changes.html">Changes</a></nav></blockquote>
'header:The cftVec2D module provides a 2D vector class.
'***************************************
Class ftVec2Dp
Field x:Float = 0.0
Field y:Float = 0.0
End
'***************************************
Class ftVec2D Extends ftVec2Dp
'------------------------------------------
Method Add:Void (vector:ftVec2D)
x += vector.x
y += vector.y
End
'------------------------------------------
Method Add:Void (addX:Float, addY:Float)
x += addX
y += addY
End
'------------------------------------------
Method Angle:Float (vector:ftVec2D)
Local xdiff:Float
Local ydiff:Float
Local ang:Float
xdiff = vector.x - x
ydiff = vector.y - y
ang = ATan2( ydiff, xdiff )+90.0
If ang < 0.0 Then
ang = 360.0 + ang
Endif
Return ang
End
'------------------------------------------
Method Angle:Float (xPos:Float, yPos:Float)
Local xdiff:Float
Local ydiff:Float
Local ang:Float
xdiff = xPos - x
ydiff = yPos - y
ang = ATan2( ydiff, xdiff )+90.0
If ang < 0.0 Then
ang = 360.0 + ang
Endif
Return ang
End
'------------------------------------------
Method Angle:Float ()
Local ang:Float
ang = ATan2( y, x )+90.0
If ang < 0.0 Then
ang = 360.0 + ang
Endif
Return ang
End
'------------------------------------------
Method Copy:ftVec2D()
Return New ftVec2D (x, y)
End
'------------------------------------------
Method Dot:Float(xPos:Float, yPos:Float)
Return (x * xPos + y * yPos)
End
'------------------------------------------
Method Dot:Float (vector:ftVec2D)
Return (x * vector.x + y * vector.y)
End
'------------------------------------------
Method Equals:Bool (vector:ftVec2D)
Return (x = vector.x) And (y = vector.y)
End
'------------------------------------------
Method Inverse:Void()
x = -x
y = -y
End
'------------------------------------------
Method InverseX:Void()
x = -x
End
'------------------------------------------
Method InverseY:Void()
y = -y
End
'------------------------------------------
Method Length:Float(vector:ftVec2D)
Local xdiff:Float
Local ydiff:Float
xdiff = vector.x - x
ydiff = vector.y - y
Return Sqrt(xdiff * xdiff + ydiff * ydiff)
End
'------------------------------------------
Method Length:Float(xPos:Float, yPos:Float)
Local xdiff:Float
Local ydiff:Float
xdiff = xPos - x
ydiff = yPos - y
Return Sqrt(xdiff * xdiff + ydiff * ydiff)
End
'------------------------------------------
Method Length:Float()
Return Sqrt (x * x + y * y)
End
'------------------------------------------
'changes:2.0:New command
Method Lerp:ftVec2D(targetVector:ftVec2D, timeFaktor:Float)
Local xdiff:Float
Local ydiff:Float
Local lerpV:ftVec2D
xdiff = targetVector.x - x
ydiff = targetVector.y - y
lerpV.x = xdiff * timeFaktor
lerpV.y = ydiff * timeFaktor
Return lerpV
End
'------------------------------------------
Method Mul:Void (scalar:Float)
x *= scalar
y *= scalar
End
'------------------------------------------
Method New(xp:Float, yp:Float)
x = xp
y = yp
End
'------------------------------------------
Method Normalize:Void()
Local length:Float = Self.Length()
If length = 0
Return
Endif
Set (x/length, y/length)
End
'------------------------------------------
Method Perp:Void()
Local xt:Float = Self.x
Self.x = Self.y
Self.y = -xt
End
'------------------------------------------
Method Set:Void (setX:Float, setY:Float)
x = setX
y = setY
End
'------------------------------------------
Method Set:Void (vector:ftVec2D)
x = vector.x
y = vector.y
End
'------------------------------------------
Method Sub:Void (vector:ftVec2D)
x -= vector.x
y -= vector.y
End
'------------------------------------------
Method Sub:Void (subX:Float, subY:Float)
x -= subX
y -= subY
End
End
#rem
footer:This fantomCX framework is released under the MIT license:
[quote]Copyright (c) 2011-2018 Michael Hartlef
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[/quote]
#end