|
![](/i/fill.gif) |
//my suggestion (with clock 0-1)
//-------------------------------------------------------
// truck-and-trailer problem
// POV-implementation
// (c) 2002 J. Diehl
// http://enter.diehlsworld.de
//-------------------------------------------------------
//-------------------------------------------------------
// some math macros
//-------------------------------------------------------
//the main macro to drive a pole to a given destination (NewX,NewY)
//it computes the new position and angle of the pole
#macro driveTo (Pole, NewX,NewY)
//get the vector [axle --> new position]
#declare dx=NewX-PosX[Pole];
#declare dy=NewY-PosY[Pole];
//get the new position of the pole
#declare d=sqrt(dx*dx+dy*dy);
#declare tomove=d-Length[Pole];
#declare PosX[Pole]=PosX[Pole]+dx/d*tomove;
#declare PosY[Pole]=PosY[Pole]+dy/d*tomove;
//get the new position of the back link
#declare LinkPosX[Pole]=PosX[Pole]-dx/d*LinkDist[Pole]
#declare LinkPosY[Pole]=PosY[Pole]-dy/d*LinkDist[Pole]
//get the angle of the pole
#declare Angle[Pole]=0;
#if (d!=0)
#declare Angle[Pole]=atan2(dx,dy)/pi*180;
#end
#end
//a macro for a simple path (very simple, of course! - a line)
//Put your own spline here
#declare ax=-10;
#declare ay=6;
#declare ex=30;
#declare ey=40;
#macro getPath(time)
#declare PathX=ax*(1-time)+ex*time;
#declare PathY=ay*(1-time)+ey*time;
#end
//-------------------------------------------------------
//definition of poles
//-------------------------------------------------------
#declare Poles=2;
#declare PosX=array[Poles]
#declare PosY=array[Poles]
#declare Length=array[Poles]
#declare Angle=array[Poles]
//variables for back link
#declare LinkPosX=array[Poles]
#declare LinkPosY=array[Poles]
#declare LinkDist=array[Poles]
//the initial position of each pole is the position where it was 'parked'
before linking first.
//it affects the direction the pole will be linked to the previous in the
first step.
#declare PosX[0]=20;
#declare PosY[0]=0;
#declare Length[0]=6;
#declare LinkDist[0]=5;
#declare PosX[1]=0;
#declare PosY[1]=2;
#declare Length[1]=18;
#declare LinkDist[1]=0;
//-------------------------------------------------------
//Follow the path
//-------------------------------------------------------
#declare myclock=clock;
//since we can't store the actual position from one frame to the next,
//we have to follow the path up to the current frame everytime.
//the smaller the steps, the more realistic the movement
#declare time=0;
#declare step=0.001;
#while (time <= myclock)
getPath(time)
//pole #0 follows the path,
//pole #1 follows pole #0 and so on...
driveTo (0,PathX,PathY)
driveTo (1,LinkPosX[0],LinkPosY[0])
#declare time=time+step;
#end
//-------------------------------------------------------
//draw the scene
//-------------------------------------------------------
camera {location<12,18,12> look_at < LinkPosX[0],0,LinkPosY[0]>}
light_source {<0,3000,0> color rgb 1}
light_source {<1000,1000,1000> color rgb 1}
plane
{
y, 0
pigment {color rgb <0.7,0.6,0.5>}
normal {granite 0.3 scale 5}
hollow on
}
//this one shows the path on the ground the truck will follow
cylinder{< ax,0,ay> < ex,0,ey> 0.2
pigment{color rgb <0,0,1>}
}
//the truck (pole #0)
union{
box{<-1,1.8,-8><1,2,8>}
cylinder{<-2,1,6><2,1,6> 1 pigment {color rgb 0.3}}
cylinder{<-2,1,-3><2,1,-3> 1 pigment {color rgb 0.3}}
cylinder{<-2,1,-6><2,1,-6> 1 pigment {color rgb 0.3}}
pigment {color rgb 0.7}
//first rotate, then translate the whole to the destination
rotate y*Angle[0]
translate < PosX[0],0,PosY[0]>
}
//the trailer (pole #1)
union{
cylinder{<-2,1,1.5><2,1,1.5 > 1 pigment {color rgb 0.3}}
cylinder{<-2,1,-1.5 ><2,1,-1.5 > 1 pigment {color rgb 0.3}}
box{<-1,2.2,-4.5><1,2.4,19.5>}
pigment {color rgb 0.5}
//first rotate, then translate the whole to the destination
rotate y*Angle[1]
translate < PosX[1],0,PosY[1]>
}
Post a reply to this message
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
Thomas van der Veen wrote:
>I just rendered it here at work and it looks great! Now all I need to do is
>to find sometime and implement it....
I'm pleased I could help. And thanks for the idea with Lego models - I'm
just starting with them and experimenting a little. But rebuilding your
truck would take me years... aaargh! Pieces never rest where I want to...!
'Nice' sculptures, though, look a bit like modern art or fractals or...
:-)))
Playing with LeoCAD and exporting to POV, I figured out that the coordinate
system is very different to mine (I'm not the first, I guess). But with
putting the parts into a union and do some rotate <-90,180,0> and scale
1.25 on it, it fits with my coordinates (x=left-right, y=up-down,
z=back-forward, 1 POV unit = 1 brick unit).
You'll have to find some translations for your parts, too. I think it's much
easier than trying to translate my script into any LeoCAD or LDraw
coordinate system.
have a nice time
jo
Post a reply to this message
|
![](/i/fill.gif) |