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);
            }           
        }
Example #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;
        }
Example #3
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();
        }
 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;
 }
Example #5
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;
        }
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || m_activeOp == null || m_activeOp.NodeList.Count == 0)
                return;

                // create ray in view space.
            Ray3F rayV = vc.GetWorldRay(scrPt);

            using (var intersectionScene = GameEngine.GetEditorSceneManager().GetIntersectionScene())
            {
                Vec3F intersectionPt;
                if (!CalculateTerrainIntersection(vc, rayV, intersectionScene, out intersectionPt))
                    return;

                if (m_pendingStartPt)
                {
                    m_startPt = intersectionPt;
                    m_pendingStartPt = false;
                }
                else
                {
                    bool clampToSurface = Control.ModifierKeys == Keys.Shift;
                    Vec3F translate = new Vec3F(intersectionPt.X - m_startPt.X, intersectionPt.Y - m_startPt.Y, 0.0f);
                    for (int i = 0; i < m_activeOp.NodeList.Count; i++)
                    {
                        ITransformable node = m_activeOp.NodeList[i];

                        Path<DomNode> path = new Path<DomNode>(Adapters.Cast<DomNode>(node).GetPath());
                        Matrix4F parentLocalToWorld = TransformUtils.CalcPathTransform(path, path.Count - 2);
                        Matrix4F parentWorldToLocal = new Matrix4F();
                        parentWorldToLocal.Invert(parentLocalToWorld);

                        Vec3F newWorldPos = m_originalTranslations[i] + translate;
                        float terrainHeight = 0.0f;
                        if (GUILayer.EditorInterfaceUtils.GetTerrainHeight(
                            out terrainHeight, intersectionScene, newWorldPos.X, newWorldPos.Y)) {

                            newWorldPos.Z = terrainHeight + (clampToSurface ? 0.0f : m_originalHeights[i]);
                            Vec3F localTranslation;
                            parentWorldToLocal.TransformVector(newWorldPos, out localTranslation);
                            node.Translation = localTranslation;
                        }
                    }
                }
            }
        }
        private void ApplyBrush(ViewControl vc, System.Drawing.Point scrPt)
        {
            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;

            Ray3F rayw = vc.GetWorldRay(scrPt);
            TerrainGob.RayPickRetVal retval;
            if (terrain.RayPick(rayw, out retval))
            {
                TerrainOp op = null;
                if (brush.CanApplyTo(terrain))
                {
                    Point pt = terrain.WorldToSurfaceSpace(retval.hitpos);
                    brush.Apply(terrain, pt.X, pt.Y, out op);
                }
                else if (brush.CanApplyTo(terrainMap))
                {
                    Point pt = terrainMap.WorldToSurfaceSpace(retval.hitpos);
                    brush.Apply(terrainMap, pt.X, pt.Y, out op);
                }
                m_tmpOps.Add(op);
                m_terrainOpList.Add(new WeakReference(op));
                m_memUsage += op.SizeInBytes;

            }
        }