Ejemplo n.º 1
0
        void IManipulator.Render(ViewControl vc)
        {
            TerrainGob terrain = m_terrainEditor.TerrainEditorControl.SelectedTerrain;
            TerrainBrush brush = m_terrainEditor.TerrainEditorControl.SelectedBrush;
            TerrainMap terrainMap = m_terrainEditor.TerrainEditorControl.SelectedTerrainMap;
            if (brush == null || (!brush.CanApplyTo(terrain) && !brush.CanApplyTo(terrainMap))) return;
            
            Vec2F drawscale = new Vec2F(1.0f,1.0f);
            if (brush.CanApplyTo(terrainMap))
            {
                ImageData mapImg = terrainMap.GetSurface();
                ImageData hmImg = terrain.GetSurface();
                drawscale.X = (float)hmImg.Width / (float)mapImg.Width;
                drawscale.Y = (float)hmImg.Height / (float)mapImg.Height;
            }

            Point scrPt = vc.PointToClient(Control.MousePosition);
            if (!vc.ClientRectangle.Contains(scrPt)) return;                       
            Ray3F rayw = vc.GetWorldRay(scrPt);            
            TerrainGob.RayPickRetVal retval;
            if (terrain.RayPick(rayw, out retval))
            {
                terrain.DrawBrush(brush, drawscale, retval.hitpos);
            }           
        }
Ejemplo n.º 2
0
        public bool Pick(ViewControl vc, Point scrPt) 
        {
            m_highlightMaterialGUID = ~0ul;
            m_highlight.Clear();

            var ray = vc.GetWorldRay(scrPt);
            var endPt = ray.Origin + vc.Camera.FarZ * ray.Direction;

            var nativeVC = vc as GUILayer.IViewContext;
            if (nativeVC == null) return false;

            // do an intersection test here, and find the material under the cursor
            var pick = XLEBridgeUtils.Picking.RayPick(
                nativeVC, ray, XLEBridgeUtils.Picking.Flags.Objects);

            if (pick != null && pick.Length > 0)
            {
                m_highlightMaterialGUID = pick[0].materialGuid;
                m_highlight.Add(pick[0].documentId, pick[0].instanceId);

                using (var placements = nativeVC.SceneManager.GetPlacementsEditor())
                {
                    m_highlight.DoFixup(placements);
                }
            }

            return true;
        }
Ejemplo n.º 3
0
 public override void Render(ViewControl vc)
 {                                                
     Matrix4F normWorld = GetManipulatorMatrix();
     if (normWorld == null) return;
     float s;
     Util.CalcAxisLengths(vc.Camera, normWorld.Translation, out s);
     m_translatorControl.Render(normWorld, s);        
 }
Ejemplo n.º 4
0
 public virtual bool Pick(ViewControl vc, Point scrPt)
 {
     Matrix4F normWorld = GetManipulatorMatrix();
     if (normWorld == null) return false;
     HitRayV = vc.GetRay(scrPt, vc.Camera.ProjectionMatrix);            
     HitMatrix.Set(normWorld);            
     return true;
 }
Ejemplo n.º 5
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
                return false;

            Camera camera = vc.Camera;
            float rad;
            Util.CalcAxisLengths(camera, HitMatrix.Translation, out rad);
            float tolerance = rad / 10.0f;

            // compute ray in object space  space.
            Matrix4F vp = camera.ViewMatrix * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;            
            Ray3F rayL = vc.GetRay(scrPt, wvp);

            Plane3F xplane = new Plane3F(Vec3F.XAxis, Vec3F.ZeroVector);
            Plane3F yplane = new Plane3F(Vec3F.YAxis,Vec3F.ZeroVector);
            Plane3F zplane = new Plane3F(Vec3F.ZAxis,Vec3F.ZeroVector);

            Vec3F pt;
            float xdelta = float.MaxValue;            
            float ydelta = float.MaxValue;
            float zdelta = float.MaxValue;
            if(rayL.IntersectPlane(xplane,out pt))
            {
                xdelta = Math.Abs(pt.Length - rad); 
            }

            if (rayL.IntersectPlane(yplane, out pt))
            {
                ydelta = Math.Abs(pt.Length - rad);              
            }

            if (rayL.IntersectPlane(zplane, out pt))
            {
                zdelta = Math.Abs(pt.Length - rad);
            }

            if(xdelta < tolerance && xdelta < ydelta && xdelta < zdelta)
            {
                m_hitRegion = HitRegion.XAxis;                
            }
            else if(ydelta < tolerance && ydelta < zdelta)
            {
                m_hitRegion = HitRegion.YAxis;
            }
            else if(zdelta < tolerance)
            {
                m_hitRegion = HitRegion.ZAxis;
            }

            return m_hitRegion != HitRegion.None;
        }
