public IVector2 copy() { return new Vector2Double(x_, y_); }
/** * Returns the size of a pixel. * @retun size of a pixel */ public IVector2 getPixelSize() { Canvas canvas = canvas_; if (canvas == null) return Vector2Double.ZERO; return paddedSize_.copy().divide(new Vector2Double(canvas.getWidth(), canvas.getHeight())); }
/** * Creates a new TiledLayer. * * @param tileSize size of an individual tile * @param color the modulation color * @param texturePath resource path of the texture */ public TiledLayer(IVector2 tileSize, Object color, String texturePath) { super(Layer.LAYER_TYPE_TILED, color); this.tileSize_ = tileSize.copy(); //this.modColor_ = color==null? Color.WHITE: color; this.invTileSize_ = (new Vector2Double(1.0)).divide(tileSize_); this.texturePath_ = texturePath; //texture_ = 0; }
public ViewportCanvas() { backBuffer_ = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR_PRE); clearRectangle_ = new Rectangle.Double(); clearRectangle_.x = 0.0; clearRectangle_.y = 0.0; clearRectangle_.width = size_.getXAsDouble(); clearRectangle_.height = size_.getYAsDouble(); }
public void mousePressed(MouseEvent e) { if(e.getButton() == MouseEvent.BUTTON1) { IVector2 position = getWorldCoordinates(e.getX(), e.getY()); fireLeftMouseClickEvent(position); } else if(e.getButton() == MouseEvent.BUTTON3) { if (e.getClickCount() == 1) { lastDragPos = (new Vector2Double(e.getX(), e.getY())).multiply(getPixelSize()); } else { setAreaSize(areaSize_); } } }
/** * Converts pixel coordinates into world coordinates * * @param pixelX pixel x-coordinate * @param pixelY pixel y-coordinate * @return world coordinates */ public IVector2 getWorldCoordinates(int pixelX, int pixelY) { if(getInvertX()) { pixelX = canvas_.getWidth() - pixelX; } if(getInvertY()) { pixelY = canvas_.getHeight() - pixelY; } double xFac = (paddedSize_.getXAsDouble()) / canvas_.getWidth(); double yFac = (paddedSize_.getYAsDouble()) / canvas_.getHeight(); IVector2 position = new Vector2Double((xFac * pixelX) + position_.getXAsDouble(), (yFac * (canvas_.getHeight() - pixelY)) + position_.getYAsDouble()); return position; }
final Vector2Double direction = new Vector2Double((i == 1)||(i == 3)? 0.1:0.0, (i == 0)||(i== 2)? 0.1:0.0); if ((i & 2) != 0) direction.negate();
public Object createObject(Map args) throws Exception { IVector2 size = Vector2Double.getVector2((Double)getProperty(args, "width"), (Double)getProperty(args, "height")); return new GridLayer(size, getProperty(args, "color")); } }, new BeanAccessInfo(AccessInfo.THIS)))
public Object clone() throws CloneNotSupportedException { return copy(); }
/** * Handle the Height Value. Check if its set or not */ public Vector3f handleHeightValue(Object posObj) { Vector3f position = Vector3f.ZERO; if(posObj instanceof Vector2Double) { Vector2Double pos2d = (Vector2Double)posObj; Vector2f pos2df = new Vector2f(pos2d.getXAsFloat(), pos2d.getYAsFloat()); position = new Vector3f(pos2df.x, _app.getHeightAt(pos2df), pos2df.y); } else if(posObj instanceof Vector3Double) { Vector3Double pos3d = (Vector3Double)posObj; Vector3f pos3f = new Vector3f(pos3d.getXAsFloat(), pos3d.getYAsFloat(), pos3d.getZAsFloat()); position = pos3f; } return position; }
public boolean equals(Object obj) { if (obj instanceof IVector2) { return equals((IVector2) obj); } return false; }
public double getDirectionAsDouble(IVector2 vector) { double qa = Math.sqrt(x_*x_ + y_*y_); double qb = Math.sqrt(vector.getXAsDouble()*vector.getXAsDouble() + vector.getYAsDouble()*vector.getYAsDouble()); return Math.cos(getInnerProductAsDouble(vector)/(qa*qb)); }
/** * Sets the position of the viewport. */ public void setPosition(IVector2 pos) { position_ = pos; IVector2 pixSize = getPixelSize(); pixPosition_ = position_.copy().divide(pixSize); pixPosition_ = (new Vector2Double(new Vector2Int(pixPosition_))).multiply(pixSize); }
public Object createObject(Map args) throws Exception { IVector2 size = Vector2Double.getVector2((Double)getProperty(args, "width"), (Double)getProperty(args, "height")); return new TiledLayer(size, getProperty(args, "color"), (String)getProperty(args, "imagepath")); } }, new BeanAccessInfo(AccessInfo.THIS)))
private void setupTransform(Graphics2D g) { g.translate( backBuffer_.getWidth() * inversionFlag_.getXAsInteger(), backBuffer_.getHeight() * (inversionFlag_.getYAsInteger() ^ 1)); g.scale((backBuffer_.getWidth() / paddedSize_.getXAsDouble()) * -((inversionFlag_.getXAsInteger() << 1) - 1), (backBuffer_.getHeight() / paddedSize_.getYAsDouble()) * ((inversionFlag_.getYAsInteger() << 1) - 1)); g.translate(-pixPosition_.getXAsDouble(), -pixPosition_.getYAsDouble()); } }
public void actionPerformed(ActionEvent e) { IPerspective p = observerCenter_.getSelectedPerspective(); if (p instanceof Perspective2D) { Perspective2D pers = (Perspective2D) p; pers.shiftPosition(direction.copy()); } } });
/** * Gets the shift of all objects. */ public IVector2 getObjectShift() { return new Vector2Double(objShiftX_, objShiftY_); }
public void run() { areaSize_ = new Vector2Double(areaSize); setSize(areaSize.copy()); if (preserveAR_) { setPosition(paddedSize_.copy().subtract(areaSize_).multiply(0.5).negate()); } } });
public void mouseDragged(MouseEvent e) { if (lastDragPos != null) { IVector2 position = (new Vector2Double(e.getX(), e.getY())).multiply(getPixelSize()); IVector2 diff = position.copy().subtract(lastDragPos); if (getInvertX()) diff.negateX(); if (!getInvertY()) diff.negateY(); lastDragPos = position; setPosition(getPosition().copy().subtract(diff)); } }
if(position==null) position = Vector2Double.getVector2((Double)getProperty(args, "x"), (Double)getProperty(args, "y"));