Implementing a Car Racing Track

Started by
2 comments, last by staticVoid2 15 years, 4 months ago
Ok, sorry for the bombardment of info but here is what i'm trying to do. FYI I use C++ and OpenGL. I want to create a racing track, can be a simple oval, complexity isnt an issue. I'm implementing a NN to drive the car so the car will have 2 "feelers" of set length, and the feelers will report an intersection with the edge or wall of the track (so that the NN can do its thing and sort itself out). [img=http://img369.imageshack.us/img369/4827/carfeelersyw2.jpg] So the design contraints are whether its 2D or 3D there must be a way of reporting how much of the green feelers have left the track (or intersected a wall on a 3D track). My question is: How can I put a track in the game (easiest way)? with that method of implementation how will I establish how much of the feeler has left the track?
Feeling #0000FF
Advertisement
you could use a simple line - plane intersection test, if you have constructed walls as 3d geomtery around the track, i.e. a triangle mesh indicating a wall is there then you can use this data to test for an intersection, simply loop through all triangles, test for the intersection and find the point of intersection of the triangle that intersected, most algorithms for finding an intersection give you the intersection point as a value between 0.0 and 1.0, if you want to finds the point of intersection you would do: p = p0 + ((p1 - p0) * a) where a is the ratio between 0 and 1, p0 and p1 are the two points of the line segment, or in this case the feelers. this can be easily transfered to 2d by replacing the mesh with line segments and testing for a 2d line - line intersection.
I am quite comfortable with loading in 3D models so may make something similar in max/maya and load it in. I have come accross line plane intersections before but was a little unsure as to whether this was the right scenario to use it.

The 2D version seems a little more complex as how will the intersection testing work on curves (a bend)? a quick google brings up some ugly looking math :-s
Feeling #0000FF
Quote:Original post by sion5
I am quite comfortable with loading in 3D models so may make something similar in max/maya and load it in. I have come accross line plane intersections before but was a little unsure as to whether this was the right scenario to use it.

The 2D version seems a little more complex as how will the intersection testing work on curves (a bend)? a quick google brings up some ugly looking math :-s


if you are using some other structure like a bezier curve then you can just break it up into line segments, but for a full curve-line intersection it requires complex maths and will probaly be less efficient in the end.

you can still get realistic results by just using x-amount of line segments per curve, this is the exact same thing you would be doing with a 3d mesh exept you would be using triangles instead of lines.

This topic is closed to new replies.

Advertisement