Ejemplo n.º 6
0
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || !CanManipulate(m_node))
                return;

            Matrix4F proj = vc.Camera.ProjectionMatrix;
            // create ray in view space.
            Ray3F rayV = vc.GetRay(scrPt, proj);

            Vec3F translate = m_translatorControl.OnDragging(rayV);

            Vec3F localTranslation;
            m_worldToLocal.TransformVector(translate, out localTranslation);
            m_node.Pivot = m_originalPivot + localTranslation;
        }
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
                return false;

            m_node = GetManipulatorNode(TransformationTypes.Pivot);

            Camera camera = vc.Camera;            
            Matrix4F view = camera.ViewMatrix;
            Matrix4F vp = view * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;

            Ray3F rayL = vc.GetRay(scrPt, wvp);
            m_hitRegion = m_translatorControl.Pick(vc, HitMatrix, view, rayL, HitRayV);
            bool picked = m_hitRegion != HitRegion.None;
            return picked;
        }
Ejemplo n.º 8
0
        public override void Render(object opaqueContext, ViewControl vc)
        {                                                
            Matrix4F normWorld = GetManipulatorMatrix();
            if (normWorld == null) return;

            var context = opaqueContext as GUILayer.SimpleRenderingContext;
            if (context == null) return;

            Vec3F pos = normWorld.Translation;
            float s = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height);

            bool highlight = m_hitRegion == HitRegion.XYSquare;
            Color centerCubeColor = highlight ? Color.Gold : Color.White;

            Vec3F sv = new Vec3F(s, s, s);
            Vec3F centerCubeScale = sv * CenterCubeSize;
            Matrix4F scale = new Matrix4F(); 
            scale.Scale(centerCubeScale);
            Matrix4F centerCubeXform = scale * normWorld;
            Util3D.DrawCube(context, centerCubeXform, centerCubeColor);

            Matrix4F arrowScale = new Matrix4F();
            arrowScale.Scale(0.75f);

            Util3D.DrawArrowCap(
                context,
                arrowScale * Matrix4F.CreateTranslation(new Vec3F(1.0f, 0.0f, -0.5f)) * centerCubeXform,
                highlight ? Color.Gold : Color.Red);

            Util3D.DrawArrowCap(
                context,
                arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, Math.PI) * Matrix4F.CreateTranslation(new Vec3F(-1.0f, 0.0f, -0.5f)) * centerCubeXform,
                highlight ? Color.Gold : Color.Red);

            Util3D.DrawArrowCap(
                context,
                arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, .5 * Math.PI) * Matrix4F.CreateTranslation(new Vec3F(0.0f, 1.0f, -0.5f)) * centerCubeXform,
                highlight ? Color.Gold : Color.Green);

            Util3D.DrawArrowCap(
                context,
                arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, 1.5f * Math.PI) * Matrix4F.CreateTranslation(new Vec3F(0.0f, -1.0f, -0.5f)) * centerCubeXform,
                highlight ? Color.Gold : Color.Green);
        }
Ejemplo n.º 9
0
        public void OnEndDrag(ViewControl vc, Point scrPt) 
        {
            var ray = vc.GetWorldRay(scrPt);
            var endPt = ray.Origin + vc.Camera.FarZ * ray.Direction;

            // do an intersection test here, and find the material under the cursor
            var pick = XLEBridgeUtils.Picking.RayPick(
                vc as GUILayer.IViewContext, ray, XLEBridgeUtils.Picking.Flags.Objects);

            if (pick != null && pick.Length > 0)
            {
                Context.PreviewModelName = pick[0].modelName;
                Context.PreviewModelBinding = pick[0].materialGuid; 
                Context.MaterialName = pick[0].materialName;
            }

            m_highlightMaterialGUID = ~0ul;
            m_highlight.Clear();
        }
Ejemplo n.º 10
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
                return false;

            Camera camera = vc.Camera;
            float s;
            Util.CalcAxisLengths(camera, HitMatrix.Translation, out s);
            Matrix4F view = camera.ViewMatrix;
            Matrix4F vp = view  * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;
            
            Ray3F rayL = vc.GetRay(scrPt,wvp);

            m_hitRegion = m_translatorControl.Pick(HitMatrix, view, rayL, HitRayV, s);
            
            bool picked = m_hitRegion != HitRegion.None;                      
            return picked;
        }
