PDA

Click to See Complete Forum and Search --> : Following Path


gwdash
Sep 14th, 2000, 05:01 PM
Does any one have an algorithim to make a sprite follow a path (a network) by knowing the nodes.
i.e. if i give the coords (140,60), etc. can the algorithim, make a sprite follow the path between the points. Also, how do i rotate a sprite in DirectDraw(Is BltFx the only way, and can it rotate at angles, or just flip)

PaulLewis
Sep 14th, 2000, 05:07 PM
I'm no graphics expert nor a games programmer however it occurs to me that you need to use simple trig or vector arithmetic to do this.

Other considerations are whether the sprite must always face a certain direction or if it's "node" is always facing the direction of travel.

If the latter, then you need to do a little more than follow the path because at each change in gradient you need to adjust the sprite direction. If all the paths are straight lines then this is easily done at each vertex.

If nobody gives you exactly what you need, I can help with the vector or trig side of things as Mathematics is a hobby :)

Cheers
Paul Lewis

gwdash
Sep 14th, 2000, 05:08 PM
it's the later, the sprite needs to rotate at each vertex.

PaulLewis
Sep 14th, 2000, 07:48 PM
How about if I write some simple code that will allow the traversal of a path made up of arbitary points returning at each vertex the new angle of rotation required and the distance to the new target?

I will make a gui that allows you to click a few points to generate your path, then press a button to "watch" as the path is traversed. All it will be missing is the sprites that you will add in.

Sound ok to you?

gwdash
Sep 14th, 2000, 09:18 PM
go for it. Thats exactly what i want!!!

PaulLewis
Sep 14th, 2000, 10:07 PM
It's not on your profile and the code is longer than is reasonable to post.

Regards

gwdash
Sep 14th, 2000, 10:08 PM
gdasher@mn.rr.com

PaulLewis
Sep 14th, 2000, 10:18 PM
It's actually a modified version of a project I did for another topic on this forum.

I actually posted the previous version to someone else on here just earlier today. This version does the following:

Allows you to plot a series of points for a path to traverse (the code closes the path to make a polygon as that is what it was originally designed to do.

Allows you to generate a pseudo-random polygon of n sides.

Allows you to Save / Load the series of points in your path to disk.

Allows you to click on the picturebox and start the traversal of the path. As the path is traversed if in the default "debug mode" an info box appears giving details of distance and angle (in degrees) to reach the next point.

Once the path has been traversed, the program will indicate if the point you specified is either inside the shape, outside the shape or on the edge of the shape.

When the settings are set to enable crosshair, enable on move, disable all debug info, the program will indicate whether the mouse is inside, outside or on the edge in real time.

The project isn't pretty as far as naming conventions etc go, but it should be relatively bug free.

I thing the maths in the pclPolygon and pclPoint classes will be what you are most interested in.

Good luck. When you let me know your email address I will zip it up and send it to you.

Regards

kedaman
Sep 15th, 2000, 07:06 AM
For your other problem with DirectDraw, i think you can flip with blt (i'm not sure but if it works with paintpicture then why not with blt? I don't have vb on this comp so i can't test but you could try) What you do is giving the rect.top value a larger value than rect.bottom, so you invert the positions, and to mirror you invert the left and right values. Good luck!
I'm sure there is a way to rotate too but i think it's slow, i'll check it out when i have time.