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; } }
public Point WorldToSurfaceSpace(Vec3F posW) { Point result = new Point(); TerrainGob terrain = this.GetParentAs <TerrainGob>(); ImageData hmImg = terrain.GetSurface(); ImageData mpImg = GetSurface(); Point posH = terrain.WorldToSurfaceSpace(posW); float dx = (float)mpImg.Width / (float)hmImg.Width; float dy = (float)mpImg.Height / (float)hmImg.Height; result.X = (int)Math.Round(posH.X * dx); result.Y = (int)Math.Round(posH.Y * dy); return(result); }
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); }