Skip to content
Permalink
Browse files

adding constructors

  • Loading branch information
phpboxxx committed Mar 17, 2012
1 parent 5820e2d commit f23cfea2890dfe26b31f7c2e223f41dbacc9428e
Showing with 61 additions and 11 deletions.
  1. +61 −11 system/classes/vector.bas
@@ -1,72 +1,122 @@
'DEFINE VECTOR TYPES

'VEC2
Type vec2
x As Single
y As Single

DECLARE CONSTRUCTOR ()
DECLARE CONSTRUCTOR (x As Single, y As Single)
End Type

Constructor vec2 ()
this.x = 0
this.y = 0
End Constructor

Constructor vec2 (x As Single, y As Single)
this.x = x
this.y = y
End Constructor


'VEC3
Type vec3
x As Single
y As Single
z As Single

DECLARE CONSTRUCTOR ()
DECLARE CONSTRUCTOR (x As Single, y As Single,z As Single)
End Type

Constructor vec3 ()
this.x = 0
this.y = 0
this.z = 0
End Constructor

Constructor vec3 (x As Single, y As Single, z As Single)
this.x = x
this.y = y
this.z = z
End Constructor


'VEC4
Type vec4
x As Single
y As Single
z As Single
w As Single

DECLARE CONSTRUCTOR ()
DECLARE CONSTRUCTOR (x As Single, y As Single, z As Single, w As Single)
End Type

Constructor vec4 ()
this.x = 0
this.y = 0
this.z = 0
End Constructor

Constructor vec4 (x As Single, y As Single, z As Single, w As Single)
this.x = x
this.y = y
this.z = z
this.w = w
End Constructor


'OPERATORS
'ADD
Operator + ( v1 As vec2, v2 As vec2 ) As vec2
Return type<vec2>( v1.x + v2.x, v1.y + v2.y)
Return vec2(v1.x + v2.x, v1.y + v2.y)
End Operator

Operator + ( v1 As vec3, v2 As vec3 ) As vec3
Return type<vec3>( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z )
Return vec3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z)
End Operator

'SUBSTRACT
Operator - ( v1 As vec2, v2 As vec2 ) As vec2
Return type<vec2>( v1.x - v2.x, v1.y - v2.y)
Return vec2( v1.x - v2.x, v1.y - v2.y)
End Operator

Operator - ( v1 As vec3, v2 As vec3 ) As vec3
Return type<vec3>( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z )
Return vec3( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z )
End Operator

'MULTIPLY
Operator * ( v1 As vec2, v2 As vec2 ) As vec2
Return type<vec2>( v1.x * v2.x, v1.y * v2.y)
Return vec2( v1.x * v2.x, v1.y * v2.y)
End Operator

Operator * ( v1 As vec3, v2 As vec3 ) As vec3
Return type<vec3>( v1.x * v2.x, v1.y * v2.y, v1.z * v2.z )
Return vec3( v1.x * v2.x, v1.y * v2.y, v1.z * v2.z )
End Operator

Operator * ( v1 As vec3, v2 As Single ) As vec3
Return type<vec3>( v1.x * v2, v1.y * v2, v1.z * v2 )
Return vec3( v1.x * v2, v1.y * v2, v1.z * v2 )
End Operator

'DIVIDE
Operator / ( v1 As vec2, v2 As vec2 ) As vec2
Return type<vec2>( v1.x / v2.x, v1.y / v2.y)
Return vec2( v1.x / v2.x, v1.y / v2.y)
End Operator

Operator / ( v1 As vec3, v2 As vec3 ) As vec3
Return type<vec3>( v1.x / v2.x, v1.y / v2.y, v1.z / v2.z )
Return vec3( v1.x / v2.x, v1.y / v2.y, v1.z / v2.z )
End Operator


'FUNCTIONS TO CREATE VECTORS
Function createVec2 (x As Single, y As Single) As vec2
Return type<vec2>( x, y )
Return vec2( x, y )
End Function

Function createVec3 (x As Single, y As Single, z As Single) As vec3
Return type<vec3>( x, y, z )
Return vec3( x, y, z )
End Function

'HELPER FUNCTIONS

0 comments on commit f23cfea

Please sign in to comment.
You can’t perform that action at this time.