# OpenGL Implementing a Car Racing Track

This topic is 3477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by sion5I 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.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 21
• 12
• 11
• 41
• ### Forum Statistics

• Total Topics
631401
• Total Posts
2999871
×