Jump to content

Terrain Grid Points

Paul Thomas

Recommended Posts

Just experimenting and I'm trying to get the terrain grid points from a mouse click/position. Not sure how to go about it yet, just started messing around, and starting to try cameraproject but I don't think that's going to work out. Anyone have any ideas?


where are you trying to do this? in a program or the editor?


for a lua program, this gives me the position of a pick for any entity class including terrain:

if pick~=nil then


it should also work for bmax as well

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Almost. I'll probably have it completed here in just a few, and I'll post up an example. Wanted to mess with terrain editing while "in-game" and it's going well, just have to finalize some of the math. Grid x=0, y=0 works fine, except that I have the y backwards, same with Grid x=128, y=128 (on a 128x128 terrain). Grid x=0, y=128 and Grid x=128, y=0, I have backwards, lol. So click 0, 128 raises the terrain over at 128, 0.

Link to comment
Share on other sites

Now that I'm done feeling stupid, here it is, after I realized no math was really required.


Gather terrain resolution from your sandbox scene or use createterrain.


local pick:tpick
local grid:tvec3
local height:float
local terrain:tterrain

if mousehit(1)
 pick = camerapick(camera, vec3(mousex(), mousey(), 1000.0), 0, 0)
   if pick <> null and tterrain(pick.entity)
     terrain = tterrain(pick.entity)
     grid = pick.position

     grid.x = grid.x + ((-terrainResolution / 2) + terrainResolution)
     grid.z = grid.z + ((-terrainResolution / 2) + terrainResolution)

     height = terrainheight(terrain, grid.z, grid.x)
     setterrainheight(terrain, grid.z, grid.x, height + 0.001)


That will edit the terrain while playing around with your program.






For BlitzMax

Link to comment
Share on other sites

Yeah, going to start experimenting with TerrainElevation instead, since using TerrainElevation was the only way to make my radius tool work correctly (drawn based on terrain height). I have a fairly smooth terrain editor so far, but I still have to work on providing radius (inner and outer). My calculations at the moment are way off.

Link to comment
Share on other sites

lol. I'd like to mimic most of the 2.28 sandbox and then continue to build it to be more targeted for my project. Yes, I'm reinventing the wheel, but I can't build upon the LE sandbox. Project targeted features such as changing the time of day, visual cloud layer manipulation, eventually weather, and so forth.


If the original LE sandbox was a module or available for purchase, that would be fantastic, but at the moment I'll have to work on this enough to fit my projects needs.

Link to comment
Share on other sites

Lol E.C.


It would be cool if we could add new toolbar, UI, etc. functionality to the 2.3 Editor via scripts.


Similar to how the InitGrid works per-entity, but more so on a game/editor level.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)


IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15


csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer



Link to comment
Share on other sites

For the actual red radius that follows the terrain?




In loop somewhere:

pick = camerapick(camera, vec3(mousex(), mousey(), 1000.0), 0, 0)
 if pick <> null and tterrain(pick.entity)
   createradiusmesh(tterrain(pick.entity), pick.position.x, pick.position.y, pick.position.z)


The above could be simplified, it was final code after testing purposes, but never polished up.


function createradiusmesh(terrain:tterrain, x:float, y:float, z:float)
   if radiusmesh freeentity(radiusmesh)
 radiusmesh = createmesh()
 entitycolor(radiusmesh, vec4(1.0, 0.0, 0.0, 1.0))
 radiussurface = createsurface(radiusmesh)

   for local i:int = 1 to 360
     local px:float = x + cos(i) * radius
     local pz:float = z + sin(i) * radius
     local h:float = terrainelevation(terrain, pz, px)
     addvertex(radiussurface, vec3(px, h, pz))

 radiussurface.mode = GL_LINE_LOOP
 entityshadowmode(radiusmesh, false)


Again, can be polished up, and you need a tmesh/tsurface for the above. I'm not really sure how to do this with the current C# headers, have to still try the header out, just haven't had the time.


Code above was also rewritten for this forum instead of copy and pasted, so there could be mistakes but it looks correct.


And thanks :blink:

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...