Ejemplo n.º 11
0
 bool IManipulator.Pick(ViewControl vc, System.Drawing.Point scrPt)
 {            
     TerrainGob terrain = m_terrainEditor.TerrainEditorControl.SelectedTerrain;
     TerrainBrush brush = m_terrainEditor.TerrainEditorControl.SelectedBrush;
     if (terrain != null && brush != null)
     {
         FlattenBrush fbrush = brush as FlattenBrush;                
         if (fbrush != null)
         {
             Ray3F rayw = vc.GetWorldRay(scrPt);
             TerrainGob.RayPickRetVal retval;
             if (terrain.RayPick(rayw, out retval))
             {
                 Point pt = terrain.WorldToSurfaceSpace(retval.hitpos);
                 ImageData hm = terrain.GetSurface();
                 fbrush.Height = hm.GetPixelFloat(pt.X, pt.Y);                        
             }
         }
         return true;
     }            
     return false;
 }
        public override void Render(ViewControl vc)
        {
            Matrix4F normWorld = GetManipulatorMatrix();
            if (normWorld == null) return;

            Camera camera = vc.Camera;
            float s;
            Util.CalcAxisLengths(camera, normWorld.Translation, out s);
            m_translatorControl.Render(normWorld, s);        
            
            Matrix4F sc = new Matrix4F();
            Vec3F pos = normWorld.Translation;            
            s /= 12.0f;
            sc.Scale(s);

            Matrix4F bl = new Matrix4F();
            Util.CreateBillboard(bl, pos, camera.WorldEye, camera.Up, camera.LookAt);

            Matrix4F recXform = new Matrix4F();
            Matrix4F.Multiply(sc, bl, recXform);

            Util3D.DrawPivot(recXform, Color.Yellow);
        }
Ejemplo n.º 13
0
        public override void OnEndDrag(ViewControl vc, Point scrPt)
        {
            if (CanManipulate(m_node))
            {
                var transactionContext = DesignView.Context.As<ITransactionContext>();
                try
                {
                    if (transactionContext.InTransaction)
                        transactionContext.End();
                }
                catch (InvalidTransactionException ex)
                {
                    if (transactionContext.InTransaction)
                        transactionContext.Cancel();

                    if (ex.ReportError)
                        Outputs.WriteLine(OutputMessageType.Error, ex.Message);
                }
            }

            m_hitRegion = HitRegion.None;
            m_node = null;
        }
Ejemplo n.º 14
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
                return false;

            Camera camera = vc.Camera;
            
            Matrix4F view = camera.ViewMatrix;
            Matrix4F vp = view  * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;
            
            Ray3F rayL = vc.GetRay(scrPt,wvp);

            float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height);

                // There's only one hot-spot for this manipulator:
                //      a square at the manipulator origin.
            Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f);
            Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f);
            AABB box = new AABB(min, max);

            float centerCubeScale = s * CenterCubeSize;
            Matrix4F centerCubeXform = new Matrix4F();
            centerCubeXform.Scale(centerCubeScale);
            centerCubeXform.Invert(centerCubeXform);
            Ray3F ray = rayL;
            ray.Transform(centerCubeXform);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.XYSquare;
                return true;
            }

            m_hitRegion = HitRegion.None;
            return false;
        }
Ejemplo n.º 15
0
 public override void OnEndDrag(ViewControl vc, Point scrPt)
 {
     if (m_activeOp != null)
     {
         m_activeOp.FinishTransaction();
         m_activeOp = null;
     }
     m_hitRegion = HitRegion.None;                        
     m_rotations = null;
 }
Ejemplo n.º 16
0
 public override void OnMouseWheel(ViewControl vc, Point scrPt, int delta) { }
Ejemplo n.º 17
0
        public override void Render(object opaqueContext, ViewControl vc)
        {                                                                           
            Matrix4F normWorld = GetManipulatorMatrix();
            if (normWorld == null) return;

            var context = opaqueContext as GUILayer.SimpleRenderingContext;
            if (context == null) return;

            float RingDiameter = 2 * AxisLength;
            Color xcolor = (m_hitRegion == HitRegion.XAxis) ? Color.Gold : XAxisColor;
            Color ycolor = (m_hitRegion == HitRegion.YAxis ) ? Color.Gold : YAxisColor;
            Color Zcolor = (m_hitRegion == HitRegion.ZAxis ) ? Color.Gold : ZAxisColor;
            Color lColor = (m_hitRegion == HitRegion.LookAxis) ? Color.Gold : Color.Cyan;

            float s = Util.CalcAxisScale(vc.Camera, normWorld.Translation, RingDiameter, vc.Height);
            Vec3F axScale = new Vec3F(s, s, s);

            Matrix4F rot = new Matrix4F();
            Matrix4F scale = new Matrix4F();
            scale.Scale(axScale);
            rot.RotX(MathHelper.PiOver2);            
            Matrix4F xform = scale * rot * normWorld;
            Util3D.DrawRing(context, xform, Zcolor);

            rot.RotZ(-MathHelper.PiOver2);
            xform = scale * rot * normWorld;
            Util3D.DrawRing(context, xform, xcolor);
            
            xform = scale * normWorld;
            Util3D.DrawRing(context, xform, ycolor);

            Matrix4F billboard
                = Util.CreateBillboard(normWorld.Translation, vc.Camera.WorldEye, vc.Camera.Up, vc.Camera.LookAt);
            rot.RotX(MathHelper.PiOver2);
            scale.Scale(s * LookRingScale);
            xform = scale * rot * billboard;
            Util3D.DrawRing(context, xform, lColor);
        }
