Пример #1
0
 void IRenderable.Draw(WSceneView view)
 {
     DrawIfNotNull(m_vrSky, view);
     DrawIfNotNull(m_vrKasumiMae, view);
     DrawIfNotNull(m_vrUsoUmi, view);
     DrawIfNotNull(m_vrBackCloud, view);
 }
Пример #2
0
        void IRenderable.Draw(WSceneView view)
        {
            var bbox = GetBoundingBox();

            m_world.DebugDrawBox(bbox.Center, (bbox.Max - bbox.Min) / 2, Transform.Rotation, (Flags & NodeFlags.Selected) == NodeFlags.Selected ? WLinearColor.White : WLinearColor.Black, 0, 0);

            Matrix4 trs = Matrix4.CreateScale(Transform.LocalScale) * Matrix4.CreateFromQuaternion(Transform.Rotation) * Matrix4.CreateTranslation(Transform.Position);

            if (m_actorMesh != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (ColorOverrides.ColorsEnabled[i])
                    {
                        m_actorMesh.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                    }

                    if (ColorOverrides.ConstColorsEnabled[i])
                    {
                        m_actorMesh.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                    }
                }

                m_actorMesh.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
            else
            {
                m_objRender.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
Пример #3
0
        public void UpdateForSceneView(WSceneView view)
        {
            if (!Enabled)
            {
                return;
            }

            // Update camera distance to our camera.
            if ((!m_isTransforming) || (m_mode != FTransformMode.Translation))
            {
                m_cameraDistance = (view.GetCameraPos() - m_position).Length;
            }

            WLinearColor[] gizmoColors = new[]
            {
                WLinearColor.Red,
                WLinearColor.Green,
                WLinearColor.Blue,
                WLinearColor.Blue,
                WLinearColor.Red,
                WLinearColor.Green,
                WLinearColor.White,
            };

            List <AxisDistanceResult> results = new List <AxisDistanceResult>();

            var gizmoBoxes = GetAABBBoundsForMode(m_mode);

            for (int i = 0; i < gizmoBoxes.Length; i++)
            {
                //m_world.DebugDrawBox(gizmoBoxes[i].Min + m_position, gizmoBoxes[i].Max + m_position, gizmoColors[i], 25, 0f);
            }

            // Update Highlight Status of Models.
            int gizmoIndex = (int)m_mode - 1;

            if (gizmoIndex >= 0)
            {
                for (int i = 0; i < m_gizmoMeshes[gizmoIndex].Length; i++)
                {
                    FSelectedAxes axis = (FSelectedAxes)(m_mode == FTransformMode.Rotation ? i + 1 : i); // Rotation doesn't have a center, thus it needs an index fixup.
                    m_gizmoMeshes[gizmoIndex][i].Highlighted = ContainsAxis(m_selectedAxes, axis);
                }
            }

            //switch (m_mode)
            //{
            //    case FTransformMode.Translation:
            //        Console.WriteLine("m_position: {0} m_deltaTranslation: {1} m_totalTranslation: {2}", m_position, m_deltaTranslation, m_totalTranslation);
            //        break;
            //    case FTransformMode.Rotation:
            //        Console.WriteLine("m_rotation: {0} m_localRotation: {1} m_deltaRotation: {2} m_currentRotation: {3} m_totalRotation(UI): {4}", m_rotation, m_localRotation, m_deltaRotation, m_currentRotation, m_totalRotation);
            //        break;
            //    case FTransformMode.Scale:
            //        Console.WriteLine("m_scale: {0} m_deltaScale: {1} m_totalScale: {2}", m_scale, m_deltaScale, m_totalScale);
            //        break;
            //    default:
            //        break;
            //}
        }
Пример #4
0
        public override void Draw(WSceneView view)
        {
            var bbox = GetBoundingBox();

            m_world.DebugDrawBox(bbox.Center, (bbox.Max - bbox.Min) / 2, Transform.Rotation, (Flags & NodeFlags.Selected) == NodeFlags.Selected ? WLinearColor.White : WLinearColor.Black, 0, 0);

            int spawnPatternIndex = (int)SpawnPattern;
            int groupIndex        = kFoliageSpawnPatternGroupIndexes[spawnPatternIndex];
            int numModels         = kFoliageSpawnPatternNumModels[spawnPatternIndex];

            Vector3[] offsetsForGroup = kGrassSpawnOffsets[groupIndex];

            for (int i = 0; i < numModels; i++)
            {
                Vector3 modelOffset = offsetsForGroup[i];

                WTransform transform = new WTransform();

                if (Type == TypeEnum.Tree)
                {
                    // Only trees rotate, and they only rotate the positions of each tree model around the entity's center, not the individual trees themselves.
                    Quaternion rotation = Quaternion.Identity.FromEulerAngles(new Vector3(0, Transform.Rotation.ToEulerAngles().Y, 0));
                    modelOffset = Vector3.Transform(modelOffset, rotation);
                }

                transform.Position = Transform.Position + modelOffset;

                Matrix4 trs = Matrix4.CreateScale(transform.LocalScale) * Matrix4.CreateFromQuaternion(transform.Rotation) * Matrix4.CreateTranslation(transform.Position);

                m_objRender.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
Пример #5
0
        virtual public void Draw(WSceneView view)
        {
            Matrix4 trs = Matrix4.CreateScale(VisualScale) * Matrix4.CreateFromQuaternion(Transform.Rotation.ToSinglePrecision()) * Matrix4.CreateTranslation(Transform.Position);

            if (m_actorMeshes.Count > 0)
            {
                foreach (var actor_mesh in m_actorMeshes)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (ColorOverrides.ColorsEnabled[i])
                        {
                            actor_mesh.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                        }

                        if (ColorOverrides.ConstColorsEnabled[i])
                        {
                            actor_mesh.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                        }
                    }

                    if (IsSelected)
                    {
                        actor_mesh.Tick(1 / (float)60);
                    }

                    actor_mesh.Render(view.ViewMatrix, view.ProjMatrix, trs);
                }
            }
            else if (m_objRender != null)
            {
                m_objRender.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
Пример #6
0
        public override void Draw(WSceneView view)
        {
            base.Draw(view);
            if (m_stairMesh == null)
            {
                return;
            }

            for (int i = 0; i < 4; i++)
            {
                if (ColorOverrides.ColorsEnabled[i])
                {
                    m_stairMesh.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                }

                if (ColorOverrides.ConstColorsEnabled[i])
                {
                    m_stairMesh.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                }
            }

            for (int i = 1; i < GetNumStairs() + 1; i++)
            {
                WTransform transform = new WTransform();
                float      yRot      = Transform.Rotation.ToEulerAngles().Y + 180;
                transform.Rotation = Quaterniond.FromAxisAngle(Vector3d.UnitY, yRot / 180f * Math.PI);
                Vector3 positionOffset = new Vector3(0, i * 25f, i * -50f);
                positionOffset     = Vector3.Transform(positionOffset, transform.Rotation.ToSinglePrecision());
                transform.Position = Transform.Position + positionOffset;

                Matrix4 trs = Matrix4.CreateScale(transform.LocalScale) * Matrix4.CreateFromQuaternion(transform.Rotation.ToSinglePrecision()) * Matrix4.CreateTranslation(transform.Position);

                m_stairMesh.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
Пример #7
0
        void IRenderable.Draw(WSceneView view)
        {
            if (!Enabled)
            {
                return;
            }

            m_scale = Vector3.One * m_gizmoSize * (float)(Math.Sqrt(m_cameraDistance) / 2.5f);

            // Construct a model matrix for the gizmo mesh to render at.
            Matrix4 modelMatrix = Matrix4.CreateScale(m_scale) * Matrix4.CreateFromQuaternion(m_rotation) * Matrix4.CreateTranslation(m_position);

            // Clear the depth buffer so the transform gizmo draws on top of everything else.
            // Note that we must clear it only before drawing the entire gizmo. Clearing it for each mesh would result in strange z-indexing between the multiple meshes.
            GL.Clear(ClearBufferMask.DepthBufferBit);

            int gizmoIndex = (int)m_mode - 1;

            if (gizmoIndex >= 0)
            {
                for (int j = 0; j < m_gizmoMeshes[gizmoIndex].Length; j++)
                {
                    m_gizmoMeshes[gizmoIndex][j].Render(view.ViewMatrix, view.ProjMatrix, modelMatrix);
                }
            }
        }
Пример #8
0
        public override void Draw(WSceneView view)
        {
            if (HasBrazier() && m_brazierModel != null)
            {
                // Draw the brazier.
                Matrix4 trs = Matrix4.CreateFromQuaternion(Transform.Rotation) * Matrix4.CreateTranslation(Transform.Position);

                for (int i = 0; i < 4; i++)
                {
                    if (ColorOverrides.ColorsEnabled[i])
                    {
                        m_brazierModel.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                    }

                    if (ColorOverrides.ConstColorsEnabled[i])
                    {
                        m_brazierModel.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                    }
                }

                if (IsSelected)
                {
                    m_brazierModel.Tick(1 / (float)60);
                }

                m_brazierModel.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }

            // Draw the region that is lit up.
            base.Draw(view);
        }
Пример #9
0
        override public void Draw(WSceneView view)
        {
            base.Draw(view);

            if (NextNode != null)
            {
                m_world.DebugDrawLine(Transform.Position, NextNode.Transform.Position, WLinearColor.Black, 5f, 0f);
            }
        }
Пример #10
0
        private void DrawIfNotNull(IRenderable skyPart, WSceneView view)
        {
            if (skyPart == null)
            {
                return;
            }

            skyPart.Draw(view);
        }
Пример #11
0
 public void AddToRenderer(WSceneView view)
 {
     foreach (WScene scene in m_sceneList)
     {
         foreach (var renderable in scene.GetChildrenOfType <IRenderable>())
         {
             renderable.AddToRenderer(view);
         }
     }
 }
Пример #12
0
        private void CheckForObjectSelectionChange(WSceneView view)
        {
            // If we have a gizmo and we're transforming it, don't check for selection change.
            if (m_transformGizmo != null && m_transformGizmo.IsTransforming)
            {
                return;
            }
            if (WInput.GetMouseButtonDown(0) && !WInput.GetMouseButton(1))
            {
                FRay       mouseRay   = view.ProjectScreenToWorld(WInput.MousePosition);
                WActorNode addedActor = Raycast(mouseRay);

                // Check the behaviour of this click to determine appropriate selection modification behaviour.
                // Click w/o Modifiers = Clear Selection, add result to selection
                // Click /w Ctrl = Toggle Selection State
                // Click /w Shift = Add to Selection
                bool ctrlPressed  = WInput.GetKey(Key.LeftCtrl) || WInput.GetKey(Key.RightCtrl);
                bool shiftPressed = WInput.GetKey(Key.LeftShift) || WInput.GetKey(Key.RightShift);

                if (!ctrlPressed & !shiftPressed)
                {
                    ModifySelection(SelectionType.Add, addedActor, true);
                    //m_selectionList.Clear();
                    //if (addedActor != null) m_selectionList.Add(addedActor);
                }
                else if (addedActor != null && (ctrlPressed && !shiftPressed))
                {
                    if (m_selectionList.Contains(addedActor))
                    {
                        ModifySelection(SelectionType.Remove, addedActor, false);
                    }
                    //m_selectionList.Remove(addedActor);
                    else
                    {
                        ModifySelection(SelectionType.Add, addedActor, false);
                    }
                    //m_selectionList.Add(addedActor);
                }
                else if (addedActor != null && shiftPressed)
                {
                    if (!m_selectionList.Contains(addedActor))
                    {
                        ModifySelection(SelectionType.Add, addedActor, false);
                    }
                    //m_selectionList.Add(addedActor);
                }

                if (m_transformGizmo != null && m_selectionList.Count > 0)
                {
                    m_transformGizmo.SetPosition(m_selectionList[0].Transform.Position);
                    m_transformGizmo.SetLocalRotation(m_selectionList[0].Transform.Rotation);
                }
            }
        }
Пример #13
0
 public override void AddToRenderer(WSceneView view)
 {
     if (Type == TypeEnum.Light_Beam)
     {
         view.AddTransparentMesh(this);
     }
     else
     {
         view.AddOpaqueMesh(this);
     }
 }
Пример #14
0
        public void UpdateForSceneView(WSceneView view)
        {
            // Update our Selection Gizmo first, so we can check if it is currently transforming when we check to see
            // if the user's selection has changed.
            UpdateSelectionGizmo(view);

            // Check to see if they've left clicked and are changing their selection.
            CheckForObjectSelectionChange(view);

            // Add our gizmo to the renderer this frame.
            ((IRenderable)m_transformGizmo).AddToRenderer(view);
        }
Пример #15
0
        public WWorld()
        {
            m_dtStopwatch     = new System.Diagnostics.Stopwatch();
            m_persistentLines = new WLineBatcher();
            m_undoStack       = new WUndoStack();
            m_actorEditor     = new WActorEditor(this);

            m_sceneViews = new List <WSceneView>();

            WSceneView perspectiveView = new WSceneView();

            m_sceneViews.AddRange(new[] { perspectiveView });
        }
Пример #16
0
        public override void Draw(WSceneView view)
        {
            if (Type == TypeEnum.Laser_Barrier && LaserPath != null)
            {
                Matrix4 centerTrs = Matrix4.CreateTranslation(Transform.Position);
                m_objRender.Render(view.ViewMatrix, view.ProjMatrix, centerTrs);

                if (m_actorMeshes.Count > 0)
                {
                    var wallMountModel = m_actorMeshes[0];

                    for (int i = 0; i < 4; i++)
                    {
                        if (ColorOverrides.ColorsEnabled[i])
                        {
                            wallMountModel.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                        }

                        if (ColorOverrides.ConstColorsEnabled[i])
                        {
                            wallMountModel.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                        }
                    }

                    var points = LaserPath.GetPoints();
                    if (points.Count < 2)
                    {
                        return;
                    }

                    Vector3 p1         = points[0].Transform.Position;
                    Vector3 p2         = points[1].Transform.Position;
                    Vector3 path_delta = p2 - p1;
                    float   y_rot1     = (float)Math.Atan2(path_delta.X, path_delta.Z);
                    float   y_rot2     = (float)Math.Atan2(-path_delta.X, -path_delta.Z);

                    Quaternion firstPointRotation  = Quaternion.FromAxisAngle(Vector3.UnitY, y_rot1);
                    Quaternion secondPointRotation = Quaternion.FromAxisAngle(Vector3.UnitY, y_rot2);

                    Matrix4 firstTrs  = Matrix4.CreateFromQuaternion(firstPointRotation) * Matrix4.CreateTranslation(points[0].Transform.Position);
                    Matrix4 secondTrs = Matrix4.CreateFromQuaternion(secondPointRotation) * Matrix4.CreateTranslation(points[1].Transform.Position);

                    wallMountModel.Render(view.ViewMatrix, view.ProjMatrix, firstTrs);
                    wallMountModel.Render(view.ViewMatrix, view.ProjMatrix, secondTrs);
                }
            }
            else
            {
                base.Draw(view);
            }
        }
Пример #17
0
        override public void Draw(WSceneView view)
        {
            base.Draw(view);

            if (NextNode != null)
            {
                WLinearColor color = WLinearColor.Black;
                if (IsPathSelected)
                {
                    color = WLinearColor.Green;
                }
                m_world.DebugDrawLine(Transform.Position, NextNode.Transform.Position, color, 5f, 0f);
            }
        }
Пример #18
0
        private void CheckForObjectSelectionChange(WSceneView view)
        {
            // If we have a gizmo and we're transforming it, don't check for selection change.
            if (m_transformGizmo != null && m_transformGizmo.IsTransforming)
            {
                return;
            }
            if (WInput.GetMouseButtonDown(0) && !WInput.GetMouseButton(1))
            {
                FRay mouseRay   = view.ProjectScreenToWorld(WInput.MousePosition);
                var  addedActor = Raycast(mouseRay);

                // Check the behaviour of this click to determine appropriate selection modification behaviour.
                // Click w/o Modifiers = Clear Selection, add result to selection
                // Click /w Ctrl = Toggle Selection State
                // Click /w Shift = Add to Selection
                bool ctrlPressed  = WInput.GetKey(Key.LeftCtrl) || WInput.GetKey(Key.RightCtrl);
                bool shiftPressed = WInput.GetKey(Key.LeftShift) || WInput.GetKey(Key.RightShift);

                if (!ctrlPressed & !shiftPressed)
                {
                    EditorSelection.ClearSelection();
                    if (addedActor != null)
                    {
                        EditorSelection.AddToSelection(addedActor);
                    }
                }
                else if (addedActor != null && (ctrlPressed && !shiftPressed))
                {
                    if (addedActor.IsSelected)
                    {
                        EditorSelection.RemoveFromSelection(addedActor);
                    }
                    else
                    {
                        EditorSelection.AddToSelection(addedActor);
                    }
                }
                else if (addedActor != null && shiftPressed)
                {
                    if (!EditorSelection.SelectedObjects.Contains(addedActor))
                    {
                        EditorSelection.AddToSelection(addedActor);
                    }
                }

                UpdateGizmoTransform();
            }
        }
Пример #19
0
        private void UpdateSceneViews()
        {
            // If they've clicked, check which view is in focus.
            if (WInput.GetMouseButtonDown(0) || WInput.GetMouseButtonDown(1) || WInput.GetMouseButtonDown(2))
            {
                WSceneView focusedScene = GetFocusedSceneView();
                foreach (var scene in m_sceneViews)
                {
                    scene.IsFocused = false;
                    FRect viewport = scene.GetViewportDimensions();
                    if (viewport.Contains(WInput.MousePosition.X, WInput.MousePosition.Y))
                    {
                        focusedScene = scene;
                    }
                }

                focusedScene.IsFocused = true;
            }
        }
Пример #20
0
        void IRenderable.Draw(WSceneView view)
        {
            Vector3    scale       = Transform.LocalScale;
            Quaternion rotation    = Transform.Rotation;
            Vector3    translation = Transform.Position;

            if (RoomTransform != null)
            {
                rotation    = Quaternion.FromAxisAngle(Vector3.UnitY, WMath.DegreesToRadians(RoomTransform.YRotation));
                translation = new Vector3(RoomTransform.Translation.X, 0, RoomTransform.Translation.Y);
            }

            Matrix4 trs = Matrix4.CreateScale(scale) * Matrix4.CreateFromQuaternion(rotation) * Matrix4.CreateTranslation(translation);

            foreach (var mesh in m_roomModels)
            {
                mesh.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
Пример #21
0
        public override void Draw(WSceneView view)
        {
            Matrix4 trs            = Matrix4.CreateScale(VisualScale) * Matrix4.CreateFromQuaternion(Transform.Rotation) * Matrix4.CreateTranslation(Transform.Position);
            Matrix4 centerPointTrs = Matrix4.CreateTranslation(Transform.Position);

            // Render the center point model first.
            if (m_actorMeshes.Count > 0)
            {
                foreach (var actor_mesh in m_actorMeshes)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (ColorOverrides.ColorsEnabled[i])
                        {
                            actor_mesh.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                        }

                        if (ColorOverrides.ConstColorsEnabled[i])
                        {
                            actor_mesh.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                        }
                    }

                    if (IsSelected)
                    {
                        actor_mesh.Tick(1 / (float)60);
                    }

                    actor_mesh.Render(view.ViewMatrix, view.ProjMatrix, centerPointTrs);
                }
            }
            else if (m_objRender != null)
            {
                m_objRender.Render(view.ViewMatrix, view.ProjMatrix, centerPointTrs);
            }

            // Then render the area, but only when selected.
            if (IsSelected)
            {
                m_RegionAreaModel.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
Пример #22
0
        public WWorld()
        {
            m_dtStopwatch     = new System.Diagnostics.Stopwatch();
            m_persistentLines = new WLineBatcher();
            m_persistentQuads = new WQuadBatcher();

            m_undoStack = new WUndoStack();

            m_ActorMode     = new ActorMode(this);
            m_CollisionMode = new CollisionMode(this);
            m_EventMode     = new EventMode(this);

            CurrentMode = m_ActorMode;

            m_sceneViews = new List <WSceneView>();

            WSceneView perspectiveView = new WSceneView();

            m_sceneViews.AddRange(new[] { perspectiveView });
        }
Пример #23
0
        void IRenderable.Draw(WSceneView view)
        {
            if (!Enabled)
            {
                return;
            }

            m_scale = Vector3.One * m_gizmoSize * (m_cameraDistance / 100f);

            // Construct a model matrix for the gizmo mesh to render at.
            Matrix4 modelMatrix = Matrix4.CreateScale(m_scale) * Matrix4.CreateFromQuaternion(m_rotation) * Matrix4.CreateTranslation(m_position);

            int gizmoIndex = (int)m_mode - 1;

            if (gizmoIndex >= 0)
            {
                for (int j = 0; j < m_gizmoMeshes[gizmoIndex].Length; j++)
                {
                    m_gizmoMeshes[gizmoIndex][j].Render(view.ViewMatrix, view.ProjMatrix, modelMatrix);
                }
            }
        }
Пример #24
0
        public override void Draw(WSceneView view)
        {
            base.Draw(view);

            if (m_liftControlMesh == null || Path == null)
            {
                return;
            }

            for (int i = 0; i < 4; i++)
            {
                if (ColorOverrides.ColorsEnabled[i])
                {
                    m_liftControlMesh.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                }

                if (ColorOverrides.ConstColorsEnabled[i])
                {
                    m_liftControlMesh.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                }
            }

            var points = Path.GetPoints();

            for (int pathPointIndex = 2; pathPointIndex < 4; pathPointIndex++)
            {
                if (pathPointIndex >= points.Count)
                {
                    break;
                }
                PathPoint_v2 point = points[pathPointIndex];

                Matrix4 trs = Matrix4.CreateScale(point.Transform.LocalScale) * Matrix4.CreateFromQuaternion(point.Transform.Rotation) * Matrix4.CreateTranslation(point.Transform.Position);

                m_liftControlMesh.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
Пример #25
0
 void IRenderable.AddToRenderer(WSceneView view)
 {
     view.AddOpaqueMesh(this);
 }
Пример #26
0
        void IRenderable.Draw(WSceneView view)
        {
            Matrix4 trs = Matrix4.CreateScale(Transform.LocalScale) * Matrix4.CreateFromQuaternion(Transform.Rotation.ToSinglePrecision()) * Matrix4.CreateTranslation(Transform.Position);

            m_model.Render(view.ViewMatrix, view.ProjMatrix, trs);
        }
Пример #27
0
 void IRenderable.AddToRenderer(WSceneView view)
 {
     view.AddTransparentMesh(this);
 }
Пример #28
0
        public bool TransformFromInput(FRay ray, WSceneView view)
        {
            if (m_mode != FTransformMode.Translation)
            {
                WrapCursor();
            }

            // Store the cursor position in viewport coordinates.
            Vector2 screenDimensions = App.GetScreenGeometry();
            Vector2 cursorPos        = App.GetCursorPosition();
            Vector2 mouseCoords      = new Vector2(((2f * cursorPos.X) / screenDimensions.X) - 1f, (1f - ((2f * cursorPos.Y) / screenDimensions.Y))); //[-1,1] range

            bool shiftPressed = WInput.GetKey(Key.LeftShift) || WInput.GetKey(Key.RightShift);

            if (m_mode == FTransformMode.Translation)
            {
                // Create a Translation Plane
                Vector3 axisA, axisB;

                if (GetNumSelectedAxes() == 1)
                {
                    if (m_selectedAxes == FSelectedAxes.X)
                    {
                        axisB = Vector3.UnitX;
                    }
                    else if (m_selectedAxes == FSelectedAxes.Y)
                    {
                        axisB = Vector3.UnitY;
                    }
                    else
                    {
                        axisB = Vector3.UnitZ;
                    }

                    Vector3 dirToCamera = (m_position - view.GetCameraPos()).Normalized();
                    axisA = Vector3.Cross(axisB, dirToCamera);
                }
                else
                {
                    axisA = ContainsAxis(m_selectedAxes, FSelectedAxes.X) ? Vector3.UnitX : Vector3.UnitZ;
                    axisB = ContainsAxis(m_selectedAxes, FSelectedAxes.Y) ? Vector3.UnitY : Vector3.UnitZ;
                }

                Vector3 planeNormal = Vector3.Cross(axisA, axisB).Normalized();
                m_translationPlane = new FPlane(planeNormal, m_position);

                float intersectDist;
                if (m_translationPlane.RayIntersectsPlane(ray, out intersectDist))
                {
                    Vector3 hitPos     = ray.Origin + (ray.Direction * intersectDist);
                    Vector3 localDelta = Vector3.Transform(hitPos - m_position, m_rotation.Inverted());

                    // Calculate a new position
                    Vector3 newPos = m_position;
                    if (ContainsAxis(m_selectedAxes, FSelectedAxes.X))
                    {
                        newPos += Vector3.Transform(Vector3.UnitX, m_rotation) * localDelta.X;
                    }
                    if (ContainsAxis(m_selectedAxes, FSelectedAxes.Y))
                    {
                        newPos += Vector3.Transform(Vector3.UnitY, m_rotation) * localDelta.Y;
                    }
                    if (ContainsAxis(m_selectedAxes, FSelectedAxes.Z))
                    {
                        newPos += Vector3.Transform(Vector3.UnitZ, m_rotation) * localDelta.Z;
                    }

                    if (shiftPressed)
                    {
                        // Round to nearest 100 unit increment while shift is held down.
                        newPos.X = (float)Math.Round(newPos.X / 100f) * 100f;
                        newPos.Y = (float)Math.Round(newPos.Y / 100f) * 100f;
                        newPos.Z = (float)Math.Round(newPos.Z / 100f) * 100f;
                    }

                    // Check the new location to see if it's skyrocked off into the distance due to near-plane raytracing issues.
                    Vector3 newPosDirToCamera = (newPos - view.GetCameraPos()).Normalized();
                    float   dot = Math.Abs(Vector3.Dot(planeNormal, newPosDirToCamera));

                    //Console.WriteLine("hitPos: {0} localOffset: {1} newPos: {2}, dotResult: {3}", hitPos, localOffset, newPos, dot);
                    if (dot < 0.02f)
                    {
                        return(false);
                    }

                    // This is used to set the offset to the gizmo the mouse cursor is from the origin of the gizmo on the first frame
                    // that you click on the gizmo.
                    if (!m_hasSetMouseOffset)
                    {
                        m_translateOffset   = m_position - newPos;
                        m_deltaTranslation  = Vector3.Zero;
                        m_hasSetMouseOffset = true;
                        return(false);
                    }

                    // Apply Translation
                    m_deltaTranslation = Vector3.Transform(newPos - m_position + m_translateOffset, m_rotation.Inverted());

                    if (!ContainsAxis(m_selectedAxes, FSelectedAxes.X))
                    {
                        m_deltaTranslation.X = 0f;
                    }
                    if (!ContainsAxis(m_selectedAxes, FSelectedAxes.Y))
                    {
                        m_deltaTranslation.Y = 0f;
                    }
                    if (!ContainsAxis(m_selectedAxes, FSelectedAxes.Z))
                    {
                        m_deltaTranslation.Z = 0f;
                    }

                    m_totalTranslation += m_deltaTranslation;
                    m_position         += Vector3.Transform(m_deltaTranslation, m_rotation);

                    if (!m_hasTransformed && (m_deltaTranslation != Vector3.Zero))
                    {
                        m_hasTransformed = true;
                    }

                    return(m_hasTransformed);
                }
                else
                {
                    // Our raycast missed the plane
                    m_deltaTranslation = Vector3.Zero;
                    return(false);
                }
            }
            else if (m_mode == FTransformMode.Rotation)
            {
                Vector3 rotationAxis;
                if (m_selectedAxes == FSelectedAxes.X)
                {
                    rotationAxis = Vector3.UnitX;
                }
                else if (m_selectedAxes == FSelectedAxes.Y)
                {
                    rotationAxis = Vector3.UnitY;
                }
                else
                {
                    rotationAxis = Vector3.UnitZ;
                }

                // Convert these from [0-1] to [-1, 1] to match our mouse coords.
                Vector2 lineOrigin = (view.UnprojectWorldToViewport(m_hitPoint) * 2) - Vector2.One;
                Vector2 lineEnd    = (view.UnprojectWorldToViewport(m_hitPoint + m_moveDir) * 2) - Vector2.One;

                lineOrigin.Y = -lineOrigin.Y;
                lineEnd.Y    = -lineEnd.Y;

                Vector2 lineDir   = (lineEnd - lineOrigin).Normalized();
                float   rotAmount = Vector2.Dot(lineDir, mouseCoords + m_wrapOffset - lineOrigin) * 180f;

                if (float.IsNaN(rotAmount))
                {
                    Console.WriteLine("rotAmountNaN!");
                    return(false);
                }

                if (!m_hasSetMouseOffset)
                {
                    m_rotateOffset      = -rotAmount;
                    m_deltaRotation     = Quaternion.Identity;
                    m_hasSetMouseOffset = true;
                    return(false);
                }

                // Apply Rotation
                rotAmount += m_rotateOffset;
                if (shiftPressed)
                {
                    // Round to nearest 45 degree increment while shift is held down.
                    rotAmount = (float)Math.Round(rotAmount / 45f) * 45f;
                }
                Quaternion oldRot = m_currentRotation;
                m_currentRotation = Quaternion.FromAxisAngle(rotationAxis, WMath.DegreesToRadians(rotAmount));
                m_deltaRotation   = m_currentRotation * oldRot.Inverted();

                if (m_transformSpace == FTransformSpace.Local)
                {
                    m_rotation *= m_deltaRotation;
                }

                // Add to Total Rotation recorded for UI.
                if (m_selectedAxes == FSelectedAxes.X)
                {
                    m_totalRotation.X = rotAmount;
                }
                else if (m_selectedAxes == FSelectedAxes.Y)
                {
                    m_totalRotation.Y = rotAmount;
                }
                else
                {
                    m_totalRotation.Z = rotAmount;
                }

                if (!m_hasTransformed && rotAmount != 0f)
                {
                    m_hasTransformed = true;
                }

                return(m_hasTransformed);
            }
            else if (m_mode == FTransformMode.Scale)
            {
                // Create a line in screen space.
                // Convert these from [0-1] to [-1, 1] to match our mouse coords.
                Vector2 lineOrigin = (view.UnprojectWorldToViewport(m_position) * 2) - Vector2.One;
                lineOrigin.Y = -lineOrigin.Y;

                // Determine the appropriate world space directoin using the selected axes and then conver this for use with
                // screen-space controlls. This has to be done every frame because the axes can be flipped while the gizmo
                // is transforming, so we can't pre-calculate this.
                Vector3 dirX = Vector3.Transform(mFlipScaleX ? -Vector3.UnitX : Vector3.UnitX, m_rotation);
                Vector3 dirY = Vector3.Transform(mFlipScaleY ? -Vector3.UnitY : Vector3.UnitY, m_rotation);
                Vector3 dirZ = Vector3.Transform(mFlipScaleZ ? -Vector3.UnitZ : Vector3.UnitZ, m_rotation);
                Vector2 lineDir;

                // If there is only one axis, then the world space direction is the selected axis.
                if (GetNumSelectedAxes() == 1)
                {
                    Vector3 worldDir;
                    if (ContainsAxis(m_selectedAxes, FSelectedAxes.X))
                    {
                        worldDir = dirX;
                    }
                    if (ContainsAxis(m_selectedAxes, FSelectedAxes.Y))
                    {
                        worldDir = dirY;
                    }
                    else
                    {
                        worldDir = dirZ;
                    }

                    Vector2 worldPoint = (view.UnprojectWorldToViewport(m_position + worldDir) * 2) - Vector2.One;
                    worldPoint.Y = -lineOrigin.Y;

                    lineDir = (worldPoint - lineOrigin).Normalized();
                }
                // If there's two axii selected, then convert both to screen space and average them out to get the line direction.
                else if (GetNumSelectedAxes() == 2)
                {
                    Vector3 axisA = ContainsAxis(m_selectedAxes, FSelectedAxes.X) ? dirX : dirY;
                    Vector3 axisB = ContainsAxis(m_selectedAxes, FSelectedAxes.Z) ? dirZ : dirY;

                    Vector2 screenA = (view.UnprojectWorldToViewport(m_position + axisA) * 2) - Vector2.One;
                    screenA.Y = -screenA.Y;
                    Vector2 screenB = (view.UnprojectWorldToViewport(m_position + axisB) * 2) - Vector2.One;
                    screenB.Y = -screenB.Y;

                    screenA = (screenA - lineOrigin).Normalized();
                    screenB = (screenB - lineOrigin).Normalized();
                    lineDir = ((screenA + screenB) / 2f).Normalized();
                }
                // There's three axis, just use up.
                else
                {
                    lineDir = Vector2.UnitY;
                }

                float scaleAmount = Vector2.Dot(lineDir, mouseCoords + m_wrapOffset - lineOrigin) * 5f;

                if (shiftPressed)
                {
                    // Round to nearest whole number scale while shift is held down.
                    scaleAmount = (float)Math.Round(scaleAmount);
                }

                // Set their initial offset if we haven't already
                if (!m_hasSetMouseOffset)
                {
                    m_scaleOffset       = -scaleAmount;
                    m_deltaScale        = Vector3.One;
                    m_hasSetMouseOffset = true;
                    return(false);
                }

                // Apply the scale
                scaleAmount = scaleAmount + m_scaleOffset + 1f;

                // A multiplier is applied to the scale amount if it's less than one to prevent it dropping into the negatives.
                // ???
                if (scaleAmount < 1f)
                {
                    scaleAmount = 1f / (-(scaleAmount - 1f) + 1f);
                }

                Vector3 oldScale = m_totalScale;
                m_totalScale = Vector3.One;
                if (ContainsAxis(m_selectedAxes, FSelectedAxes.X))
                {
                    m_totalScale.X = scaleAmount;
                }
                if (ContainsAxis(m_selectedAxes, FSelectedAxes.Y))
                {
                    m_totalScale.Y = scaleAmount;
                }
                if (ContainsAxis(m_selectedAxes, FSelectedAxes.Z))
                {
                    m_totalScale.Z = scaleAmount;
                }

                m_deltaScale = new Vector3(m_totalScale.X / oldScale.X, m_totalScale.Y / oldScale.Y, m_totalScale.Z / oldScale.Z);

                if (!m_hasTransformed && (scaleAmount != 1f))
                {
                    m_hasTransformed = true;
                }

                return(m_hasTransformed);
            }

            return(false);
        }
Пример #29
0
 override public void AddToRenderer(WSceneView view)
 {
     view.AddOpaqueMesh(this);
 }
Пример #30
0
 public override void AddToRenderer(WSceneView view)
 {
     view.AddTransparentMesh(this);
 }