package gameEngine.entites.gameComponents; import gameEngine.entites.Entity; import gameEngine.entites.GameObject; import gameEngine.geometry.Transform; import gameEngine.scenes.GameScene; import gameEngine.views.Color; import gameEngine.views.Sprite; import gameEngine.views.Window; import org.joml.Vector3f; public class Mesh extends GameComponent { private GameObject parent; public enum MeshType { SPRITE, CUBE } private final MeshType type; private Sprite sprite; public Mesh(GameObject parent, MeshType type, String texturePath) { this.parent = parent; this.type = type; if (type == MeshType.SPRITE) { this.sprite = new Sprite(texturePath); sprite.updateSpriteDimensions(); } } public Mesh(Mesh original, GameObject newParent) { this.type = original.type; this.sprite = original.sprite; this.parent = newParent; sprite.updateSpriteDimensions(); } @Override public GameComponent copy() { return this; } @Override public void init() { if (type == MeshType.SPRITE) { sprite.update(); sprite.updateSpriteDimensions(); } } @Override public void update() { if (type == MeshType.SPRITE) { Transform transform = parent.transform; Transform screenTransform = parent.screenTransform; Vector3f actualPosition = new Vector3f(screenTransform.position); sprite.setPosition(actualPosition); sprite.setRotation(transform.rotation); sprite.setScale(transform.scale); sprite.update(); } } public void setSprite(String texturePath){ sprite.setTexturePath(texturePath); } public void setColor(Color color){ sprite.setColor(color); sprite.update(); } public float getDisplayedWidth() { return sprite != null ? sprite.getDisplayedWidth() : 0; } public float getDisplayedHeight() { return sprite != null ? sprite.getDisplayedHeight() : 0; } }