Ejemplo n.º 18
0
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || m_activeOp == null || m_activeOp.NodeList.Count == 0)
                return;
            Camera cam = vc.Camera;

            Matrix4F view = cam.ViewMatrix;
            Matrix4F proj = cam.ProjectionMatrix;

            Matrix4F axisMtrx = HitMatrix * view;
            Ray3F hitRay = HitRayV;
            Ray3F dragRay = vc.GetRay(scrPt, proj);
            
            Vec3F xAxis = axisMtrx.XAxis;
            Vec3F yAxis = axisMtrx.YAxis;
            Vec3F zAxis = axisMtrx.ZAxis;
            Vec3F origin = axisMtrx.Translation;
            
            Vec3F rotAxis = new Vec3F();            
            float theta = 0;

            float snapAngle = ((ISnapSettings)DesignView).SnapAngle;
            switch (m_hitRegion)
            {                
                case HitRegion.XAxis:
                    {
                        Plane3F xplane = new Plane3F(xAxis, origin);
                        theta = CalcAngle(origin, xplane, hitRay, dragRay, snapAngle);
                        rotAxis = HitMatrix.XAxis;                        
                    }
                    break;
                case HitRegion.YAxis:
                    {
                        Plane3F yplane = new Plane3F(yAxis, origin);
                        theta = CalcAngle(origin, yplane, hitRay, dragRay, snapAngle);
                        rotAxis = HitMatrix.YAxis;                        
                    }
                    break;
                case HitRegion.ZAxis:
                    {
                        Plane3F zplane = new Plane3F(zAxis, origin);
                        theta = CalcAngle(origin, zplane, hitRay, dragRay, snapAngle);
                        rotAxis = HitMatrix.ZAxis;
                    }
                    break;
                case HitRegion.LookAxis:
                    {                        
                        // for billboard objects the look vector is object's negative position in viewspace.
                        Vec3F lookAxis = Vec3F.Normalize(-origin);
                        Plane3F plane = new Plane3F(lookAxis, origin);
                        theta = CalcAngle(origin, plane, hitRay, dragRay, snapAngle);                        
                        rotAxis = m_lookAxisHitMtrx.ZAxis;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            AngleAxisF axf = new AngleAxisF(-theta, rotAxis);
            Matrix4F deltaMtrx = new Matrix4F(axf);                                   
            Matrix4F rotMtrx = new Matrix4F();

            for (int i = 0; i < m_activeOp.NodeList.Count; i++)
            {
                ITransformable node = m_activeOp.NodeList[i];                              
                rotMtrx.Mul(m_rotations[i], deltaMtrx);                
                float ax, ay, az;
                rotMtrx.GetEulerAngles(out ax, out ay, out az);                                
                node.Rotation = new Vec3F(ax, ay, az);      
            }
        }
Ejemplo n.º 19
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
                return false;

            Camera camera = vc.Camera;
            float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height);

            Matrix4F vp = camera.ViewMatrix * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;

            // get ray in object space  space.
            Ray3F rayL = vc.GetRay(scrPt, wvp);

            m_scale = new Vec3F(1, 1, 1);
            m_hitScale = s;

            Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f);
            Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f);
            AABB box = new AABB(min, max);
            Matrix4F boxScale = new Matrix4F();
            Matrix4F boxTrans = new Matrix4F();
            Matrix4F BoxMtrx = new Matrix4F();

            float handleScale = s * AxisHandle;

            // +X axis
            boxScale.Scale(new Vec3F(s, handleScale, handleScale));
            boxTrans.Translation = new Vec3F(s / 2, 0, 0);
            BoxMtrx = boxScale * boxTrans;

            Ray3F ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);

            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.XAxis;
                return true;
            }

            // -X
            boxTrans.Translation = new Vec3F(-s / 2, 0, 0);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);

            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.NegXAxis;
                return true;
            }

            // y axis
            boxScale.Scale(new Vec3F(handleScale, s, handleScale));
            boxTrans.Translation = new Vec3F(0, s / 2, 0);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.YAxis;
                return true;
            }

            // -Y
            boxTrans.Translation = new Vec3F(0, -s / 2, 0);
            BoxMtrx = boxScale * boxTrans;
            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.NegYAxis;
                return true;
            }

            // z axis
            boxScale.Scale(new Vec3F(handleScale, handleScale, s));
            boxTrans.Translation = new Vec3F(0, 0, s / 2);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.ZAxis;
                return true;
            }

            // -Z
            boxTrans.Translation = new Vec3F(0, 0, -s / 2);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.NegZAxis;
                return true;
            }

            return false;
        }
