Jump to content

Help with drawing a simple street for a car game

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
giovaniluigi

giovaniluigi

    Newbie

  • Members
  • Pip
  • 1 posts
Hi,

I'm doing an app like a car game.

I need to paint over a vector of points connected forming a line.
The paint is like a street.
Here is an example: I have a red trace that is the sight for drawing a street on it.

The origin of this red line is from GPS coordenates.

Here is a picture of what I'm talking about:

Posted Image

The problem is described by the image.:rules:

I need to rotate the rectangles to follow the line.:glare:

I did all using GDI+ Transformations, but this problem I don't know how to solve.:irritated:

I can rotate one by one, but the more the design grows, the slower will be the application. I'm talking about thousands of points to form the line, because the code it's on the onPaint event of a picturebox.

Anyone can help me ?

Any ideas ? Please!:worry:

Thank you in advance.

#2
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
Basically you need to know the slope of the curve at the given point. From the slope you can get the angle of the curve at that exact point to be used to rotate the rectangles. Remember that the slopes were tangent values of the angles. Sorry that my trigonometry is rusty right now, but the basic formula is either

Quote

y=mx
or

Quote

y=-mx

Where:
x = position in horizontal axis
y = position in vertical axis
m = the slope

Also perhaps you could combine that equation with this one:

Quote

m=y-y'/x-x'
this one is helpful to calculate the slope from coordinates that slightly different from the current one (sounds like differential calculus, right?).

giovaniluigi said:

I can rotate one by one, but the more the design grows, the slower will be the application. I'm talking about thousands of points to form the line, because the code it's on the onPaint event of a picturebox.

Then don't do the calculation everytime in realtime. Just do it once and store the result along with the coordinate it is for. So it should be like:

For each coordinate do

  If we haven't calculate the angle do

    calculate angle

    store angle with coordinate

  Rotate the rectangle by the angle from current coordinate

  Draw the rectangle