//#include "transforms.inc" #macro vtransform(vec, trans) #local fn = function { transform { trans } } #local result = (fn(vec.x, vec.y, vec.z)); //<-- DOT-NOTATION IN FUNCTIONS! result #end #macro vinv_transform(vec, trans) #local fn = function { transform { trans inverse } } #local result = (fn(vec.x, vec.y, vec.z)); //<-- DOT-NOTATION IN FUNCTIONS! result #end #declare X = x; #declare Y = y; #declare Z = z; #declare VI = function {transform {translate <0, 0, 0>}} // The sum of the following functions for an vector would give 1 // for any cardinal vector. // The idea being that they would be multiplied by <1, 2, 3> // and then 2 subtracted from the result // giving -1, 0, or 1 for use in a select() function #declare GX = function {pigment {gradient x}} #declare GY = function {pigment {gradient y}} #declare GZ = function {pigment {gradient z}} #declare Vec = function (V) {GX(VI(V, V, V).x, 0, 0).x} // + GY(VI(V).x, VI(V).y, VI(V).z).y, GZ(VI(V).x, VI(V).y, VI(V).z).z) } #declare Vector = array [7] {x, y, z, x+y, x+z, y+z, x+y+z} #local _vectors = dimension_size (Vector, 1)-1; #for (i, 0, _vectors) #declare Test = VI (Vector[i].x, Vector[i].y, Vector[i].z); //<-- DOT-NOTATION IN FUNCTIONS! //#debug concat( "Test = ", vstr(3, Test, ", ", 0, 3), " \n") #end //********************************************************************************************************* // AND HERE'S WHERE IT GETS INTERESTING, FOLKS! //********************************************************************************************************* #declare f_r = function {internal(57)} #declare VS = function {transform {scale <1, 2, 3>}} #declare AxisID = array[3] {"x axis", "y axis", "z axis"} #macro Axis (V) #local Result = f_r (VS(V.x, V.y, V.z).x, VS(V.x, V.y, V.z).y, VS(V.x, V.y, V.z).z)-2; //<-- DOT-NOTATION IN FUNCTIONS! Result #end //#debug concat (str (Axis (z), 0, 0), "\n") #declare Value = function (A) {select (A, -1, 0, 1)} // Since vector dot-notation IS apparently allowed in certain specific instances, // we need a way to "inject" the vector quantity identifier into the function VM // and we can do that by using the vector as a macro argument that gets passed as // a function argument #declare FunctionTest = Value (Axis(<0, 0, 1>)); #debug concat (str (FunctionTest, 0, 0), " = ", AxisID[FunctionTest+1], "\n") #declare S1 = function {transform {scale <1, 1, 1>}} #macro VX (V) #local Result = f_r (S1(V.x, V.y, V.z).x, 0, 0); //<-- DOT-NOTATION IN FUNCTIONS! Result #end #macro VY (V) #local Result = f_r (0, S1(V.x, V.y, V.z).y, 0); //<-- DOT-NOTATION IN FUNCTIONS! Result #end #macro VZ (V) #local Result = f_r (0, 0, S1(V.x, V.y, V.z).z); //<-- DOT-NOTATION IN FUNCTIONS! Result #end #declare M = <1, 2, 3>; #debug concat ("X value = ", str (VX(M), 0, 0),"\n") #debug concat ("Y value = ", str (VY(M), 0, 0),"\n") #debug concat ("Z value = ", str (VZ(M), 0, 0),"\n") #declare FunctionVector = S1(VX(M), VY(M), VZ(M) ); #debug concat( "FunctionVector = ", vstr(3, FunctionVector, ", ", 0, 3), " \n") #declare FunctionVector2 = S1(VX(<1, 2, 3>), VY(<1, 2, 3>), VZ(<1, 2, 3>) ); #debug concat( "FunctionVector2 = ", vstr(3, FunctionVector2, ", ", 0, 3), " \n") #error "No objects in scene"