Ejemplo n.º 20
0
        public override void Render(ViewControl vc)
        {
            Matrix4F normWorld = GetManipulatorMatrix();
            if (normWorld == null) return;

            int axis = (int)m_hitRegion;

            // axis colors
            Color saveColor = m_axisColor[axis];
            m_axisColor[axis] = m_highlightColor;
            Color xcolor  = m_axisColor[(int)HitRegion.XAxis];
            Color ycolor  = m_axisColor[(int)HitRegion.YAxis];
            Color zcolor  = m_axisColor[(int)HitRegion.ZAxis];
            Color nxcolor = m_axisColor[(int)HitRegion.NegXAxis];
            Color nycolor = m_axisColor[(int)HitRegion.NegYAxis];
            Color nzcolor = m_axisColor[(int)HitRegion.NegZAxis];
            m_axisColor[axis] = saveColor;

            if (m_hitRegion != HitRegion.None)
            {
                normWorld.Translation = HitMatrix.Translation;
            }

            Vec3F pos = normWorld.Translation;
            float s = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height);

            Vec3F sv = new Vec3F(s, s, s);
            Vec3F axscale = new Vec3F(s*AxisThickness, s, s*AxisThickness);
            bool negativeAxis = m_hitRegion == HitRegion.NegXAxis || m_hitRegion == HitRegion.NegYAxis || m_hitRegion == HitRegion.NegZAxis;
            Vec3F dragScale = new Vec3F(Math.Abs(m_scale.X),
                Math.Abs(m_scale.Y), Math.Abs(m_scale.Z));

            Matrix4F rot = new Matrix4F();
            Matrix4F scale = new Matrix4F();
            axscale.Y = negativeAxis ? s : s * dragScale.X;
            scale.Scale(axscale);
            rot.RotZ(-MathHelper.PiOver2);
            Matrix4F xform = scale * rot * normWorld;
            Util3D.DrawCylinder(xform, xcolor);

            axscale.Y = negativeAxis ? s : s * dragScale.Y;
            scale.Scale(axscale);
            xform = scale * normWorld;
            Util3D.DrawCylinder(xform, ycolor);

            axscale.Y = negativeAxis ? s : s * dragScale.Z;
            scale.Scale(axscale);
            rot.RotX(MathHelper.PiOver2);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(xform, zcolor);

            rot.RotZ(MathHelper.PiOver2);
            axscale.Y = negativeAxis ? s * dragScale.X : s;
            scale.Scale(axscale);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(xform, nxcolor);

            rot.RotZ(MathHelper.Pi);
            axscale.Y = negativeAxis ? s * dragScale.Y : s;
            scale.Scale(axscale);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(xform, nycolor);

            rot.RotX(-MathHelper.PiOver2);
            axscale.Y = negativeAxis ? s * dragScale.Z : s;
            scale.Scale(axscale);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(xform, nzcolor);

            // draw center cube
            scale.Scale(s*(1.0f / 16.0f));
            xform = scale * normWorld;
            Util3D.DrawCube(xform, Color.White);

            Vec3F handle = sv*AxisHandle;
            float handleWidth = handle.X/2;
            scale.Scale(handle);
            Matrix4F trans = new Matrix4F();

            // X handle
            float drag = m_hitRegion == HitRegion.XAxis ? dragScale.X : 1.0f;
            trans.Translation = new Vec3F(drag * sv.X - handleWidth, 0, 0);
            xform = scale * trans * normWorld;
            Util3D.DrawCube(xform, xcolor);

            // y handle
            drag = m_hitRegion == HitRegion.YAxis ? dragScale.Y : 1.0f;
            trans.Translation = new Vec3F(0, drag * sv.Y - handleWidth, 0);
            xform = scale * trans * normWorld;
            Util3D.DrawCube(xform, ycolor);

            // z handle
            drag = m_hitRegion == HitRegion.ZAxis ? dragScale.Z : 1.0f;
            trans.Translation = new Vec3F(0, 0, drag * sv.Z - handleWidth);
            xform = scale * trans * normWorld;
            Util3D.DrawCube(xform, zcolor);

            // -x handle
            drag = m_hitRegion == HitRegion.NegXAxis ? dragScale.X : 1.0f;
            trans.Translation = new Vec3F(-sv.X * drag + handleWidth, 0, 0);
            xform = scale * trans * normWorld;
            Util3D.DrawCube(xform, nxcolor);

            // -y handle
            drag = m_hitRegion == HitRegion.NegYAxis ? dragScale.Y : 1.0f;
            trans.Translation = new Vec3F(0, -sv.Y * drag + handleWidth, 0);
            xform = scale * trans * normWorld;
            Util3D.DrawCube(xform, nycolor);

            // -z handle
            drag = m_hitRegion == HitRegion.NegZAxis ? dragScale.Z : 1.0f;
            trans.Translation = new Vec3F(0, 0, -sv.Z * drag + handleWidth);
            xform = scale * trans * normWorld;
            Util3D.DrawCube(xform, nzcolor);
        }
Ejemplo n.º 21
0
 public void OnMouseWheel(LevelEditorCore.ViewControl vc, Point scrPt, int delta)
 {
 }
Ejemplo n.º 22
0
        public void Render(object opaqueContext, ViewControl vc)
        {
            if (m_hasHoverPt)
            {
                var context = opaqueContext as GUILayer.SimpleRenderingContext;
                if (context == null) return;

                GUILayer.RenderingUtil.RenderCylinderHighlight(
                    context, XLEBridgeUtils.Utils.AsVector3(m_hoverPt), ManipulatorContext.Radius);
            }
        }
Ejemplo n.º 23
0
        public void OnDragging(ViewControl vc, Point scrPt)
        {
            m_hasHoverPt = HitTest(out m_hoverPt, scrPt, vc);
            if (!m_hasHoverPt) return;

            var nativeVC = vc as GUILayer.IViewContext;
            if (nativeVC == null) return;

            var game = vc.As<DesignViewControl>().DesignView.Context.As<IGame>();
            if (game == null) return;

            if (ManipulatorContext.Objects.Count == 0) return;

            GUILayer.EditorInterfaceUtils.ScatterPlaceOperation op;

            var sceneManager = nativeVC.SceneManager;
            using (var editor = sceneManager.GetPlacementsEditor())
            {
                using (var scene = sceneManager.GetIntersectionScene())
                {
                    op = GUILayer.EditorInterfaceUtils.CalculateScatterOperation(
                        editor, scene,
                        ManipulatorContext.Objects.Select(C => C.Model),
                        XLEBridgeUtils.Utils.AsVector3(m_hoverPt),
                        ManipulatorContext.Radius, ManipulatorContext.Density);
                }
            }

            foreach (var d in op._toBeDeleted)
            {
                var adapter = m_nativeIdMapping.GetAdapter(d.Item1, d.Item2).As<DomNodeAdapter>();
                if (adapter != null)
                {
                    adapter.DomNode.RemoveFromParent();
                }
            }

            var resourceResolvers = Globals.MEFContainer.GetExportedValues<IResourceResolver>();
            var resourceConverter = Globals.MEFContainer.GetExportedValue<ResourceConverterService>();

            foreach (var s in op._creationPositions)
            {
                // select a random entry from the list of objects
                var o = ManipulatorContext.SelectRandomObject(m_rng);

                IResource resource = null;
                foreach (var d in resourceResolvers)
                {
                    resource = d.Resolve(new Uri(
                        new Uri(System.Environment.CurrentDirectory + "\\"),
                        o.Model + "<model"));
                    if (resource != null) break;
                }

                if (resource != null)
                {
                    var resGob = resourceConverter.Convert(resource);
                    if (resGob != null)
                    {
                        resGob.As<DomNode>().InitializeExtensions();

                        var hierarchical = game.AsAll<IHierarchical>();
                        foreach (var h in hierarchical)
                            if (h.AddChild(resGob)) break;

                        var transform = resGob.As<LevelEditorCore.ITransformable>();
                        transform.Translation = XLEBridgeUtils.Utils.AsVec3F(s);
                        transform.Rotation = new Sce.Atf.VectorMath.Vec3F(0.0f, 0.0f, (float)(m_rng.NextDouble()) * 2.0f * 3.14159f);

                            // set the material name (if we can)
                        var p = resGob.As<Placements.XLEPlacementObject>();
                        if (p != null)
                        {
                            p.Material = o.Material;
                            p.Supplements = o.Supplements;
                        }
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
                return false;

            Camera camera = vc.Camera;
            float RingDiameter = 2 * AxisLength;
            float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, RingDiameter, vc.Height);

            float rad = s * Util3D.RingCenterRadias;
            float lrad = rad * LookRingScale;
            float tolerance = s * Util3D.RingThickness;
            
            Matrix4F billboard
                = Util.CreateBillboard(HitMatrix.Translation, vc.Camera.WorldEye, vc.Camera.Up, vc.Camera.LookAt);
            m_lookAxisHitMtrx = billboard;
            // compute ray in object space  space.
            Matrix4F vp = camera.ViewMatrix * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;            
            Ray3F rayL = vc.GetRay(scrPt, wvp);

            Matrix4F wvp2 = billboard * vp;
            Ray3F rayL2 = vc.GetRay(scrPt, wvp2);

            Plane3F xplane = new Plane3F(Vec3F.XAxis, Vec3F.ZeroVector);
            Plane3F yplane = new Plane3F(Vec3F.YAxis,Vec3F.ZeroVector);
            Plane3F zplane = new Plane3F(Vec3F.ZAxis, Vec3F.ZeroVector);
            

            Vec3F pt;
            float xdelta    = float.MaxValue;            
            float ydelta    = float.MaxValue;
            float zdelta    = float.MaxValue;
            float lookdelta = float.MaxValue;
            if(rayL.IntersectPlane(xplane,out pt))
            {
                xdelta = Math.Abs(pt.Length - rad); 
            }

            if (rayL.IntersectPlane(yplane, out pt))
            {
                ydelta = Math.Abs(pt.Length - rad);              
            }

            if (rayL.IntersectPlane(zplane, out pt))
            {
                zdelta = Math.Abs(pt.Length - rad);
            }

            if (rayL2.IntersectPlane(zplane, out pt))
            {
                lookdelta = Math.Abs(pt.Length - lrad);
            }

            if(xdelta < tolerance && xdelta < ydelta && xdelta < zdelta
                && xdelta < lookdelta)
            {
                m_hitRegion = HitRegion.XAxis;                
            }
            else if(ydelta < tolerance && ydelta < zdelta
                && ydelta < lookdelta)
            {
                m_hitRegion = HitRegion.YAxis;
            }
            else if(zdelta < tolerance && zdelta < lookdelta)
            {
                m_hitRegion = HitRegion.ZAxis;
            }
            else if (lookdelta < tolerance)
            {
                m_hitRegion = HitRegion.LookAxis;
            }

            return m_hitRegion != HitRegion.None;
        }
Ejemplo n.º 25
0
        public override void OnEndDrag(ViewControl vc, Point scrPt)
        {
            if (NodeList.Count > 0)
            {
                for (int k = 0; k < NodeList.Count; k++)
                {
                    IManipulatorNotify notifier = NodeList[k].As<IManipulatorNotify>();
                    if (notifier != null) notifier.OnEndDrag();
                }

                var transactionContext = DesignView.Context.As<ITransactionContext>();
                try
                {
                    if (transactionContext.InTransaction)
                        transactionContext.End();
                }
                catch (InvalidTransactionException ex)
                {
                    if (transactionContext.InTransaction)
                        transactionContext.Cancel();

                    if (ex.ReportError)
                        Outputs.WriteLine(OutputMessageType.Error, ex.Message);
                }
            }
            m_hitRegion = HitRegion.None;                        
            NodeList.Clear();            
            m_rotations = null;
        }
Ejemplo n.º 26
0
 public bool Pick(ViewControl vc, Point scrPt)
 {
     m_hasHoverPt = HitTest(out m_hoverPt, scrPt, vc);
     return m_hasHoverPt;
 }
Ejemplo n.º 27
0
        public override void Render(ViewControl vc)
        {                                                                           
            Matrix4F normWorld = GetManipulatorMatrix();
            if (normWorld == null) return;

            Util3D.RenderFlag = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest;
            Color xcolor = (m_hitRegion == HitRegion.XAxis ) ? Color.LightSalmon : Color.Red;
            Color ycolor = (m_hitRegion == HitRegion.YAxis ) ? Color.LightGreen : Color.Green;
            Color Zcolor = (m_hitRegion == HitRegion.ZAxis ) ? Color.LightBlue : Color.Blue;

            float s;
            Util.CalcAxisLengths(vc.Camera, normWorld.Translation, out s);
            Vec3F axScale = new Vec3F(s, s, s);

            Matrix4F scale = new Matrix4F();
            scale.Scale(axScale);
            Matrix4F xform = scale*normWorld;
            Util3D.DrawCircle(xform, Zcolor);

            Matrix4F rot = new Matrix4F();
            rot.RotY(MathHelper.PiOver2);
            xform = scale * rot * normWorld;
            Util3D.DrawCircle(xform, xcolor);

            rot.RotX(MathHelper.PiOver2);
            xform = scale * rot * normWorld;
            Util3D.DrawCircle(xform,ycolor);

        }
Ejemplo n.º 28
0
 public void OnEndDrag(ViewControl vc, Point scrPt) {}
Ejemplo n.º 29
0
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || m_activeOp == null || m_activeOp.NodeList.Count == 0)
                return;

            Matrix4F view = vc.Camera.ViewMatrix;
            // compute world * view
            Matrix4F wv = new Matrix4F();
            wv.Mul(HitMatrix, view);

            // create ray in view space.
            Ray3F rayV = vc.GetRay(scrPt, vc.Camera.ProjectionMatrix);

            Vec3F xAxis = wv.XAxis;
            Vec3F yAxis = wv.YAxis;
            Vec3F zAxis = wv.ZAxis;
            Vec3F origin = wv.Translation;

            m_scale = new Vec3F(1, 1, 1);
            float scale = 1;
            float a1, a2;

            switch (m_hitRegion)
            {
                case HitRegion.XAxis:
                case HitRegion.NegXAxis:
                    {
                        a1 = Math.Abs(Vec3F.Dot(HitRayV.Direction, yAxis));
                        a2 = Math.Abs(Vec3F.Dot(HitRayV.Direction, zAxis));
                        Vec3F axis = (a1 > a2 ? yAxis : zAxis);
                        Vec3F p0 = HitRayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                        Vec3F p1 = rayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                        float dragAmount = Vec3F.Dot((p1 - p0), xAxis);
                        if (m_hitRegion == HitRegion.NegXAxis)
                        {
                            dragAmount *= -1;
                        }
                        m_scale.X = 1.0f + dragAmount / m_hitScale;
                        scale = m_scale.X;

                    }

                    break;
                case HitRegion.YAxis:
                case HitRegion.NegYAxis:
                    {
                        a1 = Math.Abs(Vec3F.Dot(HitRayV.Direction, zAxis));
                        a2 = Math.Abs(Vec3F.Dot(HitRayV.Direction, xAxis));
                        Vec3F axis = (a1 > a2 ? zAxis : xAxis);
                        Vec3F p0 = HitRayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                        Vec3F p1 = rayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                        float dragAmount = Vec3F.Dot((p1 - p0), yAxis);
                        if (m_hitRegion == HitRegion.NegYAxis)
                        {
                            dragAmount *= -1;
                        }
                        m_scale.Y = 1.0f + dragAmount / m_hitScale;
                        scale = m_scale.Y;

                    }
                    break;
                case HitRegion.ZAxis:
                case HitRegion.NegZAxis:
                    {
                        a1 = Math.Abs(Vec3F.Dot(HitRayV.Direction, xAxis));
                        a2 = Math.Abs(Vec3F.Dot(HitRayV.Direction, yAxis));
                        Vec3F axis = (a1 > a2 ? xAxis : yAxis);
                        Vec3F p0 = HitRayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                        Vec3F p1 = rayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                        float dragAmount = Vec3F.Dot((p1 - p0), zAxis);
                        if (m_hitRegion == HitRegion.NegZAxis)
                        {
                            dragAmount *= -1;
                        }
                        m_scale.Z = 1.0f + dragAmount / m_hitScale;
                        scale = m_scale.Z;

                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }

            if(m_isUniformScaling)
                m_scale = new Vec3F(scale,scale,scale);

            // scale
            for (int i = 0; i < m_activeOp.NodeList.Count; i++)
            {
                ITransformable node = m_activeOp.NodeList[i];
                node.Scale = Vec3F.Mul(m_originalScales[i], m_scale);

                Matrix4F mtrx = TransformUtils.CalcTransform(
                   Vec3F.ZeroVector,
                   node.Rotation,
                   node.Scale,
                    m_pivotOffset[i]);
                node.Translation = m_originalTranslations[i] + mtrx.Translation;

            }
        }
Ejemplo n.º 30
0
        private bool HitTest(out Vec3F result, Point pt, ViewControl vc)
        {
            var ray = vc.GetWorldRay(pt);
            var pick = XLEBridgeUtils.Picking.RayPick(
                vc as GUILayer.IViewContext, ray, XLEBridgeUtils.Picking.Flags.Terrain);

            if (pick != null && pick.Length > 0)
            {
                result = pick[0].hitPt;
                return true;
            }

            result = new Vec3F(0.0f, 0.0f, 0.0f);
            return false;
        }
Ejemplo n.º 31
0
        public override void OnEndDrag(ViewControl vc, Point scrPt)
        {
            if (m_activeOp != null)
            {
                m_activeOp.FinishTransaction();
                m_activeOp = null;
            }

            m_originalScales = null;
            m_originalTranslations = null;
            m_hitRegion = HitRegion.None;
            m_scale = new Vec3F(1, 1, 1);
        }