Introduce pushToScene() and removeFromScene() Entity's methods
This commit is contained in:
@@ -3,9 +3,11 @@ package com.bartlomiejpluta.base.core.world.animation;
|
||||
import com.bartlomiejpluta.base.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.core.world.object.RenderableObject;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class AnimationableObject extends RenderableObject {
|
||||
protected final Vector2i spriteSheetDimension;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.bartlomiejpluta.base.core.world.camera;
|
||||
|
||||
import com.bartlomiejpluta.base.core.ui.Window;
|
||||
import com.bartlomiejpluta.base.core.world.object.Object;
|
||||
import com.bartlomiejpluta.base.core.world.object.PositionableObject;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
public class Camera extends Object {
|
||||
public class Camera extends PositionableObject {
|
||||
private final Matrix4f projectionMatrix = new Matrix4f();
|
||||
private final Matrix4f viewMatrix = new Matrix4f();
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ import com.bartlomiejpluta.base.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.core.logic.Updatable;
|
||||
import com.bartlomiejpluta.base.core.world.animation.AnimationableObject;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class MovableObject extends AnimationableObject implements Updatable {
|
||||
private final Vector2f coordinateStepSize;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bartlomiejpluta.base.core.world.object;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.joml.Matrix4f;
|
||||
@@ -7,7 +8,8 @@ import org.joml.Vector2f;
|
||||
|
||||
import static java.lang.Math.toRadians;
|
||||
|
||||
public abstract class Object {
|
||||
@EqualsAndHashCode
|
||||
public abstract class PositionableObject {
|
||||
private final Matrix4f modelMatrix = new Matrix4f();
|
||||
|
||||
@Getter
|
||||
@@ -21,31 +23,31 @@ public abstract class Object {
|
||||
@Setter
|
||||
protected float scale = 1.0f;
|
||||
|
||||
public Object setPosition(float x, float y) {
|
||||
public PositionableObject setPosition(float x, float y) {
|
||||
position.x = x;
|
||||
position.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object setPosition(Vector2f position) {
|
||||
public PositionableObject setPosition(Vector2f position) {
|
||||
this.position.x = position.x;
|
||||
this.position.y = position.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object movePosition(float x, float y) {
|
||||
public PositionableObject movePosition(float x, float y) {
|
||||
position.x += x;
|
||||
position.y += y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object movePosition(Vector2f position) {
|
||||
public PositionableObject movePosition(Vector2f position) {
|
||||
this.position.x += position.x;
|
||||
this.position.y += position.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object moveRotation(float rotation) {
|
||||
public PositionableObject moveRotation(float rotation) {
|
||||
this.rotation += rotation;
|
||||
return this;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.bartlomiejpluta.base.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.core.gl.render.Renderable;
|
||||
import com.bartlomiejpluta.base.core.gl.shader.manager.ShaderManager;
|
||||
import com.bartlomiejpluta.base.core.ui.Window;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -12,7 +13,8 @@ import org.joml.Vector2f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class RenderableObject extends Object implements Renderable {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class RenderableObject extends PositionableObject implements Renderable {
|
||||
private final Mesh mesh;
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.bartlomiejpluta.base.core.world.camera.Camera;
|
||||
import com.bartlomiejpluta.base.core.world.map.GameMap;
|
||||
import com.bartlomiejpluta.base.core.world.object.RenderableObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -22,6 +23,7 @@ public class Scene implements Renderable {
|
||||
private final List<AnimationableObject> objects = new ArrayList<>();
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private GameMap map;
|
||||
|
||||
public Scene addObject(AnimationableObject object) {
|
||||
@@ -29,6 +31,11 @@ public class Scene implements Renderable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Scene removeObject(AnimationableObject object) {
|
||||
objects.remove(object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Window window, ShaderManager shaderManager) {
|
||||
shaderManager.setUniform(UniformName.UNI_PROJECTION_MATRIX, camera.getProjectionMatrix(window));
|
||||
|
||||
Reference in New Issue
Block a user