if (image.getWidth() > location.getWidth() || image.getHeight() > location.getHeight()) { return null; // does not fit if (image.getWidth() == location.getWidth() && image.getHeight() == location.getHeight()) { occupied = true; // perfect fit return this; int dw = location.getWidth() - image.getWidth(); int dh = location.getHeight() - image.getHeight(); child[1] = new Node(location.getX() + image.getWidth(), location.getY(), location.getWidth() - image.getWidth(), location.getHeight()); } else { child[0] = new Node(location.getX(), location.getY(), location.getWidth(), image.getHeight()); child[1] = new Node(location.getX(), location.getY() + image.getHeight(), location.getWidth(), location.getHeight() - image.getHeight());
/** * Get the transformed texture coordinate for a given input location. * @param previousLocation The old texture coordinate. * @return The new texture coordinate inside the atlas. */ public Vector2f getLocation(Vector2f previousLocation) { float x = (float) getX() / (float) atlasWidth; float y = (float) getY() / (float) atlasHeight; float w = (float) getWidth() / (float) atlasWidth; float h = (float) getHeight() / (float) atlasHeight; Vector2f location = new Vector2f(x, y); float prevX = previousLocation.x; float prevY = previousLocation.y; location.addLocal(prevX * w, prevY * h); return location; }
if (image.getWidth() > location.getWidth() || image.getHeight() > location.getHeight()) { return null; // does not fit if (image.getWidth() == location.getWidth() && image.getHeight() == location.getHeight()) { occupied = true; // perfect fit return this; int dw = location.getWidth() - image.getWidth(); int dh = location.getHeight() - image.getHeight(); child[1] = new Node(location.getX() + image.getWidth(), location.getY(), location.getWidth() - image.getWidth(), location.getHeight()); } else { child[0] = new Node(location.getX(), location.getY(), location.getWidth(), image.getHeight()); child[1] = new Node(location.getX(), location.getY() + image.getHeight(), location.getWidth(), location.getHeight() - image.getHeight());
/** * Get the transformed texture coordinate for a given input location. * @param previousLocation The old texture coordinate. * @return The new texture coordinate inside the atlas. */ public Vector2f getLocation(Vector2f previousLocation) { float x = (float) getX() / (float) atlasWidth; float y = (float) getY() / (float) atlasHeight; float w = (float) getWidth() / (float) atlasWidth; float h = (float) getHeight() / (float) atlasHeight; Vector2f location = new Vector2f(x, y); float prevX = previousLocation.x; float prevY = previousLocation.y; location.addLocal(prevX * w, prevY * h); return location; }