Package net.lenkaspace.creeper.vo

Examples of net.lenkaspace.creeper.vo.CRVector3d


 
  /**
   * Get normalised steering force vector
   */
  public CRVector3d getOrientationVector() {
    CRVector3d v = new CRVector3d(getRotationAsVectorComponent(), thrustForce,0);
    v.normalize();
    return v;
  }
View Full Code Here


 
  /**
   * Get vector that points in front of the situated model
   */
  public CRVector3d getLookAtVector() {
    CRVector3d v = this.getOrientationVector();
    v.multiplyBy(5);
    return v;
  }
View Full Code Here

   * @param size_ CRVector3d size [width, height, depth]
   * @param controller_ CRController holding controller instance
   */
  public CRBinWorld(CRVector3d binSize_, int id_, CRVector3d size_, CRController controller_) {
    super(id_, size_, controller_);
    binSize = new CRVector3d(binSize_);
    numberOfBins = ((int)Math.ceil(size.x / binSize.x) * (int)Math.ceil(size.y / binSize.y));
    situatedModelBins = new ArrayList[numberOfBins];
    //System.out.println("Created " + numberOfBins + " bins");
    for (int i=0; i<numberOfBins; i++) {
      situatedModelBins[i] = new ArrayList<CRBaseSituatedModel>();
View Full Code Here

   */
  public void addSituatedModel(CRBaseSituatedModel situatedModel_) {
    super.addSituatedModel(situatedModel_);
   
    //-- check if position is valid
    CRVector3d position = situatedModel_.getPosition();
   
    if (position.x > size.x ) { position.x = 0}
    else if (position.x < 0 ) { position.x = size.x; }
    if (position.y > size.y ) { position.y = 0}
    else if (position.y < 0 ) { position.y = size.y; }
View Full Code Here

   * Get index of a bin based on a position
   * @param position_ CRVector3d position
   * @return int index of a bin
   */
  public int getBinIndexForPosition(CRVector3d position_) {
    CRVector3d binCoordinates = getBinCoordinatesForPosition(position_);
    return getBinIndexForBinCoordinates(binCoordinates);
  }
View Full Code Here

   * @return CRVector3d in format [column, row, 0]
   */
  private CRVector3d getBinCoordinatesForPosition(CRVector3d position_) {
    int numRows = (int)Math.ceil(size.y / binSize.y);
    int numCols = (int)Math.ceil(size.x / binSize.x);
    CRVector3d normalisedPosition = new CRVector3d(position_);
    if (normalisedPosition.x >= size.x) { normalisedPosition.x = size.x - 1; }
    else if (normalisedPosition.x <= 0) { normalisedPosition.x = 1; }
    if (normalisedPosition.y >= size.y) { normalisedPosition.y = size.y - 1; }
    else if (normalisedPosition.y <= 0) { normalisedPosition.y = 1; }
    int row = Math.min(numRows, Math.max(0, (int)(Math.floor(normalisedPosition.y / binSize.y))));
    int col = Math.min(numCols, Math.max(0, (int)(Math.floor(normalisedPosition.x / binSize.x))));
    return new CRVector3d(col, row, 0);
  }
View Full Code Here

    int binIndex = getBinIndexForPosition(position_);
    ArrayList<CRBaseSituatedModel> returnArrayList = new ArrayList<CRBaseSituatedModel>();
    returnArrayList.addAll(situatedModelBins[binIndex]);
   
    //-- test if other bin indexes are applicable
    CRVector3d binCoordinates = getBinCoordinatesForPosition(position_);
   
    boolean addedNorth = false;
    boolean addedSouth = false;
    boolean addedWest = false;
    boolean addedEast = false;
   
    int northBinY = (int)(binCoordinates.y - 1);
    int southBinY = (int)(binCoordinates.y + 1);
    int westBinX = (int)(binCoordinates.x - 1);
    int eastBinX = (int)(binCoordinates.x + 1);
   
    int numRows = (int)Math.ceil(size.y / binSize.y);
    int numCols = (int)Math.ceil(size.x / binSize.x);
   
    if (position_.y - radius_ <= binCoordinates.y*binSize.y) { // test if reaching to the bin north of here
       addedNorth = true;
      //-- wrap the coordinate around
      if (northBinY < 0 ) {
        northBinY = numRows-1;
      }
      //-- add the bin to the list
      returnArrayList.addAll(situatedModelBins[getBinIndexForBinCoordinates(new CRVector3d(binCoordinates.x, northBinY, 0))]);
    }
    if (position_.y + radius_ >= southBinY*binSize.y || position_.y + radius_ >= size.y) { //test bin south of here if north not added
      addedSouth = true;
      //-- wrap the coordinate around
      if (southBinY >= numRows) {
        southBinY = 0;
      }
      //-- add the bin to the list
      returnArrayList.addAll(situatedModelBins[getBinIndexForBinCoordinates(new CRVector3d(binCoordinates.x, southBinY, 0))]);
    }
   
   
    if (position_.x - radius_ <= binCoordinates.x*binSize.x) { // test bin west of here
      addedWest = true;
      //-- wrap the coordinate around
      if (westBinX < 0 ) {
        westBinX = numCols-1;
      }
      //-- add the bin to the list
      returnArrayList.addAll(situatedModelBins[getBinIndexForBinCoordinates(new CRVector3d(westBinX, binCoordinates.y, 0))]);
    }
    if (position_.x + radius_ >= eastBinX*binSize.x || position_.x + radius_ >= size.x) { // test bin east of here
      addedEast = true;
      //-- wrap the coordinate around
      if (eastBinX >= numCols) {
        eastBinX = 0;
      }
      //-- add the bin to the list
      returnArrayList.addAll(situatedModelBins[getBinIndexForBinCoordinates(new CRVector3d(eastBinX, binCoordinates.y, 0))]);
    }
   
   
    //-- if added north and west, north west should also be added, etc.
    if (addedNorth && addedWest) {
      returnArrayList.addAll(situatedModelBins[getBinIndexForBinCoordinates(new CRVector3d(westBinX, northBinY, 0))]);
    }
    if (addedNorth && addedEast) {
      returnArrayList.addAll(situatedModelBins[getBinIndexForBinCoordinates(new CRVector3d(eastBinX, northBinY, 0))]);
    }
    if (addedSouth && addedWest) {
      returnArrayList.addAll(situatedModelBins[getBinIndexForBinCoordinates(new CRVector3d(westBinX, southBinY, 0))]);
    }
    if (addedSouth && addedEast) {
      returnArrayList.addAll(situatedModelBins[getBinIndexForBinCoordinates(new CRVector3d(eastBinX, southBinY, 0))]);
    }
   
    return returnArrayList;
  }
View Full Code Here

   
    public CRRenderer(CRController controller_) {
      this.setPreferredSize(new Dimension(700,650));
      controller = controller_;
      crImageProvider = new CRImageProvider();
      viewPosition = new CRVector3d();
      this.setFocusable(true);
    }
View Full Code Here

            imageFileName == CR_BLANK_CIRCLE || imageFileName == CR_BLUE_CIRCLE || imageFileName == CR_GRAY_CIRCLE || imageFileName == CR_GREEN_CIRCLE || imageFileName == CR_PURPLE_CIRCLE || imageFileName == CR_RED_CIRCLE) {
              image = crImageProvider.getImage(imageFileName);
            } else {
              image = imageProvider.getImage(imageFileName);
            }
            CRVector3d positionOnScreen = new CRVector3d(situatedModel.getPosition());
            positionOnScreen.x -= viewPosition.x;
            positionOnScreen.y -= viewPosition.y;
            if (image != null) {
              drawImageAt(image, positionOnScreen, situatedModel.getSize(), Math.toRadians(situatedModel.getRotation()), situatedModel.getAlpha(), g);
            }
View Full Code Here

*
*/
public class Agent extends CRBaseDynamicModel {

  public Agent(int id_, CRVector3d position_, double rotation_) {
    super(id_, position_, new CRVector3d(60,60,0), rotation_, SHAPE.CIRCLE, "agent.png");
  }
View Full Code Here

TOP

Related Classes of net.lenkaspace.creeper.vo.CRVector3d

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.