selection box now tied to world not screen
parent
9f59efc3d7
commit
b7991cdb74
|
|
@ -1,6 +1,7 @@
|
||||||
package xyz.valnet.engine.graphics;
|
package xyz.valnet.engine.graphics;
|
||||||
|
|
||||||
import xyz.valnet.engine.math.Vector4f;
|
import xyz.valnet.engine.math.Vector4f;
|
||||||
|
import xyz.valnet.engine.math.Vector4i;
|
||||||
|
|
||||||
public class Tile9 {
|
public class Tile9 {
|
||||||
|
|
||||||
|
|
@ -37,7 +38,11 @@ public class Tile9 {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Vector4f box) {
|
public void draw(Vector4f box) {
|
||||||
draw((int)box.x, (int)box.y, (int)box.z, (int)box.w);
|
draw(box.asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Vector4i box) {
|
||||||
|
draw(box.x, box.y, box.z, box.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(int x, int y, int w, int h) {
|
public void draw(int x, int y, int w, int h) {
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,23 @@ public class Vector4i implements Serializable {
|
||||||
|
|
||||||
return vecs;
|
return vecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Vector4i toAABB() {
|
||||||
|
return new Vector4i(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
x + z,
|
||||||
|
y + w
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector4i toXYWH() {
|
||||||
|
return new Vector4i(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z - x,
|
||||||
|
w - y
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,11 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
||||||
return new Vector2f((x - screenWidth / 2 + focus.x * tileWidth) / tileWidth, (y - screenHeight / 2 + focus.y * tileWidth) / tileWidth);
|
return new Vector2f((x - screenWidth / 2 + focus.x * tileWidth) / tileWidth, (y - screenHeight / 2 + focus.y * tileWidth) / tileWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector4f world2Screen(Vector4f input) {
|
public Vector2f screen2world(Vector2f pos) {
|
||||||
|
return screen2world(pos.x, pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector4f world2screen(Vector4f input) {
|
||||||
return new Vector4f(
|
return new Vector4f(
|
||||||
input.x * tileWidth + screenWidth / 2 - focus.x * tileWidth,
|
input.x * tileWidth + screenWidth / 2 - focus.x * tileWidth,
|
||||||
input.y * tileWidth + screenHeight / 2 - focus.y * tileWidth,
|
input.y * tileWidth + screenHeight / 2 - focus.y * tileWidth,
|
||||||
|
|
@ -120,7 +124,7 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
||||||
|
|
||||||
public void drawProgressBar(float progress, Vector4f worldBox) {
|
public void drawProgressBar(float progress, Vector4f worldBox) {
|
||||||
int h = 6;
|
int h = 6;
|
||||||
Vector4i box = world2Screen(worldBox).toXYWH().asInt();
|
Vector4i box = world2screen(worldBox).toXYWH().asInt();
|
||||||
Drawing.setLayer(Layers.GENERAL_UI);
|
Drawing.setLayer(Layers.GENERAL_UI);
|
||||||
Assets.flat.pushColor(new Vector4f(0, 0, 0, 1));
|
Assets.flat.pushColor(new Vector4f(0, 0, 0, 1));
|
||||||
Assets.uiFrame.draw(box.x - h, box.y + box.w / 2 - h / 2, box.z + h * 2, h);
|
Assets.uiFrame.draw(box.x - h, box.y + box.w / 2 - h / 2, box.z + h * 2, h);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import xyz.valnet.engine.graphics.Drawing;
|
||||||
import xyz.valnet.engine.math.Vector2f;
|
import xyz.valnet.engine.math.Vector2f;
|
||||||
import xyz.valnet.engine.math.Vector2i;
|
import xyz.valnet.engine.math.Vector2i;
|
||||||
import xyz.valnet.engine.math.Vector4f;
|
import xyz.valnet.engine.math.Vector4f;
|
||||||
|
import xyz.valnet.engine.math.Vector4i;
|
||||||
import xyz.valnet.engine.scenegraph.GameObject;
|
import xyz.valnet.engine.scenegraph.GameObject;
|
||||||
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
|
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
|
||||||
import xyz.valnet.engine.scenegraph.ITransient;
|
import xyz.valnet.engine.scenegraph.ITransient;
|
||||||
|
|
@ -91,7 +92,13 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
||||||
}
|
}
|
||||||
|
|
||||||
if(initialCoords != null) {
|
if(initialCoords != null) {
|
||||||
Assets.selectionFrame.draw((int) initialCoords.x, (int) initialCoords.y, (int) (App.mouseX - initialCoords.x), (int) (App.mouseY - initialCoords.y));
|
Vector2i screenPos = camera.world2screen(initialCoords);
|
||||||
|
Assets.selectionFrame.draw(new Vector4i(
|
||||||
|
screenPos.x,
|
||||||
|
screenPos.y,
|
||||||
|
App.mouseX,
|
||||||
|
App.mouseY
|
||||||
|
).toXYWH());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,8 +118,8 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
||||||
List<ISelectable> newSelection = new ArrayList<ISelectable>();
|
List<ISelectable> newSelection = new ArrayList<ISelectable>();
|
||||||
|
|
||||||
Vector4f normalizedSelectionBoxScreen = sortVector(a);
|
Vector4f normalizedSelectionBoxScreen = sortVector(a);
|
||||||
Vector2f selectionBoxWorldMin = camera.screen2world(normalizedSelectionBoxScreen.x, normalizedSelectionBoxScreen.y);
|
Vector2f selectionBoxWorldMin = new Vector2f(normalizedSelectionBoxScreen.x, normalizedSelectionBoxScreen.y);
|
||||||
Vector2f selectionBoxWorldMax = camera.screen2world(normalizedSelectionBoxScreen.z, normalizedSelectionBoxScreen.w);
|
Vector2f selectionBoxWorldMax = new Vector2f(normalizedSelectionBoxScreen.z, normalizedSelectionBoxScreen.w);
|
||||||
|
|
||||||
List<ISelectable> selectables = getAll(ISelectable.class);
|
List<ISelectable> selectables = getAll(ISelectable.class);
|
||||||
|
|
||||||
|
|
@ -197,7 +204,7 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
||||||
|
|
||||||
if(button == 0) {
|
if(button == 0) {
|
||||||
if(initialCoords == null) {
|
if(initialCoords == null) {
|
||||||
initialCoords = new Vector2f(App.mouseX, App.mouseY);
|
initialCoords = camera.screen2world(new Vector2f(App.mouseX, App.mouseY));
|
||||||
}
|
}
|
||||||
} else if (button == 1) {
|
} else if (button == 1) {
|
||||||
if(selected.size() == 0) {
|
if(selected.size() == 0) {
|
||||||
|
|
@ -218,12 +225,16 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
||||||
public void mouseUp(int button) {
|
public void mouseUp(int button) {
|
||||||
if(initialCoords != null && button == 0) {
|
if(initialCoords != null && button == 0) {
|
||||||
|
|
||||||
makeSelection(new Vector4f(
|
Vector2f worldMouse = camera.screen2world(App.mouseX, App.mouseY);
|
||||||
|
|
||||||
|
Vector4f worldBox = new Vector4f(
|
||||||
initialCoords.x,
|
initialCoords.x,
|
||||||
initialCoords.y,
|
initialCoords.y,
|
||||||
App.mouseX,
|
worldMouse.x,
|
||||||
App.mouseY
|
worldMouse.y
|
||||||
));
|
);
|
||||||
|
|
||||||
|
makeSelection(worldBox);
|
||||||
|
|
||||||
initialCoords = null;
|
initialCoords = null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ public abstract class Agent extends WorldObject implements ISelectable {
|
||||||
}
|
}
|
||||||
|
|
||||||
Assets.selectionFrame.draw(
|
Assets.selectionFrame.draw(
|
||||||
camera.world2Screen(
|
camera.world2screen(
|
||||||
terrain.getTile(
|
terrain.getTile(
|
||||||
path.getDestination().getPosition()
|
path.getDestination().getPosition()
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue