[Pogamut-list] RayCasting Bot

Jakub Gemrot jakub.gemrot at gmail.com
Wed Oct 1 07:30:25 CEST 2008


Hi Cazub!

How are you adding the rays to the bot? Where do you use your new constants?

Here is a Java code you're likely to need to add and tweak into your bot
<code>
// this mehthod is called before the agent is launched to the UT
protected void postPrepareAgent() throws PogamutException {
        // first, remove all existing rays   	
        body.removeAllRaysFromAutoTrace();

        // now add your custom rays

        // LEFT_SENSOR == integer constant you will need to query the sensor
        // new Triple(1, -1, 0) == x-coord pointing straight ahead,
y-coord goes from the left to the right, z-coord goes from down to up
(i think)
        // SENSOR_LENGTH == number, how long it should be
        // false, true == do the full raycasting (advised)
        body.addRayToAutoTrace(LEFT_SENSOR, new Triple(1, -1, 0),
SENSOR_LENGTH, false, true);
        body.addRayToAutoTrace(RIGHT_SENSOR, new Triple(1, 1, 0),
SENSOR_LENGTH, false, true);
        body.addRayToAutoTrace(FRONT_SENSOR, new Triple(1, 0, 0),
SENSOR_LENGTH, false, true);

        // tell the GB2004 you want to do those raycasts automatically
        body.initializer.setAutoTrace(true);
    }
</code>

Now - how to query those sensors:

<code>
   Trace frontTrace = memory.getAutoTrace(FRONT_SENSOR);

   if (frontTrace.result) {
      // if boolean means it hit something ...

      // now examine the distance to the obstacle in the way of the sensor
      double distance =
Triple.distanceInSpace(memory.getAgentPosition(),
frontTrace.hitLocation);

      // do something cool here ;-)
   }

</code>

I believe that you need to tweak postPrepareAgent() to get your new
traces working + next code is showing you how
to examine the trace results.

Last advise - I reccommand you to get those results in the beginning
of the doLogic() to have it as correct as possible.

Cheers, Jakub


On Wed, Oct 1, 2008 at 1:16 AM, cazub
<pogamut-forum at artemis.ms.mff.cuni.cz> wrote:
> Re: RayCasting Bot
> Ooops! forgot one Q, is it possible to cast some sort of ray with pogamut where the length is what gets returned? What i mean is a raycasting function where the bot shoots a ray out and can return the distance to the first item or wall hit?
>
> So like My bot is running foward and casts a ray foward and receives a distance of 500, this means nothing is blocking his way. THen lets say he casts a ray and the distance returned is 25, then he knows a wall or obstacle is close and he should turn.
>
> A function like this would be very helpful for a dynamically mapping bot.
>
> ----
>
> Reply Link: <https://artemis.ms.mff.cuni.cz/pogamut/tiki-view_forum_thread.php?forumId=6&comments_reply_threadId=244&comments_parentId=243&post_reply=1#form>
>
>
> _______________________________________________
> Pogamut-list mailing list
> Pogamut-list at artemis.ms.mff.cuni.cz
> https://artemis.ms.mff.cuni.cz/mailman/listinfo/pogamut-list
>



More information about the Pogamut-list mailing list