void LoadHeightMap(string sm3directory, TdfParser.Section terrainsection) { string filename = Path.Combine(sm3directory, terrainsection.GetStringValue("heightmap")); double heightoffset = terrainsection.GetDoubleValue("heightoffset"); double heightscale = terrainsection.GetDoubleValue("heightscale"); LogFile.GetInstance().WriteLine("heightoffset: " + heightoffset + " heightscale " + heightscale); Terrain.GetInstance().MinHeight = heightoffset; Terrain.GetInstance().MaxHeight = heightoffset + heightscale; // I guess??? Image image = new Image(filename); //Bitmap bitmap = DevIL.DevIL.LoadBitmap(filename); int width = image.Width; int height = image.Height; Terrain.GetInstance().HeightMapWidth = width; Terrain.GetInstance().HeightMapHeight = height; Terrain.GetInstance().Map = new double[width, height]; LogFile.GetInstance().WriteLine("loaded bitmap " + width + " x " + height); double minheight = Terrain.GetInstance().MinHeight; double maxheight = Terrain.GetInstance().MaxHeight; double heightmultiplier = (maxheight - minheight) / 255; LogFile.GetInstance().WriteLine("heightmultiplier: " + heightmultiplier + " minheight: " + minheight); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Terrain.GetInstance().Map[i, j] = (float)(minheight + heightmultiplier * image.GetBlue(i, j)); } } terrain.HeightmapFilename = filename; }
void on_btnok_clicked(object o, EventArgs e) { try { double minimumheight = Convert.ToDouble(minimumheightentry.Text); double maximumheight = Convert.ToDouble(maximumheightentry.Text); if (minimumheight >= maximumheight) { DialogHelpers.ShowErrorMessage(heightscaledialog, "Maximum height should be greater than minimum height"); return; } bool Scale = radioScale.Active; //CmdHeightScaleChange.Operation operation = CmdHeightScaleChange.Operation.Scale; //if (clip) //{ //operation = CmdHeightScaleChange.Operation.Clip; //} //Console.WriteLine(operation); //heightscaledialog.Hide(); Terrain.GetInstance().ChangeHeightScale(minimumheight, maximumheight, Scale); heightscaledialog.Destroy(); } //catch( Exception ex ) catch { //Console.WriteLine(ex); DialogHelpers.ShowErrorMessage(heightscaledialog, "Maximum height should be greater than minimum height"); return; } }
List <MapTextureStage> LoadTextureStages(string sm3directory, TdfParser.Section terrainsection) { int numstages = terrainsection.GetIntValue("numtexturestages"); List <MapTextureStage> stages = new List <MapTextureStage>(); for (int i = 0; i < numstages; i++) { TdfParser.Section texstagesection = terrainsection.SubSection("texstage" + i); string texturename = texstagesection.GetStringValue("source"); string blendertexturename = texstagesection.GetStringValue("blender"); string operation = texstagesection.GetStringValue("operation").ToLower(); int tilesize; ITexture texture = LoadTexture(sm3directory, terrainsection, texturename, out tilesize); if (operation == "blend") { ITexture blendtexture = LoadTextureAsAlpha(sm3directory, terrainsection, blendertexturename); stages.Add(new MapTextureStage(MapTextureStage.OperationType.Blend, tilesize, texture, blendtexture)); } else // todo: add other operations { stages.Add(new MapTextureStage(MapTextureStage.OperationType.Replace, tilesize, texture)); } } Terrain.GetInstance().texturestages = stages; return(stages); }
public static PluginsLoader GetInstance() { instance.LoadAssemblyPlugins(); Config.GetInstance(); Terrain.GetInstance(); HeightMapPersistence.GetInstance(); SlopeMapPersistence.GetInstance(); MouseFilterSdlMouseCache.GetInstance(); KeyFilterSdlKeyCache.GetInstance(); KeyFilterConfigMappingsFactory.GetInstance(); //HeightEditor.GetInstance(); EditController.GetInstance(); Camera.GetInstance(); Framerate.GetInstance(); FrustrumCulling.GetInstance(); BrushShapeController.GetInstance().Register(new RoundBrush()); BrushShapeController.GetInstance().Register(new SquareBrush()); BrushEffectController.GetInstance().Register(new RaiseLower()); BrushEffectController.GetInstance().Register(new Flatten()); BrushEffectController.GetInstance().Register(new PaintTexture()); BrushEffectController.GetInstance().Register(new AddFeature()); BrushEffectController.GetInstance().Register(new FixedHeight()); //Sm3Persistence.GetInstance().LoadSm3("maps/Whakamatunga_Riri.sm3"); //EditTexture.GetInstance(); //FeatureEditing.GetInstance(); MainUI.GetInstance(); return(instance); }
void renderableminimap_Render(int minimapleft, int minimaptop, int minimapwidth, int minimapheight) { //Console.WriteLine("renderableminimap_Render"); Vector3 intersectpoint = EditingHelper.GetIntersectPoint(); if (intersectpoint != null) { Vector2 minimappos = new Vector2(intersectpoint.x * minimapwidth / Terrain.GetInstance().MapWidth / Terrain.SquareSize, intersectpoint.y * minimapheight / Terrain.GetInstance().MapHeight / Terrain.SquareSize); //Console.WriteLine("minmappos: " + minimappos); //double distancefromcamera = (intersectpoint - camerapos).Det(); GraphicsHelperFactory.GetInstance().SetMaterialColor(new Color(0, 0, 1)); Gl.glPushMatrix(); Gl.glDisable(Gl.GL_LIGHTING); Gl.glDisable(Gl.GL_CULL_FACE); Gl.glColor3ub(0, 0, 255); Gl.glBegin(Gl.GL_POINTS); Gl.glVertex2d(minimapleft + minimappos.x, minimaptop + minimappos.y); Gl.glEnd(); Gl.glEnable(Gl.GL_CULL_FACE); Gl.glEnable(Gl.GL_LIGHTING); Gl.glColor3ub(255, 255, 255); //Gl.glTranslated(intersectpoint.x, intersectpoint.y, intersectpoint.z); //Gl.glScaled(0.01 * distancefromcamera, 0.01 * distancefromcamera, 0.01 * distancefromcamera); //GraphicsHelperFactory.GetInstance().DrawSphere(); Gl.glPopMatrix(); } }
public void Load(string filename) { //Bitmap bitmap = Bitmap.FromFile(filename) as Bitmap; //Bitmap bitmap = DevIL.DevIL.LoadBitmap(filename); Image image = new Image(filename); int width = image.Width; int height = image.Height; Terrain.GetInstance().HeightMapWidth = width; Terrain.GetInstance().HeightMapHeight = height; Terrain.GetInstance().Map = new double[width, height]; LogFile.GetInstance().WriteLine("loaded bitmap " + width + " x " + height); double minheight = Config.GetInstance().minheight; double maxheight = Config.GetInstance().maxheight; double heightmultiplier = (maxheight - minheight) / 255; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Terrain.GetInstance().Map[i, j] = (float)(minheight + heightmultiplier * image.GetBlue(i, j)); } } Terrain.GetInstance().HeightmapFilename = filename; Terrain.GetInstance().OnTerrainModified(); MainUI.GetInstance().uiwindow.InfoMessage("Heightmap loaded"); }
void GetDimensions() { Terrain terrain = Terrain.GetInstance(); windowwidth = RendererFactory.GetInstance().InnerWindowWidth; windowheight = RendererFactory.GetInstance().InnerWindowHeight; mapwidth = terrain.MapWidth; mapheight = terrain.MapHeight; double mapheightwidthratio = terrain.MapHeight / terrain.MapWidth; minimapwidth = 0; minimapheight = 0; if (mapheightwidthratio > 1) { minimapheight = minimapsize; minimapwidth = (int)(minimapsize / mapheightwidthratio); } else { minimapwidth = minimapsize; minimapheight = (int)(minimapsize * mapheightwidthratio); } }
public HeightScaleDialog() { Glade.XML app = new Glade.XML("./MapDesigner.glade", "heightscaledialog", ""); app.Autoconnect(this); minimumheightentry.Text = Terrain.GetInstance().MinHeight.ToString(); maximumheightentry.Text = Terrain.GetInstance().MaxHeight.ToString(); }
public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double milliseconds) { Terrain terrain = Terrain.GetInstance(); double[,] mesh = terrain.Map; int x = (int)(brushcentre_x / Terrain.SquareSize); int y = (int)(brushcentre_y / Terrain.SquareSize); double timemultiplier = milliseconds * speed; int meshsize = mesh.GetUpperBound(0) + 1; for (int i = -brushsize; i <= brushsize; i++) { for (int j = -brushsize; j <= brushsize; j++) { int thisx = x + i; int thisy = y + j; if (thisx >= 0 && thisy >= 0 && thisx < meshsize && thisy < meshsize) { double brushshapecontribution = brushshape.GetStrength((double)i / brushsize, (double)j / brushsize); if (brushshapecontribution > 0) { mesh[thisx, thisy] = mesh[thisx, thisy] + (mesh[x, y] - mesh[thisx, thisy]) * brushshapecontribution * timemultiplier / 50; } } } } terrain.OnHeightMapInPlaceEdited(x - brushsize, y - brushsize, x + brushsize, y + brushsize); }
public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double milliseconds) { if (currentfeature == null) { return; } int x = (int)(brushcentre_x / Terrain.SquareSize); int y = (int)(brushcentre_y / Terrain.SquareSize); if (israising) { if (Terrain.GetInstance().FeatureMap[x, y] == null) { Terrain.GetInstance().FeatureMap[x, y] = currentfeature; LogFile.GetInstance().WriteLine("feature " + currentfeature.texturename1 + " added to " + x + " " + y); Terrain.GetInstance().OnFeatureAdded(currentfeature, x, y); } } else { if (Terrain.GetInstance().FeatureMap[x, y] != null) { Unit oldunit = Terrain.GetInstance().FeatureMap[x, y]; Terrain.GetInstance().FeatureMap[x, y] = null; Terrain.GetInstance().OnFeatureRemoved(oldunit, x, y); } } }
public MainUIWindow() { Glade.XML app = new Glade.XML("./MapDesigner.glade", "mainwindow", ""); app.Autoconnect(this); //raiselower.Activate(); Terrain.GetInstance().TerrainModified += new Terrain.TerrainModifiedHandler(MainUIWindow_TerrainModified); //MainUIWindow_TerrainModified(); }
void Init() { int width = (Terrain.GetInstance().HeightMapWidth - 1) / 64; int height = (Terrain.GetInstance().HeightMapHeight - 1) / 64; widthentry.Entry.Text = width.ToString(); heightentry.Entry.Text = height.ToString(); }
void on_btnAddStage_clicked(object o, EventArgs e) { //MapTextureStage maptexturestage = GetSelectedMapTextureStage(); //if (maptexturestage != null) //{ Terrain.GetInstance().texturestages.Add(new MapTextureStage(MapTextureStage.OperationType.Blend)); terrain.OnTerrainModified(); //} }
void on_save_sm3_activate(object o, EventArgs e) { if (Terrain.GetInstance().Sm3Filename == "") { on_save_sm3_as1_activate(o, e); return; } Sm3Persistence.GetInstance().SaveSm3(Terrain.GetInstance().Sm3Filename); }
void NewHeightMap(int heightmapwidth, int heightmapheight) { Terrain terrain = Terrain.GetInstance(); terrain.HeightMapWidth = heightmapwidth; terrain.HeightMapHeight = heightmapheight; terrain.Map = new double[terrain.HeightMapWidth, terrain.HeightMapHeight]; terrain.HeightmapFilename = ""; terrain.OnTerrainModified(); }
public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds) { if (thistexture != null && maptexturestage != null) { double timemultiplier = milliseconds * speed; double directionmultiplier = 1.0; if (!israising) { directionmultiplier = -1.0; } int mapx = (int)(brushcentrex / Terrain.SquareSize); int mapy = (int)(brushcentrey / Terrain.SquareSize); int mapwidth = Terrain.GetInstance().HeightMapWidth - 1; int mapheight = Terrain.GetInstance().HeightMapHeight - 1; int texturex = (int)(texturewidth * mapx / mapwidth); int texturey = (int)(textureheight * mapy / mapheight); int texturebrushwidth = (int)(texturewidth * brushsize / mapwidth); int texturebrushheight = (int)(textureheight * brushsize / mapheight); for (int i = -texturebrushwidth; i <= texturebrushwidth; i++) { for (int j = -texturebrushheight; j <= texturebrushheight; j++) { double brushshapecontribution = brushshape.GetStrength((double)i / texturebrushwidth, (double)j / texturebrushheight); if (brushshapecontribution > 0) { int thisx = texturex + i; int thisy = texturey + j; // Console.WriteLine(thisx + " " + thisy); if (thisx >= 0 && thisy >= 0 && thisx < texturewidth && thisy < textureheight) { // we update our double array then set the int array iwthin ITexture itself alphadata[thisx, thisy] += speed * directionmultiplier * timemultiplier * brushshapecontribution; if (alphadata[thisx, thisy] >= 255) { alphadata[thisx, thisy] = 255; } else if (alphadata[thisx, thisy] < 0) { alphadata[thisx, thisy] = 0; } thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy]; // Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]); } } } } thistexture.ReloadAlpha(); thistexture.Modified = true; Terrain.GetInstance().OnBlendMapInPlaceEdited(maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize); } }
void FixedHeight_TerrainModified() { minheight = Terrain.GetInstance().MinHeight; maxheight = Terrain.GetInstance().MaxHeight; if (heightscale != null) { heightscale.SetRange(minheight, maxheight); lastheight = Math.Min(maxheight, lastheight); lastheight = Math.Max(minheight, lastheight); } }
public void Save() { if (Terrain.GetInstance().HeightmapFilename != "") { Save(Terrain.GetInstance().HeightmapFilename); } else { Save(Config.GetInstance().defaultHeightMapFilename); } }
void on_btnHeightMapSave_clicked(object o, EventArgs e) { if (Terrain.GetInstance().HeightmapFilename != "") { HeightMapPersistence.GetInstance().Save(Terrain.GetInstance().HeightmapFilename); } else { on_btnHeightmapSaveAs_clicked(o, e); } }
public LodDialog() { Glade.XML app = new Glade.XML("./MapDesigner.glade", "levelofdetaildialog", ""); app.Autoconnect(this); int[] lod = Terrain.GetInstance().GetLod(); lod1.Value = lod[0]; //LogFile.GetInstance().WriteLine( lod[0] + " " + lod1.Value); lod2.Value = lod[1]; //LogFile.GetInstance().WriteLine(lod[1] + " " + lod2.Value); lod3.Value = lod[2]; //LogFile.GetInstance().WriteLine(lod[2] + " " + lod3.Value); lod4.Value = lod[3]; lod5.Value = lod[4]; lod6.Value = lod[5]; }
public void Render(Vector3 intersectpos) { double radius = CurrentEditBrush.GetInstance().BrushSize; double displayradius = radius * Terrain.SquareSize; Terrain terrain = Terrain.GetInstance(); int numsegments = 16; // list four corner of square, in order List <Vector2> corners = new List <Vector2>(); corners.Add(new Vector2(-1, -1)); corners.Add(new Vector2(-1, 1)); corners.Add(new Vector2(1, 1)); corners.Add(new Vector2(1, -1)); Gl.glBegin(Gl.GL_LINE_LOOP); for (int i = 0; i < 4; i++) { Vector2 startcorner = corners[i]; Vector2 endcorner = corners[(i + 1) % 4]; double startx = intersectpos.x + startcorner.x * displayradius; double starty = intersectpos.y + startcorner.y * displayradius; startx = Math.Max(0, startx); startx = Math.Min(startx, terrain.MapWidth * Terrain.SquareSize); starty = Math.Max(0, starty); starty = Math.Min(starty, terrain.MapHeight * Terrain.SquareSize); double endx = intersectpos.x + endcorner.x * displayradius; double endy = intersectpos.y + endcorner.y * displayradius; endx = Math.Max(0, endx); endx = Math.Min(endx, terrain.MapWidth * Terrain.SquareSize); endy = Math.Max(0, endy); endy = Math.Min(endy, terrain.MapHeight * Terrain.SquareSize); for (int segment = 0; segment < numsegments; segment++) { double x = startx + (endx - startx) * segment / numsegments; double y = starty + (endy - starty) * segment / numsegments; double z = Terrain.GetInstance().Map[(int)(x / Terrain.SquareSize), (int)(y / Terrain.SquareSize)]; z = Math.Max(0.1, z); // make sure visible over sea Gl.glVertex3d(x, y, z); } } Gl.glEnd(); }
void on_btnRemoveStage_clicked(object o, EventArgs e) { if (terrain.texturestages.Count > 1) { MapTextureStage maptexturestage = GetSelectedMapTextureStage(); if (maptexturestage != null) { Terrain.GetInstance().texturestages.Remove(maptexturestage); terrain.OnTerrainModified(); } } else { InfoMessage("You need at least one texture stage for the map to run"); } }
void on_okbutton_clicked(object o, EventArgs e) { width = Convert.ToInt32(widthentry.Entry.Text); height = Convert.ToInt32(heightentry.Entry.Text); mapsizedialog.Destroy(); if (callback == null) { int mapwidth = width * 64; int mapheight = height * 64; Terrain.GetInstance().ChangeMapSize(mapwidth, mapheight, radioScale.Active); // CommandQueueFactory.FromUI.Enqueue(new CmdMapSizeChange(width, height)); } else { callback(this); } }
public void Go() { LogFile logfile = LogFile.GetInstance(); logfile.Init("logfile.txt"); LogFile.GetInstance().WriteLine("MapDesigner starting " + DateTime.Now.ToString()); Il.ilInit(); Ilu.iluInit(); Ilut.ilutInit(); Ilut.ilutRenderer(Ilut.ILUT_OPENGL); IRenderer renderer = RendererFactory.GetInstance(); renderer.Init(); PluginsLoader.GetInstance(); Terrain.GetInstance().NewMap(); renderer.StartMainLoop(); }
void ChangeLods() { int lod1value = (int)lod1.Value; int lod2value = (int)lod2.Value; int lod3value = (int)lod3.Value; int lod4value = (int)lod4.Value; int lod5value = (int)lod5.Value; int lod6value = (int)lod6.Value; List <int> lodlist = new List <int>(); lodlist.Add(lod1value); lodlist.Add(lod2value); lodlist.Add(lod3value); lodlist.Add(lod4value); lodlist.Add(lod5value); lodlist.Add(lod6value); Terrain.GetInstance().SetLod(lodlist.ToArray()); }
public void Render(Vector3 intersectpos) { double radius = CurrentEditBrush.GetInstance().BrushSize; int segments = 32; double anglestep = Math.PI * 2 / segments; Terrain terrain = Terrain.GetInstance(); double x, y, z; // outer radius double displayradius = radius * Terrain.SquareSize; Gl.glBegin(Gl.GL_LINE_LOOP); for (double angle = 0; angle < Math.PI * 2; angle += anglestep) { x = intersectpos.x + displayradius * Math.Sin(angle); y = intersectpos.y + displayradius * Math.Cos(angle); x = Math.Max(0, x); x = Math.Min(x, terrain.MapWidth * Terrain.SquareSize); y = Math.Max(0, y); y = Math.Min(y, terrain.MapHeight * Terrain.SquareSize); z = terrain.Map[(int)(x / Terrain.SquareSize), (int)(y / Terrain.SquareSize)]; z = Math.Max(0.1, z); // make sure visible over sea Gl.glVertex3d(x, y, z); } Gl.glEnd(); // core radius displayradius = coresizevalue / 100 * radius * Terrain.SquareSize; Gl.glBegin(Gl.GL_LINE_LOOP); for (double angle = 0; angle < Math.PI * 2; angle += anglestep) { x = intersectpos.x + displayradius * Math.Sin(angle); y = intersectpos.y + displayradius * Math.Cos(angle); x = Math.Max(0, x); x = Math.Min(x, terrain.MapWidth * Terrain.SquareSize); y = Math.Max(0, y); y = Math.Min(y, terrain.MapHeight * Terrain.SquareSize); z = terrain.Map[(int)(x / Terrain.SquareSize), (int)(y / Terrain.SquareSize)]; z = Math.Max(0.1, z); // make sure visible over sea Gl.glVertex3d(x, y, z); } Gl.glEnd(); }
public void Save(string filename) { double[,] mesh = Terrain.GetInstance().Map; int width = mesh.GetUpperBound(0) + 1; int height = mesh.GetUpperBound(1) + 1; Image image = new Image(width, height); //Bitmap bitmap = new Bitmap( width, height, PixelFormat.Format24bppRgb ); //Graphics g = Graphics.FromImage(bitmap); //Pen[] pens = new Pen[256]; //for (int i = 0; i < 256; i++) //{ // pens[i] = new Pen(System.Drawing.Color.FromArgb(i, i, i)); //} double minheight = Config.GetInstance().minheight; double maxheight = Config.GetInstance().maxheight; double heightmultiplier = 255 / (maxheight - minheight); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int normalizedmeshvalue = (int)((mesh[i, j] - minheight) * heightmultiplier); normalizedmeshvalue = Math.Max(0, normalizedmeshvalue); normalizedmeshvalue = Math.Min(255, normalizedmeshvalue); byte normalizedmeshvaluebyte = (byte)normalizedmeshvalue; image.SetPixel(i, j, normalizedmeshvaluebyte, normalizedmeshvaluebyte, normalizedmeshvaluebyte, 255); //g.DrawRectangle(pens[ normalizedmeshvalue ], i, j, 1, 1); } } if (File.Exists(filename)) { File.Delete(filename); } image.Save(filename); //DevIL.DevIL.SaveBitmap(filename, bitmap); //bitmap.Save(filename, ImageFormat.Bmp); Terrain.GetInstance().HeightmapFilename = filename; Terrain.GetInstance().OnTerrainModified(); MainUI.GetInstance().uiwindow.InfoMessage("Heightmap saved"); }
// ported from Spring's ReadMap.cpp by Hugh Perkins public double[,] GetSlopeMap() { Terrain terrain = Terrain.GetInstance(); double[,] mesh = terrain.Map; int mapwidth = terrain.HeightMapWidth - 1; int mapheight = terrain.HeightMapHeight - 1; slopemapwidth = mapwidth / 2; slopemapheight = mapheight / 2; //logfile.WriteLine( "Getting heightmap, this could take a while... " ); double[,] SlopeMap = new double[slopemapwidth, slopemapheight]; for (int y = 2; y < mapheight - 2; y += 2) { for (int x = 2; x < mapwidth - 2; x += 2) { Vector3 e1 = new Vector3(-squaresize * 4, mesh[x - 1, y - 1] - mesh[x + 3, y - 1], 0); Vector3 e2 = new Vector3(0, mesh[x - 1, y - 1] - mesh[x - 1, y + 3], -squaresize * 4); Vector3 n = Vector3.CrossProduct(e2, e1); n.Normalize(); e1 = new Vector3(squaresize * 4, mesh[x + 3, y + 3] - mesh[x - 1, y + 3], 0); e2 = new Vector3(0, mesh[x + 3, y + 3] - mesh[x + 3, y - 1], squaresize * 4); Vector3 n2 = Vector3.CrossProduct(e2, e1); n2.Normalize(); SlopeMap[x / 2, y / 2] = 1 - (n.y + n2.y) * 0.5; } } //logfile.WriteLine("... slopes calculated" ); return(SlopeMap); }
/// <summary> /// /// </summary> /// <param name="IsInitialMouseclick">When mouse button is initially pressed, this is true.</param> void ApplyBrush(bool IsInitialMouseclick) { if (!(increaseheight || decreaseheight)) { return; } if (CurrentEditBrush.GetInstance().BrushEffect == null || CurrentEditBrush.GetInstance().BrushShape == null) { return; } if (!(IsInitialMouseclick || CurrentEditBrush.GetInstance().BrushEffect.Repeat)) { return; } Vector3 intersectpoint = EditingHelper.GetIntersectPoint(); if (intersectpoint == null) { return; } double x = intersectpoint.x; double y = intersectpoint.y; if (x >= 0 && y >= 0 && x < (Terrain.GetInstance().HeightMapWidth *Terrain.SquareSize) && y < (Terrain.GetInstance().HeightMapHeight *Terrain.SquareSize)) { double milliseconds = DateTime.Now.Subtract(LastDateTime).TotalMilliseconds; LastDateTime = DateTime.Now; CurrentEditBrush.GetInstance().BrushEffect.ApplyBrush( CurrentEditBrush.GetInstance().BrushShape, CurrentEditBrush.GetInstance().BrushSize, x, y, increaseheight, milliseconds); } }
/// <summary> /// Return current mouse intersect point to x-y plane on map, in display coordinates /// </summary> /// <returns></returns> public static Vector3 GetIntersectPoint() { // intersect mousevector with x-z plane. Terrain terrain = Terrain.GetInstance(); Vector3 mousevector = GraphicsHelperFactory.GetInstance().GetMouseVector( Camera.GetInstance().RoamingCameraPos, Camera.GetInstance().RoamingCameraRot, MouseFilterMouseCacheFactory.GetInstance().MouseX, MouseFilterMouseCacheFactory.GetInstance().MouseY); Vector3 camerapos = Camera.GetInstance().RoamingCameraPos; int width = terrain.HeightMapWidth; int height = terrain.HeightMapHeight; //Vector3 planenormal = mvMath.ZAxis; mousevector.Normalize(); if (mousevector.z < -0.0005) { //Vector3 intersectionpoint = camerapos + mousevector * (Vector3.DotProduct(camerapos, planenormal) + 0) / // (Vector3.DotProduct(mousevector, planenormal)); Vector3 intersectpoint = camerapos - mousevector * (camerapos.z / mousevector.z); //Console.WriteLine("intersection: " + intersectionpoint.ToString()); double heightmapx = intersectpoint.x / Terrain.SquareSize; double heightmapy = intersectpoint.y / Terrain.SquareSize; if (heightmapx >= 0 && heightmapy >= 0 && heightmapx < width && heightmapy < height) { intersectpoint.z = Terrain.GetInstance().Map[(int)heightmapx, (int)heightmapy]; return intersectpoint; } else { return null; } } else { // Console.WriteLine("no intersection"); return null; } }