Track editor help required

Blitz3D Forums/Blitz3D Programming/Track editor help required

CyberHeater(Posted 2003) [#1]
I'm writing a racetrack editor and have a pretty funky interface where you can design your track with anchor points which define hermite splines which is easy to use and looks great.



All these dots are defined in a array. Has anyone got a useful routine that will convert these anchor point data to a 3d mesh. I've looked at addvertex comands but got in a bit of a state.

This will be released to the community with source when i'm done.


Stevie G(Posted 2003) [#2]
Something like this should help - not tested I'm afraid but used this method to create my own tracks ...

Assuming your points are held in an array ..
pointx(2,nopoints), pointz(2,nopoints)

Where pointx(1,..) and pointz(1,..) hold the x & z position of your initial track points.



for a=0 to nopoints-1

;get next point
b=(a+1) mod nopoints

;get vector from point a to point b
dx#=pointx(1,b)-pointx(1,a)
dz#=pointz(1,b)-pointz(1,a)
d#=sqr( dx*dx+dz*dz)

;normalise vector
dx=dx/d:dz=dz/d

;get points perpendicular to point a

;point to left
pointx(0,a)=pointx(1,a)-dz*trackwidth
pointz(0,a)=pointz(1,a)+dx*trackwidth

;point to right
pointx(2,a)=pointx(1,a)+dz*trackwidth
pointz(2,a)=pointz(1,a)-dx*trackwidth

next



Once you have this you can then build the track mesh from the new perpendicular points like this ..



mesh=createmesh():s=createsurface(mesh)

for a=0 to nopoints-1
;get next point
b=(a+1) mod nopoints
;add the 4 points to the mesh
v0 = addvertex (s,pointx(0,a),0,pointz(0,a))
v1 = addvertex (s,pointx(0,b),0,pointz(0,b))
v2 = addvertex (s,pointx(2,b),0,pointz(2,b))
v3 = addvertex (s,pointx(2,a),0,pointz(2,a))
addtriangle s,v0,v1,v2
addtriangle s,v2,v3,v0
next

...............


CyberHeater(Posted 2003) [#3]
Thanks. I'll give it a try.


WebDext(Posted 2003) [#4]
You also might want to create a list of verteces for the left and right edges initially then step through them and check to make sure that they are not too close together, so you won't get sliver shaped triangles on tight corners.

The other thing you may need to do is check tight corners for intersections so that the track polygons don't overlap wierd.

Just some thoughts...
Jack


Stevie G(Posted 2003) [#5]
Yeh Jack - ran into that problem too ...

I found that just averaging the previous, current and next perpendicular points made it much smoother but I guess it depends on how wide you want the track to be.