08-16-2023, 11:53 AM
I feel your pain. Working with vector types just screams having a way to directly functionalize their manipulation. I resort to the somewhat clumsy approach of passing a variable back from a sub. The main issue being keeping track of which variable is the desired result. I use the first parameter as a return. Then I have to decide if I want to preserve original operands or overwrite them. At least it can be done in a fairly concise manner.
I imagine that since there are no rules against multi-dimensional (4+ element) vectors, there is simply no point in trying to satisfy all possibilities. So we'll just have to do the typical hacks.
I imagine that since there are no rules against multi-dimensional (4+ element) vectors, there is simply no point in trying to satisfy all possibilities. So we'll just have to do the typical hacks.
Code: (Select All)
TYPE V3
x AS SINGLE
y AS SINGLE
z AS SINGLE
END TYPE
DIM AS V3 A, B, C
A.x = 3: A.y = 7: A.z = -4
B.x = -13: B.y = 5: B.z = 9
'If I need to keep the original state, then I copy the first parameter prior to the call
C = A: R3_Add C, B, 1
Pvec "A", A
PRINT "plus"
Pvec "B", B
PRINT "equals"
Pvec "C", C
PRINT "________________________________"
C = A: R3_Add C, B, -1
Pvec "A", A
PRINT "minus"
Pvec "B", B
PRINT "equals"
Pvec "C", C
PRINT "________________________________"
'If I don't need the original, I'll just overwrite it.
Pvec "A", A
PRINT "plus"
R3_Add A, B, 1
Pvec "B", B
PRINT "equals"
Pvec "A", A
PRINT "________________________________"
'an inversion by manipulating the scalar
Pvec "A", A
PRINT "inverted"
R3_Add A, A, -2
Pvec "A", A
END
SUB R3_Add (re AS V3, se AS V3, scalar AS INTEGER)
re.x = re.x + se.x * scalar
re.y = re.y + se.y * scalar
re.z = re.z + se.z * scalar
END SUB
SUB Pvec (s AS STRING, v AS V3)
PRINT "Vector "; s; ": <"; v.x; ", "; v.y; ", "; v.z; ">"
END SUB
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: