List Info

Thread: Bezier / Vector Shape




Bezier / Vector Shape
user name
2006-11-29 00:03:29
Hi Wille,

thanks a lot for sharing the code with me.

I tried a very similar approach using some source code
I got on directoronline but it had the same problem I'm
having with yours. My problem is as follows:

I have a race track. I'm using a vectorshape with the same
shape as the track. My idea is that a few cars move at
CONSTANT speed on the track. My problem seems to
be that. I need smooth and constant speed. 

Your method seems to make my car go faster when beziers
are larger and slower when the curves are shorter.

How can I accomplish the same speed still having a very
smooth
movement. I'm not too good in maths...

Thanks a lot in advance,

Min

----- Original Message ----
From: Wille Frankenhaeuser <willesulake.com>
To: Director - Shockwave - and Flash Game Production
<dirgames-lnuttybar.drama.uga.edu>
Sent: Tuesday, November 28, 2006 9:44:47 AM
Subject: Re: [dirGames-L] Bezier / Vector Shape

Minyer Jolibem wrote:
> Hello,
>
> I have a lot of vector shape members (not closed)
> I would like to create a function like this:
>
> pointList = loadPoints(vectorShapeMemberName)
>
> So I can have in pointList the list of points of the
vector shape.
> That will allow me to move a little car over the curves
smoothly
> backwards and forward. 
>
> Would some one please give me some help? I tried all. I
used
> an example from director online but's not working.
>
> Any help will be much appreciated,
>
> Thanks
> Min
>
>   
Hello Min,

the following is a global moviescript-function, by adjusting
a_iSteps 
you can control how many points are drawn in between
vertexpoints, i.e. 
how smooth the resulting bezier-curve is:

-- vectorShapePoints("vectorshape", 12, true)
on vectorShapePoints(a_sMemName, a_iSteps, a_bClosed)

 t_ar_VertexList = member(a_sMemName).vertexList

 if(a_bClosed) then
   t_ar_VertexList.append(t_ar_VertexList[1])
 end if

 t_ar_polygon = []
 repeat with i = 1 to t_ar_VertexList.count - 1
   repeat with j = 1 to a_iSteps
     p1 = t_ar_VertexList[i][#vertex]
     p2 = t_ar_VertexList[i][#vertex]   +
t_ar_VertexList[i][#handle1]
     p3 = t_ar_VertexList[i+1][#vertex] +
t_ar_VertexList[i+1][#handle2]
     p4 = t_ar_VertexList[i+1][#vertex]
     t = (j/(a_iSteps *1.0))
     t_rP = interpolateCubicBezier( t, p1, p2, p3, p4 )
     t_ar_polygon.append(t_rP)
   end repeat     end repeat

 -- Draw
 repeat with i = 1 to t_ar_polygon.count - 1
   p1 = t_ar_polygon[i]
   p2 = t_ar_polygon[i+1]
   _movie.stage.image.draw(p1, p2, [#shapeType:#line,
#lineSize:1, 
#color: rgb(0, 0, 0)])
 end repeat    updatestage

end

on interpolateCubicBezier( t, p1, p2, p3, p4 )
 u=1.0-t
 v=3.0*u*t
 return u*u*u*p1+u*v*p2+v*t*p3+t*t*t*p4
end

Best,
Wille
_______________________________________________
dirGames-L mailing list  -  dirGames-Lnuttybar.drama.uga.edu
http://nuttybar.drama.uga.edu/mailman/listinfo/dirgames
-l







 
____________________________________________________________
________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
_______________________________________________
dirGames-L mailing list  -  dirGames-Lnuttybar.drama.uga.edu
http://nuttybar.drama.uga.edu/mailman/listinfo/dirgames
-l
Bezier / Vector Shape
user name
2006-11-29 08:02:31
 

> thanks a lot for sharing the code with me.
> 
> I tried a very similar approach using some source code
I got 
> on directoronline but it had the same problem I'm
having with 
> yours. My problem is as follows:
> 
> I have a race track. I'm using a vectorshape with the
same 
> shape as the track. My idea is that a few cars move at 
> CONSTANT speed on the track. My problem seems to be
that. I 
> need smooth and constant speed. 

This is possible but difficult. The problem is that there
isn't a simple
formula for calculating the length of a (cubic) Bezier
curve, which is what
you need for your situation. The only simple solution is to
approximate the
curve with line segments, then traverse your line segments
at the speed you
want to use.

Best
Danny
 

_______________________________________________
dirGames-L mailing list  -  dirGames-Lnuttybar.drama.uga.edu
http://nuttybar.drama.uga.edu/mailman/listinfo/dirgames
-l
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )