use of com.badlogic.gdx.math.Polygon in project bladecoder-adventure-engine by bladecoder.
the class ScnWidgetInputListener method keyDown.
@Override
public boolean keyDown(InputEvent event, int keycode) {
super.keyDown(event, keycode);
Polygon p = null;
if (scnWidget.getStage() == null || scnWidget.getStage().getKeyboardFocus() != scnWidget)
return false;
switch(keycode) {
case Keys.ENTER:
break;
case Keys.BACKSPACE:
break;
case Keys.Z:
if (UIUtils.ctrl()) {
Ctx.project.getUndoStack().undo();
}
break;
case Keys.FORWARD_DEL:
BaseActor a = Ctx.project.getSelectedActor();
if (a == null)
return false;
Ctx.project.getUndoStack().add(new UndoDeleteActor(Ctx.project.getSelectedScene(), a));
Ctx.project.getSelectedScene().removeActor(a);
Ctx.project.setModified(this, Project.NOTIFY_ELEMENT_DELETED, null, a);
break;
case Keys.S:
if (UIUtils.ctrl()) {
try {
Ctx.project.saveProject();
} catch (IOException e1) {
String msg = "Something went wrong while saving the actor.\n\n" + e1.getClass().getSimpleName() + " - " + e1.getMessage();
Message.showMsgDialog(scnWidget.getStage(), "Error", msg);
EditorLogger.printStackTrace(e1);
}
}
break;
case Keys.UP:
case Keys.DOWN:
case Keys.LEFT:
case Keys.RIGHT:
selActor = scnWidget.getSelectedActor();
p = selActor.getBBox();
undoOrg.set(p.getX(), p.getY());
Ctx.project.setModified(this, Project.POSITION_PROPERTY, null, selActor);
break;
case Keys.PLUS:
case 70:
scnWidget.zoom(-1);
break;
case Keys.MINUS:
scnWidget.zoom(1);
break;
}
return false;
}
use of com.badlogic.gdx.math.Polygon in project bladecoder-adventure-engine by bladecoder.
the class ScnWidgetInputListener method clicked.
@Override
public void clicked(InputEvent event, float x, float y) {
Scene scn = scnWidget.getScene();
if (scn == null)
return;
Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY());
scnWidget.screenToWorldCoords(p);
// DOUBLE CLICK TO CREATE OR DELETE POINTS
if (getTapCount() == 2) {
// Check WALKZONE
if (scn.getPolygonalNavGraph() != null && scnWidget.getShowWalkZone()) {
Polygon poly = scn.getPolygonalNavGraph().getWalkZone();
if (UIUtils.ctrl()) {
// Delete the point if selected
boolean deleted = PolygonUtils.deletePoint(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
if (deleted) {
Ctx.project.setModified();
return;
}
} else {
boolean created = PolygonUtils.addClampPointIfTolerance(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
if (created) {
Ctx.project.setModified();
return;
}
}
}
if (scnWidget.getSelectedActor() != null) {
Polygon poly = scnWidget.getSelectedActor().getBBox();
if ((!(scnWidget.getSelectedActor() instanceof SpriteActor) || !((SpriteActor) scnWidget.getSelectedActor()).isBboxFromRenderer()) && !(scnWidget.getSelectedActor() instanceof AnchorActor)) {
if (UIUtils.ctrl()) {
// Delete the point if selected
boolean deleted = PolygonUtils.deletePoint(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
if (deleted) {
Ctx.project.setModified();
return;
}
} else {
boolean created = PolygonUtils.addClampPointIfTolerance(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
if (created) {
Ctx.project.setModified();
return;
}
}
}
}
}
}
use of com.badlogic.gdx.math.Polygon in project bladecoder-adventure-engine by bladecoder.
the class ScnWidgetInputListener method touchDragged.
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
// EditorLogger.debug("Touch Dragged - X: " + Gdx.input.getX() + " Y: "
// + Gdx.input.getY());
super.touchDragged(event, x, y, pointer);
if (Gdx.input.isButtonPressed(Buttons.LEFT)) {
Scene scn = scnWidget.getScene();
if (scn == null)
return;
Vector2 d = new Vector2(Gdx.input.getX(), Gdx.input.getY());
scnWidget.screenToWorldCoords(d);
d.sub(org);
org.add(d);
if (draggingMode == DraggingModes.DRAGGING_ACTOR) {
selActor.setPosition(selActor.getX() + d.x, selActor.getY() + d.y);
Ctx.project.setModified(this, Project.POSITION_PROPERTY, null, selActor);
} else if (draggingMode == DraggingModes.DRAGGING_REFPOINT) {
Vector2 refPoint = ((InteractiveActor) selActor).getRefPoint();
refPoint.add(d.x, d.y);
Ctx.project.setModified();
} else if (draggingMode == DraggingModes.DRAGGING_BBOX_POINT) {
Polygon poly = selActor.getBBox();
float[] verts = poly.getVertices();
verts[vertIndex] += d.x;
verts[vertIndex + 1] += d.y;
poly.dirty();
Ctx.project.setModified();
} else if (draggingMode == DraggingModes.DRAGGING_WALKZONE_POINT) {
Polygon poly = scn.getPolygonalNavGraph().getWalkZone();
float[] verts = poly.getVertices();
verts[vertIndex] += d.x;
verts[vertIndex + 1] += d.y;
poly.dirty();
Ctx.project.setModified();
} else if (draggingMode == DraggingModes.DRAGGING_WALKZONE) {
Polygon poly = scn.getPolygonalNavGraph().getWalkZone();
poly.translate(d.x, d.y);
Ctx.project.setModified();
} else if (draggingMode == DraggingModes.DRAGGING_MARKER_0) {
Vector2 depthVector = scnWidget.getScene().getDepthVector();
depthVector.x += d.y;
Ctx.project.setModified();
updateFakeDepth();
} else if (draggingMode == DraggingModes.DRAGGING_MARKER_100) {
Vector2 depthVector = scnWidget.getScene().getDepthVector();
depthVector.y += d.y;
Ctx.project.setModified();
updateFakeDepth();
}
} else if (Gdx.input.isButtonPressed(Buttons.RIGHT) || Gdx.input.isButtonPressed(Buttons.MIDDLE)) {
Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY());
scnWidget.screenToWorldCoords(p);
p.sub(org);
scnWidget.translate(p);
}
}
use of com.badlogic.gdx.math.Polygon in project bladecoder-adventure-engine by bladecoder.
the class PolygonalNavGraph method createInitialGraph.
public void createInitialGraph(Collection<BaseActor> actors) {
graphNodes.clear();
// 1.- Add WalkZone convex nodes
float[] verts = walkZone.getTransformedVertices();
for (int i = 0; i < verts.length; i += 2) {
if (!PolygonUtils.isVertexConcave(walkZone, i)) {
graphNodes.add(new NavNodePolygonal(verts[i], verts[i + 1]));
}
}
// 2.- Add obstacles concave nodes
obstacles.clear();
for (BaseActor a : actors) {
if (a instanceof ObstacleActor && a.isVisible())
obstacles.add(a.getBBox());
}
for (Polygon o : obstacles) {
verts = o.getTransformedVertices();
for (int i = 0; i < verts.length; i += 2) {
if (PolygonUtils.isVertexConcave(o, i) && PolygonUtils.isPointInside(walkZone, verts[i], verts[i + 1], false)) {
graphNodes.add(new NavNodePolygonal(verts[i], verts[i + 1]));
}
}
}
// 3.- CALC LINE OF SIGHTs
for (int i = 0; i < graphNodes.size() - 1; i++) {
NavNodePolygonal n1 = graphNodes.get(i);
for (int j = i + 1; j < graphNodes.size(); j++) {
NavNodePolygonal n2 = graphNodes.get(j);
if (inLineOfSight(n1.x, n1.y, n2.x, n2.y)) {
n1.neighbors.add(n2);
n2.neighbors.add(n1);
}
}
}
}
use of com.badlogic.gdx.math.Polygon in project bladecoder-adventure-engine by bladecoder.
the class Scene method drawBBoxLines.
public void drawBBoxLines(ShapeRenderer renderer) {
// renderer.begin(ShapeType.Rectangle);
renderer.begin(ShapeType.Line);
for (BaseActor a : actors.values()) {
Polygon p = a.getBBox();
if (p == null) {
EngineLogger.error("ERROR DRAWING BBOX FOR: " + a.getId());
}
if (a instanceof ObstacleActor) {
renderer.setColor(OBSTACLE_COLOR);
renderer.polygon(p.getTransformedVertices());
} else if (a instanceof AnchorActor) {
renderer.setColor(Scene.ANCHOR_COLOR);
renderer.line(p.getX() - Scene.ANCHOR_RADIUS, p.getY(), p.getX() + Scene.ANCHOR_RADIUS, p.getY());
renderer.line(p.getX(), p.getY() - Scene.ANCHOR_RADIUS, p.getX(), p.getY() + Scene.ANCHOR_RADIUS);
} else {
renderer.setColor(ACTOR_BBOX_COLOR);
renderer.polygon(p.getTransformedVertices());
}
// Rectangle r = a.getBBox().getBoundingRectangle();
// renderer.rect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
if (polygonalNavGraph != null) {
renderer.setColor(WALKZONE_COLOR);
renderer.polygon(polygonalNavGraph.getWalkZone().getTransformedVertices());
// DRAW LINEs OF SIGHT
renderer.setColor(Color.WHITE);
ArrayList<NavNodePolygonal> nodes = polygonalNavGraph.getGraphNodes();
for (NavNodePolygonal n : nodes) {
for (NavNodePolygonal n2 : n.neighbors) {
renderer.line(n.x, n.y, n2.x, n2.y);
}
}
}
renderer.end();
}
Aggregations