The TORCS Racing Board
Username: Password: Remember Me?
Lost Password Register
Author: muton | Created: 2019-06-19 06:06:54
Subject: How to determine whether the specified coordinate position is on or off the course
Hi All.

I succeeded in drawing the predicted values (position coordinates in the race) on the course.
Next, I would like to determine whether the predicted value (position coordinates in the race) is on the course or off the course.
However, I do not know how to add code.
Can someone help me?
Last Edited: 2019-06-19 06:06:54 by muton
    Author: muton | Created: 2019-06-21 15:42:13
    Subject: Re: How to determine whether the specified coordinate position is on or off the course
    I have considered the following two methods for myself, is it possible with either method?
    I'm glad if anyone can give me advice.

    1. Determine by acquiring the pixel color of the position you want to determine for the image of the course. If it is possible to know the color or color range that corresponds to the course.

    2. Use polygon mesh of model data of course or terrain
    For triangle vertices of polygons that correspond to textures and materials that correspond to the course
    If the height information can be ignored, it can be judged by the cross product inside and outside.
    Outside the course if it is outside all the triangles that correspond to the course.
    Last Edited: 2019-06-21 15:42:24 by muton
      Author: timfoden | Created: 2019-06-22 18:22:12
      Subject: Re: How to determine whether the specified coordinate position is on or off the course
      There are a number of Rt* routines that query the track, and one of them returns the track local position, from which inside the track or not can be discovered.

      e.g.

      #include <robottools.h>

      tTrkLocPos trkPos;
      RtTrackGlobal2Local(car->_trkPos.seg, myGlobalX, myGlobalY, &trkPos, TR_LPOS_MAIN);
      bool inside = fabs(trkPos.toMiddle) < trkPos.seg->width / 2;
      Last Edited: 2019-06-22 18:22:12 by timfoden
        Author: muton | Created: 2019-06-25 10:42:33
        Subject: Re: How to determine whether the specified coordinate position is on or off the course
        Thank you for answering

        As a result of examining based on what you had taught,
        It was possible to define whether the coordinate position is on the course.
        Last Edited: 2019-06-25 10:42:33 by muton