GALERIE    EN COURS    SCENES    MACROS    GUIDE    A PROPOS


Triangles following curve
spline{} or other

triangles follow spline
As you see, there is somes issues along the path...


The main loop :
#declare index=0;
#while(index<360)
  object {
    Triangle
    curve_Trans (radians(index), y, 0.10)
    }
  #declare index=index + 2;
#end


The curve_Trans macro :
#macro curve_Trans (Time, Sky, Foresight)
  #local Location = <0,0,0> + myFunc(Time);
  #local LocationNext = <0,0,0> + myFunc(Time + Foresight);
  #local LocationPrev = <0,0,0> + myFunc(Time-Foresight);
  #local Forward = vnormalize(LocationNext-Location);
  #local Right = VPerp_To_Plane(Sky,Forward);
  #local Up = VPerp_To_Plane(Forward,Right);
  #local Matrix = Matrix_Trans(Right,Up,Forward,Location)
  transform {
    transform Matrix
    }
#end


Here, the curve defined by a function, but the problem is the same with a spline :
// --------------------------------------------------------------------------
// --- CURVE FUNCTION -------------------------------------------------------
//     x = cos(t) + 2.cos(2.t)
//     y = sin(t) - 2.sin(2.t)
//     z = 2.e.sin(3.t)
// --------------------------------------------------------------------------
#macro myFunc(thisTime)
  < cos(thisTime) + 2*cos(2*thisTime),
    sin(thisTime)-2*sin(2*thisTime),
    2*sin(3*thisTime)>
#end


Some add-in that helps :
// --- Returns a vector perpendicular to V1 and V2
#macro VPerp_To_Plane(V1, V2)
  (vnormalize(vcross(V1, V2)))
#end

// --- VRotation() will find the rotation angle from V1 to V2 around Axis.
#macro VRotation(V1, V2, Axis)
  (acos(min(vdot(vnormalize(V1),vnormalize(V2)),1))*(vdot(Axis,vcross(V1,V2))<0?-1:1))
#end

/ --- Projects a vector onto the plane defined by Axis.
#macro VProject_Plane(V, Axis)
  #local A = vnormalize(Axis);
  (V - vdot(V, A)*A)
#end

#macro Matrix_Trans(A, B, C, D)
  transform {
    matrix < A.x, A.y, A.z,
            B.x, B.y, B.z,
            C.x, C.y, C.z,
            D.x, D.y, D.z>
     }
#end