GLBasic forum

Main forum => GLBasic - en => Topic started by: bigsofty on 2007-Mar-28

Title: Type error?
Post by: bigsofty on 2007-Mar-28
Using types as parameter and return values for a small function library and Im getting this error...

Code (glbasic) Select
_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2007.050 - 3D, NET

Wordcount:215 commands

compiling:
C:/DOCUME~1/Dad/LOCALS~1/Temp/glbasic/gpc_temp5.cpp:9: error: expected constructor, destructor, or type conversion before '=' token
C:/DOCUME~1/Dad/LOCALS~1/Temp/glbasic/gpc_temp5.cpp:9: error: expected `,' or `;' before '=' token
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Time: 3.3 sec
Build: 0 succeeded
*** 1 FAILED ***
Title: Type error?
Post by: Schranz0r on 2007-Mar-28
hmm, pls post the Sourcecode !
Title: Type error?
Post by: bigsofty on 2007-Mar-28
OK, heres the code... this is a library, not a standalone program...

Code (glbasic) Select
// --------------------------------- //
// Project: VectorLIB
// Start: Wednesday, March 28, 2007
// IDE Version: 4.132

//used TO normalize vector
GLOBAL vector_tol = 0.0001

TYPE Tvector
x
y
z
magnitude
ENDTYPE

FUNCTION vector_calcMagnitude: vec AS Tvector
//calc the magnitude of a vector AND stor in vector
vec.magnitude=SQR(vec.x*vec.x + vec.y*vec.y + vec.z*vec.z)
ENDFUNCTION

FUNCTION vector_normalize: vec AS Tvector
    LOCAL m
//normalize a vector so it's length = 1 AND apply tolerance based on our constant tolerance value
m=SQR(SQR(vec.x*vec.x + vec.y*vec.y + vec.z*vec.z) )
IF m<= vector_tol THEN m=1
vec.x=vec.x/m
vec.y=vec.y/m
vec.z=vec.z/m
IF ABS(vec.x) IF ABS(vec.y) IF ABS(vec.z)ENDFUNCTION

FUNCTION vector_reverse: vec AS Tvector
//reverse a vector
vec.x=-vec.x
vec.y=-vec.y
vec.z=-vec.z
ENDFUNCTION

FUNCTION vector_add AS Tvector: vec1 AS Tvector, vec2 AS Tvector
//add two vectors together AND RETURN the resulting vector
LOCAL result AS Tvector
result.x=vec1.x+vec2.x
result.y=vec1.y+vec2.y
result.z=vec1.z+vec2.z
RETURN result
ENDFUNCTION

FUNCTION vector_subtract AS Tvector: vec1 AS Tvector, vec2 AS Tvector
//subtract vec1 from vec2 AND RETURN the resulting vector
LOCAL result AS Tvector
result.x=vec1.x-vec2.x
result.y=vec1.y-vec2.y
result.z=vec1.z-vec2.z
RETURN result
ENDFUNCTION

FUNCTION vector_scalarMultiply AS Tvector: vec1 AS Tvector, scale
//scalar multiplication of a vector with result returned AS new vector
//used TO scale a vector by 'scale'
LOCAL result AS Tvector
result.x=vec1.x*scale
result.y=vec1.y*scale
result.z=vec1.z*scale
RETURN result
ENDFUNCTION

FUNCTION vector_scalarDivision AS Tvector: vec1 AS Tvector, scale
//scalar division of a vector with result returned AS new vector
//used TO scale a vector
LOCAL result AS Tvector
result.x=vec1.x/scale
result.y=vec1.y/scale
result.z=vec1.z/scale
RETURN result
ENDFUNCTION

FUNCTION vector_conjugate AS Tvector: vec1 AS Tvector
//conjugate operator takes the negative of each vector component
//can be used when subtracting one vector from another OR FOR
//reversing the direction of a vector.
//applying conjugate is the same AS reversing a vector
//returns a new vector
LOCAL result AS Tvector
result.x=-vec1.x
result.y=-vec1.y
result.z=-vec1.z
RETURN result
ENDFUNCTION

FUNCTION vector_crossProduct AS Tvector: vec1 AS Tvector, vec2 AS Tvector
//takes vec1 AND vec2 AND returns the cross product vec1 X vec2
//the cross product is a vector perpendicular TO both vec1 AND vec2
//this is the normal of 2 vectors
LOCAL result AS Tvector
result.x=(vec1.y*vec2.z) - (vec1.z*vec2.y)
result.y=(vec1.z*vec2.x) - (vec1.x*vec2.z)
result.z=(vec1.x*vec2.y) - (vec1.y*vec2.x)
RETURN result
ENDFUNCTION

FUNCTION vector_dotProduct: vec1 AS Tvector, vec2 AS Tvector
//calculate AND RETURN the dot product of 2 vectors (distance)
LOCAL result
result=(vec1.x*vec2.x)+(vec1.y*vec2.y)+(vec1.z*vec2.z)
RETURN result
ENDFUNCTION

FUNCTION vector_tripleScalarProduct: vec1 AS Tvector, vec2 AS Tvector, vec3 AS Tvector
//calculate the triple scalar FUNCTION AND RETURN it
LOCAL result
result=           vec1.x * ( (vec2.y*vec3.z ) - (vec2.z * vec3.y) )
result=result + ( vec1.y * ( (-vec2.x*vec3.z) + (vec2.z * vec3.x) ) )
result=result + ( vec1.z * ( ( vec2.x*vec3.y) + (vec2.y * vec3.x) ) )
RETURN result
ENDFUNCTION
Title: Type error?
Post by: Kitty Hello on 2007-Mar-28
if it's a library, remove the GLOBAL statement and put it in a function. This needs improvement, you're right.
Title: Type error?
Post by: bigsofty on 2007-Mar-28
OK, that seemed to fix the compile... do I need to call the new function to initialise the Global Gernot?
Title: Type error?
Post by: Kitty Hello on 2007-Mar-28
unfortunately, yes. That's the thing I have to fix, still.