use of com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent in project talos by rockbite.
the class SmartTransformGizmo method setNewPointValue.
private void setNewPointValue(int touchedPoint, float x, float y) {
setRectFromPoints(prevPoints);
prevRotation = getRotation(prevPoints);
TransformComponent transform = gameObject.getComponent(TransformComponent.class);
float aspect = transform.scale.x / transform.scale.y;
// tmp2 contains movement diff
tmp2.set(x, y).sub(points[touchedPoint]);
if (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
// fix aspect
if (tmp2.x > tmp2.y) {
tmp2.x = tmp2.y;
} else if (tmp2.x <= tmp2.y) {
tmp2.y = tmp2.x;
}
tmp2.x *= aspect;
}
// find midpoint
tmp3.set(points[RT]).sub(points[LB]).scl(0.5f).add(points[LB]);
for (int i = 0; i < 4; i++) {
points[i].sub(tmp3);
points[i].rotateDeg(-prevRotation);
}
tmp2.rotateDeg(-prevRotation);
// apply diff
points[touchedPoint].add(tmp2);
if (touchedPoint == LB) {
points[LT].x = points[LB].x;
points[RB].y = points[LB].y;
}
if (touchedPoint == LT) {
points[RT].y = points[LT].y;
points[LB].x = points[LT].x;
}
if (touchedPoint == RB) {
points[LB].y = points[RB].y;
points[RT].x = points[RB].x;
}
if (touchedPoint == RT) {
points[LT].y = points[RT].y;
points[RB].x = points[RT].x;
}
// rotate back
for (int i = 0; i < 4; i++) {
points[i].rotateDeg(prevRotation);
points[i].add(tmp3);
}
setRectFromPoints(nextPoints);
nextRotation = getRotation(nextPoints);
transformOldToNew();
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent in project talos by rockbite.
the class TransformGizmo method getWorldPos.
public Vector2 getWorldPos() {
TransformComponent transform = gameObject.getComponent(TransformComponent.class);
transform.localToWorld(gameObject, tmp.set(0, 0));
return tmp;
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent in project talos by rockbite.
the class TransformGizmo method draw.
@Override
public void draw(Batch batch, float parentAlpha) {
if (gameObject.hasComponent(TransformComponent.class)) {
TransformComponent transform = gameObject.getComponent(TransformComponent.class);
transform.localToWorld(gameObject, tmp.set(0, 0));
// drawing position point
if (selected) {
drawPoint(batch, TalosMain.Instance().getSkin().getRegion("ic-target"), tmp, Color.ORANGE, 30);
} else {
drawPoint(batch, TalosMain.Instance().getSkin().getRegion("ic-target"), tmp, Color.WHITE, 30);
}
}
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent in project talos by rockbite.
the class CameraPreview method act.
@Override
public void act(float delta) {
super.act(delta);
TransformComponent transform = cameraObject.getComponent(TransformComponent.class);
viewport.getCamera().position.set(transform.position.x, transform.position.y, 0);
((OrthographicCamera) viewport.getCamera()).zoom = component.zoom;
OrthographicCamera camera = (OrthographicCamera) viewport.getCamera();
float currRotation = getCameraAngle(camera);
if (currRotation == 360)
currRotation = 0;
if (currRotation != presumedRotation) {
presumedRotation = currRotation;
}
float nextRotation = transform.rotation;
// some weird fuckery I had to do because camera just does not have setRotation, fun. sure it does not.
if (nextRotation != presumedRotation && Math.abs(nextRotation - presumedRotation) > 0.001f) {
float diff = nextRotation - presumedRotation;
camera.rotate(diff);
presumedRotation = nextRotation;
}
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent in project talos by rockbite.
the class CameraTransformGizmo method updatePointsFromComponent.
@Override
protected void updatePointsFromComponent() {
// this is center position of camera
getWorldLocAround(tmp, 0, 0);
TransformComponent transformComponent = gameObject.getComponent(TransformComponent.class);
CameraComponent cameraComponent = gameObject.getComponent(CameraComponent.class);
points[LB].set(tmp.x - cameraComponent.size.x / 2f, tmp.y - cameraComponent.size.y / 2f);
points[LT].set(tmp.x - cameraComponent.size.x / 2f, tmp.y + cameraComponent.size.y / 2f);
points[RT].set(tmp.x + cameraComponent.size.x / 2f, tmp.y + cameraComponent.size.y / 2f);
points[RB].set(tmp.x + cameraComponent.size.x / 2f, tmp.y - cameraComponent.size.y / 2f);
points[LB].rotateAroundDeg(tmp, transformComponent.rotation);
points[LT].rotateAroundDeg(tmp, transformComponent.rotation);
points[RT].rotateAroundDeg(tmp, transformComponent.rotation);
points[RB].rotateAroundDeg(tmp, transformComponent.rotation);
// midpoint
tmp.set(points[RT]).sub(points[LB]).scl(0.5f).add(points[LB]);
updateRotationAreas(tmp.x, tmp.y);
}
Aggregations