[Pogamut-list] RayCasting Bot
cazub
pogamut-forum at artemis.ms.mff.cuni.cz
Fri Oct 3 06:54:02 CEST 2008
Re: RayCasting Bot
Hi jakub,
Ok with your code it seems to be running MUCH faster but, not working still :(
Trace frontTrace = memory.getAutoTrace(RAY_STRAIGHT);
I had to change that to AutoTrace frontTrace , thats nota big deal and i got that working fine. It was however crashing (EXCEPTION in the Out Log) because of a null pointer. So i put some code in to check for this null pointer first, now i'm up and running but it seems memory.getAutoTrace() isn't ever returning anything. Heres my chunk of code:
//---------------------------------START CODE AFTER IMPORTS-------------
//inside the main class ,
//DECLARATIONS:
public static final double SENSOR_LENGTH = 50;
public static final int RAY_STRAIGHT = 0;
public static final int RAY_LEFT = 1;
public static final int RAY_RIGHT = 2;
public static final int RAY_STRAIGHT_UP45 = 3;
//AutoTraces to hold results
AutoTraceRay traceStraight, traceLeft, traceRight, traceStraightUp45;
AutoTraceRay autorayStraight; //tmp for debugging
double distStraight; //single distance variable for debugging
/** Creates a new instance of agent. */ //put here by pogamut
public Main() {
}
// this mehthod is called before the agent is launched to the UT
@Override
protected void postPrepareAgent() throws PogamutException {
// first, remove all existing rays
body.removeAllRaysFromAutoTrace();
body.addRayToAutoTrace(RAY_STRAIGHT, new Triple( 1, 0, 0), SENSOR_LENGTH, false, true);
body.addRayToAutoTrace(RAY_LEFT, new Triple( 1, 1, 0), SENSOR_LENGTH, false, true);
body.addRayToAutoTrace(RAY_RIGHT, new Triple( 1, -1, 0), SENSOR_LENGTH, false, true);
body.addRayToAutoTrace(RAY_STRAIGHT_UP45, new Triple( 1, 0, 1), SENSOR_LENGTH, false, true);
body.initializer.setAutoTrace(true);
}
//END postPrepareAgent()
//now for the DOlogic section-----------
//------------------------------------------------------------------------
protected void doLogic() {
//example from Pogamut Jakub
autorayStraight = memory.getAutoTrace(RAY_STRAIGHT);
if(autorayStraight == null){
body.sendGlobalMessage("Front ray = NULL");
}
else if (autorayStraight.result) {
distStraight = Triple.distanceInSpace(memory.getAgentLocation(), autorayStraight.hitLocation);
body.sendGlobalMessage("distance in front = " +distStraight);
if(distStraight
----
Reply Link: <https://artemis.ms.mff.cuni.cz/pogamut/tiki-view_forum_thread.php?forumId=6&comments_reply_threadId=248&comments_parentId=243&post_reply=1#form>
More information about the Pogamut-list
mailing list