Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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>();
        }