SimLightSensor |
1 package simworldobjects; 2 3 import interfaces.*; 4 5 /** 6 * Simulates a light sensor 7 * 8 * @author Graham Ritchie 9 */ 10 public class SimLightSensor extends SimSensor 11 { 12 private SimRCX robot; 13 private double xOffset, zOffset; 14 15 /** 16 * Sets up a light sensor on the given SimRCX, and positions it at the 17 * the appropriate offset from the robot's position. 18 * 19 * @param r the SimRCX owner of this sensor 20 * @param xOffset the offest from the SimRCX's x position 21 * @param zOffset the offest from the SimRCX's z position 22 */ 23 public SimLightSensor(SimRCX r, double xOffset, double zOffset) 24 { 25 robot=r; 26 initSimSensor(r,xOffset,zOffset,10.0,10.0,10.0,"sensor"); 27 this.xOffset=xOffset; 28 this.zOffset=zOffset; 29 } 30 31 /** 32 * Returns the current brightness of the world at this sensor's position 33 * 34 * @return the light level as an int 35 */ 36 public int getValue() 37 { 38 // ask the SimWorld for it's brightness at this point, and return it 39 SimWorld world=robot.getWorld(); 40 return world.getBrightness(this.getXCoord(),this.getYCoord(),this.getZCoord()); 41 } 42 43 /** 44 * Returns the offset from the owning SimRCX's x coordinate 45 * 46 * @return the x offset 47 */ 48 public double getXOffset() 49 { 50 return xOffset; 51 } 52 53 /** 54 * Returns the offset from the owning SimRCX's y coordinate 55 * 56 * @return the y offset 57 */ 58 public double getZOffset() 59 { 60 return zOffset; 61 } 62 } 63
SimLightSensor |