Make a curve...

Blitz3D Forums/Blitz3D Programming/Make a curve...

Tab(Posted 2008) [#1]
Hello...

i'm working now in a roads system... but i have a problem...

I need deform a mesh in real time with VertexCoords, and transform the mesh in the screenshot in to a 90º perfect curve, something like the second image...

Thx for any idea or example.






Leon Drake(Posted 2008) [#2]
did you try using pivots with children and rotateentity to get the rotated points coords then use vertexcoords to update the road?


Tab(Posted 2008) [#3]
My real problem is with the algorithm to move all vertex to the position to make the curve.

Thx.


markcw(Posted 2008) [#4]
Screenshot doesn't work.


Gillissie(Posted 2008) [#5]
I've done something similar, but I created the mesh programmatically instead of using a pre-made mesh. This makes it easier to deal with the vertices since you create them yourself and know the order they're in.

I assume you will want to assign UV coordinates to your road section too, so that no matter how it bends, the road texture sticks to it.

It's fairly complicated to explain without some code examples, so I'm sorry if I just confused you further.

Hints: Cos, Sin, CreateMesh, CreateSurface, AddVertex. You'll need your start and end angle of the curve, as well as the radius.

BTW, do you really need to deform it in realtime, or a one-time deformation during runtime of the game?


Ross C(Posted 2008) [#6]
Well, it should be slightly easier if the curve is one quarter of a circle. You can use, as the other poster says, sin and cos.

You would place a vertex at a division of 90/number of road segments.

ie.

meshsegments = 10

interval = 90/ meshsegments

which equals 9. Then you need a distance or raduis value. Ie. distance from the curves centre point.

If you know how the mesh is built as mentioned by Gillissie, it should be very straight forward to loop through each vertex, then place it at the required distance from the curve centre point. Something like:

For segments_vertical = 1 to 10 ; (in the case of above)

   For segments_horizontal = 1 to 4 (the segments horizontally)

      x = cos(9*segments_vertical) * distance_from_centre *segments_horizontally
      y = sin(9*segments_vertical) * distance_from_centre * segments_horizontally
      place vertex at x , y , z

   next

next



Obviously the code above won't complie, but it will maybe give you a start :o)


markcw(Posted 2008) [#7]
Why are you linking to images with no text in the link??

Let me help...

road.jpg
curve.JPG


Ross C(Posted 2008) [#8]
The images work for me :o)


Tab(Posted 2008) [#9]
wow... thx for all your support.

@Ross C
Your code works nice, only need some changes.
Thx again for your help.


Tab(Posted 2008) [#10]
Ok, definitely stuck again... I can modify curves to 90º, but when i try 89º or less, everything goes wrong.

Please, help me again... >_>


Ross C(Posted 2008) [#11]

You would place a vertex at a division of 90/number of road segments.



It should just be a case of changing that to 89 deg. I'll need to see when i get home.


Ross C(Posted 2008) [#12]
Ok, it really should just be a case of changing the multiplier value to

For segments_vertical = 1 to 10 ; (in the case of above)

   For segments_horizontal = 1 to 4 (the segments horizontally)

      x = cos(8.9*segments_vertical) * distance_from_centre *segments_horizontally
      y = sin(8.9*segments_vertical) * distance_from_centre * segments_horizontally
      place vertex at x , y , z

   next

next


To 8.9, as 89 deg divided by 10 segments = 8.9 :o)


Stevie G(Posted 2008) [#13]
Best to also make sure x, y & z are floats.


Ross C(Posted 2008) [#14]
OFF TOPIC: Sorry, i sent that model to your email stevie.


Tab(Posted 2008) [#15]
All work fine now... thx for your help Ross C.