/** * Transforms a whole texture coordinates buffer. * @param inBuf The input texture buffer. * @param offset The offset in the output buffer * @param outBuf The output buffer. */ public void transformTextureCoords(FloatBuffer inBuf, int offset, FloatBuffer outBuf) { Vector2f tex = new Vector2f(); // offset is given in element units // convert to be in component units offset *= 2; for (int i = 0; i < inBuf.limit() / 2; i++) { tex.x = inBuf.get(i * 2 + 0); tex.y = inBuf.get(i * 2 + 1); Vector2f location = getLocation(tex); //TODO: add proper texture wrapping for atlases.. outBuf.put(offset + i * 2 + 0, location.x); outBuf.put(offset + i * 2 + 1, location.y); } }
FloatBuffer inPos = (FloatBuffer) inBuf.getData(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); tile.transformTextureCoords(inPos, offset, outPos); return true; } else {
FloatBuffer inPos = (FloatBuffer) inBuf.getData(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); tile.transformTextureCoords(inPos, offset, outPos); return true; } else {
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[0] = new Node(location.getX(), location.getY(), image.getWidth(), location.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());
/** * Transforms a whole texture coordinates buffer. * @param inBuf The input texture buffer. * @param offset The offset in the output buffer * @param outBuf The output buffer. */ public void transformTextureCoords(FloatBuffer inBuf, int offset, FloatBuffer outBuf) { Vector2f tex = new Vector2f(); // offset is given in element units // convert to be in component units offset *= 2; for (int i = 0; i < inBuf.limit() / 2; i++) { tex.x = inBuf.get(i * 2 + 0); tex.y = inBuf.get(i * 2 + 1); Vector2f location = getLocation(tex); //TODO: add proper texture wrapping for atlases.. outBuf.put(offset + i * 2 + 0, location.x); outBuf.put(offset + i * 2 + 1, location.y); } }
/** * 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; }
public Node(int x, int y, int width, int height) { location = new TextureAtlasTile(x, y, width, height); child = new Node[2]; child[0] = null; child[1] = null; occupied = false; }
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[0] = new Node(location.getX(), location.getY(), image.getWidth(), location.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; }
public Node(int x, int y, int width, int height) { location = new TextureAtlasTile(x, y, width, height); child = new Node[2]; child[0] = null; child[1] = null; occupied = false; }