View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric;
2   
3   import java.util.UUID;
4   import java.util.concurrent.Future;
5   import java.util.logging.Logger;
6   
7   import javax.vecmath.Vector3d;
8   
9   import cz.cuni.amis.pogamut.base.agent.module.SensomotoricModule;
10  import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEventListener;
11  import cz.cuni.amis.pogamut.base.communication.worldview.object.event.WorldObjectUpdatedEvent;
12  import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
13  import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
14  import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
15  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AutoTraceRay;
16  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AutoTraceRayMessage;
17  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
18  
19  public class RaycastingBSP extends SensomotoricModule<UT2004Bot> {
20  	
21  	int counter = 0;
22  	private String idSuffix;
23  	
24  	private IWorldObjectEventListener<Self, WorldObjectUpdatedEvent<Self>> selfListener = new IWorldObjectEventListener<Self, WorldObjectUpdatedEvent<Self>>() {
25  
26  		@Override
27  		public void notify(WorldObjectUpdatedEvent<Self> event) {
28  			selfUpdate(event.getObject());
29  		}
30  		
31  	};
32  
33      public RaycastingBSP(UT2004Bot bot) {
34          this(bot, null);
35      }
36      
37      
38  	public RaycastingBSP(UT2004Bot bot, Logger log) {
39          super(bot, log);
40          
41          idSuffix = "_" + bot.getName() + UUID.randomUUID().toString();
42          
43          bot.getWorldView().addObjectListener(Self.class, WorldObjectUpdatedEvent.class, selfListener);
44      }
45      
46      /**
47       * Whether we have BSP data for raycasting.
48       * @return
49       */
50      public boolean isUsable() {
51      	return false;
52      }
53  
54      /**
55       * Deletes all previous rays and makes this instance ready for setting up
56       * new rays.
57       */
58  	public void clear() {
59  	}
60  
61  	public Future<AutoTraceRay> createRay(Vector3d direction, int length, boolean floorCorrection) {
62  		String id = counter++ + idSuffix;
63  		return createRay(id, direction, length, floorCorrection);
64  	}
65  
66  	public Future<AutoTraceRay> createRay(String id, Vector3d direction, int length, boolean floorCorrection) {
67  		// TODO
68  		UnrealId unrealId = UnrealId.get(id);
69  		return null;
70  	}
71  	
72  	protected void selfUpdate(Self self) {
73  		// RECOMPUTE AutoTraceRay(s)
74  		
75  		
76  //		AutoTraceRay ray = new AutoTraceRayMessage(
77  //			// unrealId ray z createRay()
78  //			// Location From == self.getLocation()  
79  //			// Location To   == end of ray
80  //			// boolean FastTrace == false
81  //			// boolean FloorCorrection
82  //			// boolean Result
83  //			// Vector3d HitNormal
84  //			// Location HitLocation
85  //			// boolean TraceActors == false
86  //			// UnrealId HitId == null
87  //		);
88  //		
89  //		agent.getWorldView().notify(ray);
90  	}
91  
92  
93  }