Rogue: Savage Rats, a retro-themed dungeon crawler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rogue-savage-rats/src/mightypork/gamecore/render/textures/TxQuad.java

113 lines
2.2 KiB

package mightypork.gamecore.render.textures;
import mightypork.util.constraints.rect.Rect;
import mightypork.util.constraints.rect.RectConst;
/**
* Texture Quad (describing a part of a texture)
*
* @author MightyPork
*/
public class TxQuad {
/** The texture */
public final GLTexture tx;
/** Coords in texture (0-1) */
public final RectConst uvs;
/**
* TxQuad from origin and size in pixels
*
* @param tx texture
* @param xPx left top X (0-1)
* @param yPx left top Y (0-1)
* @param widthPx area width (0-1)
* @param heightPx area height (0-1)
* @return new TxQuad
*/
public static TxQuad fromSizePx(GLTexture tx, double xPx, double yPx, double widthPx, double heightPx)
{
final double w = tx.getImageWidth();
final double h = tx.getImageHeight();
return fromSize(tx, xPx / w, yPx / h, widthPx / w, heightPx / h);
}
/**
* TxQuad from origin and size 0-1
*
* @param tx texture
* @param x1 left top X (0-1)
* @param y1 left top Y (0-1)
* @param width area width (0-1)
* @param height area height (0-1)
* @return new TxQuad
*/
public static TxQuad fromSize(GLTexture tx, double x1, double y1, double width, double height)
{
return new TxQuad(tx, x1, y1, x1 + width, y1 + height);
}
/**
* Make of coords
*
* @param tx texture
* @param x1 left top X (0-1)
* @param y1 left top Y (0-1)
* @param x2 right bottom X (0-1)
* @param y2 right bottom Y (0-1)
*/
public TxQuad(GLTexture tx, double x1, double y1, double x2, double y2) {
this(tx, Rect.make(x1, y1, x2, y2));
}
/**
* @param tx Texture
* @param uvs Rect of texture UVs (0-1); will be frozen.
*/
public TxQuad(GLTexture tx, Rect uvs) {
this.tx = tx;
this.uvs = uvs.freeze();
}
/**
* Clone another
*
* @param txQuad a copied quad
*/
public TxQuad(TxQuad txQuad) {
this.tx = txQuad.tx;
this.uvs = txQuad.uvs;
}
/**
* Get copy
*
* @return copy of this
*/
public TxQuad copy()
{
return new TxQuad(this);
}
/**
* Make a sheet starting with this quad, spannign to right and down.
*
* @param width sheet width
* @param height sheet height
* @return sheet
*/
public TxSheet makeSheet(int width, int height)
{
return new TxSheet(this, width, height);
}
}