private Matrix GetWorldMatrix(IEditorGameCameraService cameraService) { Matrix worldMatrix = Matrix.Identity; switch (Space) { case TransformationSpace.WorldSpace: worldMatrix.TranslationVector = AnchorEntity.Transform.WorldMatrix.TranslationVector; break; case TransformationSpace.ObjectSpace: var parentMatrix = Matrix.Identity; if (AnchorEntity.GetParent() != null) { parentMatrix = AnchorEntity.TransformValue.Parent.WorldMatrix; } // We don't use the entity's "WorldMatrix" because it's scale could be zero, which would break the gizmo. worldMatrix = Matrix.RotationQuaternion(AnchorEntity.Transform.Rotation) * Matrix.Translation(AnchorEntity.Transform.Position) * parentMatrix; break; case TransformationSpace.ViewSpace: worldMatrix = Matrix.Invert(cameraService.ViewMatrix); worldMatrix.TranslationVector = AnchorEntity.Transform.WorldMatrix.TranslationVector; break; default: throw new ArgumentOutOfRangeException(); } return(worldMatrix); }
private float GetTargetedScale(IEditorGameCameraService cameraService) { if (cameraService.Component.Projection == CameraProjectionMode.Perspective) { var distanceToSelectedEntity = Math.Abs(Vector3.TransformCoordinate(AnchorEntity.Transform.WorldMatrix.TranslationVector, cameraService.ViewMatrix).Z); return(SizeFactor * DefaultScale * 2f * (float)Math.Tan(MathUtil.DegreesToRadians(cameraService.VerticalFieldOfView / 2)) * distanceToSelectedEntity); } return(SizeFactor * DefaultScale * cameraService.Component.OrthographicSize); }
public override void Initialize(IServiceRegistry services, Scene editorScene) { base.Initialize(services, editorScene); if (GizmoRootEntity != null) { CollectComponentIds(GizmoRootEntity); } gizmos = Game.EditorServices.Get <IEditorGameComponentGizmoService>(); camera = Game.EditorServices.Get <IEditorGameCameraService>(); }