public override void OnSingleClick(ProceduralObject obj) { foreach (var po in selection) { if (po.isRootOfGroup && logic.selectedGroup == null) { Quaternion diff = obj.m_rotation * Quaternion.Inverse(po.m_rotation); foreach (var o in po.group.objects) { o.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.moveTo, null); o.SetRotation(diff * o.m_rotation); if (o != po) { o.SetPosition(VertexUtils.RotatePointAroundPivot(o.m_position, po.m_position, diff)); } o.historyEditionBuffer.ConfirmNewStep(null); } } else { po.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.rotation, null); po.SetRotation(obj.m_rotation); po.historyEditionBuffer.ConfirmNewStep(null); } } ExitAction(); }
public void DoSlope(bool oriented) { var maxObjects = VertexUtils.OutmostPoints(selection.ToArray()); float heightDiff = maxObjects.Value.m_position.y - maxObjects.Key.m_position.y; float distDiff = Vector2.Distance(maxObjects.Value.m_position.AsXZVector2(), maxObjects.Key.m_position.AsXZVector2()); Vector3 flatDirection = new Vector3(maxObjects.Value.m_position.x, 0, maxObjects.Value.m_position.z) - new Vector3(maxObjects.Key.m_position.x, 0, maxObjects.Key.m_position.z); Quaternion rotDiff = Quaternion.FromToRotation(flatDirection, maxObjects.Value.m_position - maxObjects.Key.m_position); foreach (var po in selection) { var localdistdiff = Vector3.Project((po.m_position - maxObjects.Key.m_position).NullY(), (maxObjects.Value.m_position - maxObjects.Key.m_position).NullY()).magnitude; var localheightdiff = (po == maxObjects.Key) ? 0f : ((po == maxObjects.Value) ? heightDiff : heightDiff * localdistdiff / distDiff); if (po.isRootOfGroup && logic.selectedGroup == null) { foreach (var o in po.group.objects) { if (oriented) { o.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.moveTo, null); o.SetPosition(new Vector3(o.m_position.x, localheightdiff + maxObjects.Key.m_position.y, o.m_position.z)); o.SetRotation(rotDiff * o.m_rotation); if (o != po) { o.m_position = VertexUtils.RotatePointAroundPivot(o.m_position, po.m_position, rotDiff); } } else { o.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.position, null); o.SetPosition(new Vector3(o.m_position.x, localheightdiff + maxObjects.Key.m_position.y, o.m_position.z)); } o.historyEditionBuffer.ConfirmNewStep(null); } } else { if (oriented) { po.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.moveTo, null); po.SetRotation(rotDiff * po.m_rotation); } else { po.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.position, null); } po.SetPosition(new Vector3(po.m_position.x, localheightdiff + maxObjects.Key.m_position.y, po.m_position.z)); po.historyEditionBuffer.ConfirmNewStep(null); } } }
// move vertices public void ApplyToNewPosition(Vector3 newHitPoint, ProceduralObject obj) { if (relativePositions == null) { return; } if (relativePositions.Count == 0) { return; } var referencial = VertexUtils.RotatePointAroundPivot(newHitPoint, originHitPoint, Quaternion.Inverse(obj.m_rotation)); foreach (KeyValuePair <Vertex, Vector3> kvp in relativePositions) { var newpos = kvp.Value + referencial; kvp.Key.Position = new Vector3(newpos.x, kvp.Key.Position.y, newpos.z); } }
// rotate vertices public void ApplyToNewPosition(float mousePosX) { float diff = originMousePosition.x - mousePosX; Quaternion rot = Quaternion.identity; if (diff > 0) { rot = Quaternion.Euler(0, (diff * 370f) / Screen.width, 0); } else { rot = Quaternion.Euler(0, -(((-diff) * 370f) / Screen.width), 0); } foreach (KeyValuePair <Vertex, Vertex> kvp in rotVertices) { kvp.Value.Position = VertexUtils.RotatePointAroundPivot(kvp.Key.Position, verticesBounds.center, rot); } }
private void ApplyRotations() { foreach (var po in selection) { Quaternion appliedRot = Quaternion.Euler(RandomX ? randomizedRotations[po].x : 0f, RandomY ? randomizedRotations[po].y : 0f, RandomZ ? randomizedRotations[po].z : 0f); if (po.isRootOfGroup && logic.selectedGroup == null) { foreach (var o in po.group.objects) { o.SetRotation(appliedRot * oldRotations[o]); if (o != po) { o.SetPosition(VertexUtils.RotatePointAroundPivot(oldPositions[o], po.m_position, appliedRot)); } } } else { po.SetRotation(appliedRot * oldRotations[po]); } } }