[Pogamut-list] RayCasting Bot
jakub.gemrot
pogamut-forum at artemis.ms.mff.cuni.cz
Wed Oct 1 07:32:11 CEST 2008
Re: RayCasting Bot
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
// 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);
}
Now - how to query those sensors:
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 ;-)
}
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
----
Reply Link: <https://artemis.ms.mff.cuni.cz/pogamut/tiki-view_forum_thread.php?forumId=6&comments_reply_threadId=246&comments_parentId=243&post_reply=1#form>
More information about the Pogamut-list
mailing list