Commit c3220788 authored by Christian Winter's avatar Christian Winter

prefabs rotation and scale preview working

parent 538a370a
......@@ -32,6 +32,11 @@ class LineManipulator {
for (let p of selAsPoints)
p.position = this.rotatePositionByAngle(p.position, rotationCenter, degrees);
for (let instance of Selection.data.prefabInstances) {
instance.transform.position = this.rotatePositionByAngle(instance.transform.position, rotationCenter, degrees);
instance.transform.rotation += degrees;
}
Renderer.redraw();
}
......@@ -122,6 +127,11 @@ class LineManipulator {
for (let p of selectionAsPoints)
p.position = this.scalePoint(p.position, center, scaleVector);
for (let instance of Selection.data.prefabInstances) {
instance.transform.position = this.scalePoint(instance.transform.position, center, scaleVector);
instance.transform.scale = instance.transform.scale.addVector(scaleVector);
}
Renderer.redraw();
}
......
......@@ -130,9 +130,19 @@ class Vector2 {
let epsilon = 0.01; // TODO STATIC??
return Vector2.sqrDistance(this, other) <= (epsilon * epsilon);
}
rotateAround(center, degree) {
return LineManipulator.rotatePositionByAngle(this, center, degree);
}
scaleFrom(center, scaleVector) {
return LineManipulator.scalePoint(this, center, scaleVector);
}
static get zero() {
return new Vector2(0, 0);
}
toString(decimals) {
if (decimals == undefined)
decimals = 2;
......
......@@ -833,6 +833,8 @@
ending.line.thickness,
ending.line.color
);
this.drawPrefabInstances(Settings.prefabSelectionColor, null, angleDegree, null, center);
}
static drawScaleLinesPreview() {
......@@ -861,6 +863,8 @@
ending.line.thickness,
ending.line.color
);
this.drawPrefabInstances(Settings.prefabSelectionColor, null, null, scaleVector, center);
}
static drawCrosshair(dontSnap) {
......@@ -988,32 +992,66 @@
}
static drawPrefabInstances(outlinecolor, deltaPos, deltaRot, deltaScale) {
deltaPos = deltaPos ? deltaPos : new Vector2(0, 0);
static drawPrefabInstances(outlinecolor, deltaPos, deltaRot, deltaScale, center) {
let positionOnly = false;
// draw prefab instances
for (let instance of Selection.data.prefabInstances) {
if (!Logic.isPreviewing())
this.batchCircle(instance.transform.position.addVector(deltaPos));
// TODO multibatching? or dont delete batch after rendering to reuse?
// light green outline
{
let pos = instance.transform.position;
if (deltaPos)
pos = pos.addVector(deltaPos);
if (deltaRot)
pos = pos.rotateAround(center, deltaRot);
if (deltaScale)
pos = pos.scaleFrom(center, deltaScale);
this.batchCircle(pos);
}
// TODO multibatching? or dont delete batch after rendering to reuse?
// light green outline
if (!Logic.isPreviewing()) {
for (let line of instance.reference.lines)
this.drawLineFromTo(
line.start.position.addVector(instance.transform.position).addVector(deltaPos),
line.end.position.addVector(instance.transform.position).addVector(deltaPos),
line.thickness + Settings.prefabOutlineSize,
outlinecolor
);
for (let line of instance.reference.lines) {
let start = line.start.position.addVector(instance.transform.position);
let end = line.end.position.addVector(instance.transform.position);
if (deltaPos) {
start = start.addVector(deltaPos);
end = end.addVector(deltaPos);
}
if (deltaRot) {
start = start.rotateAround(center, deltaRot);
end = end.rotateAround(center, deltaRot);
}
if (deltaScale) {
start = start.scaleFrom(center, deltaScale);
end = end.scaleFrom(center, deltaScale);
}
this.drawLineFromTo(start, end, line.thickness + Settings.prefabOutlineSize, outlinecolor);
}
}
for (let line of instance.reference.lines)
this.drawLineFromTo(
line.start.position.addVector(instance.transform.position).addVector(deltaPos),
line.end.position.addVector(instance.transform.position).addVector(deltaPos),
line.thickness,
line.color
);
{
let start = line.start.position.addVector(instance.transform.position);
let end = line.end.position.addVector(instance.transform.position);
if (deltaPos) {
start = start.addVector(deltaPos);
end = end.addVector(deltaPos);
}
if (deltaRot) {
start = start.rotateAround(center, deltaRot);
end = end.rotateAround(center, deltaRot);
}
if (deltaScale) {
start = start.scaleFrom(center, deltaScale);
end = end.scaleFrom(center, deltaScale);
}
this.drawLineFromTo(start, end, line.thickness, line.color);
}
}
if (!Logic.isPreviewing())
this.renderBatchedCircles(2, 0, outlinecolor, false, true, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment