Make a curve...
Blitz3D Forums/Blitz3D Programming/Make a curve...
| ||
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. ![]() |
| ||
did you try using pivots with children and rotateentity to get the rotated points coords then use vertexcoords to update the road? |
| ||
My real problem is with the algorithm to move all vertex to the position to make the curve. Thx. |
| ||
Screenshot doesn't work. |
| ||
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? |
| ||
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) |
| ||
Why are you linking to images with no text in the link?? Let me help... road.jpg curve.JPG |
| ||
The images work for me :o) |
| ||
wow... thx for all your support. @Ross C Your code works nice, only need some changes. Thx again for your help. |
| ||
Ok, definitely stuck again... I can modify curves to 90º, but when i try 89º or less, everything goes wrong. Please, help me again... >_> |
| ||
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. |
| ||
Ok, it really should just be a case of changing the multiplier value toFor 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) |
| ||
Best to also make sure x, y & z are floats. |
| ||
OFF TOPIC: Sorry, i sent that model to your email stevie. |
| ||
All work fine now... thx for your help Ross C. |