Terrain Editor Mouse Position Problem

Blitz3D Forums/Blitz3D Programming/Terrain Editor Mouse Position Problem

FBEpyon(Posted 2004) [#1]
Hello,

Im trying to get my mouse to position on the terrain right..

Im making a map editor for a MMORPG a freind and I are working on and I need help getting the mouse(cursor) to move along the terrain including height...

<quote>

mx = MouseX()
my = MouseY()
mz = MouseZ()

mouse_y = TerrainY(terrain,mx,my,mz)+2

PositionEntity cursor,mx*x_scale,mouse_y*y_scale,mz*z_scale

</quote>

this is all I have so far, but still no mouse following the terrain...

If you could help, thank you..


SabataRH(Posted 2004) [#2]
MouseZ() is not a 3d location.. its the position the mouse scroll wheel is turned to. Also mx and my in your equation is 2d screen coordinates, not 3d world space so the call to the terrainY is completely wrong.

You'll need to check into CameraProject and CameraPick's to accomplish this task.


Matty(Posted 2004) [#3]
To get a simple mouse cursor to be able to click on the terrain I would suggest
the following method:


Load your object you wish to use as the mouse cursor. Make it the child of the
camera. Position it at the camera's position then move it in the Z direction a distance
equal to the Screen Width divided by 2. Like this:

ie
Camera=createcamera()
Mouse3d=loadmesh("MouseMesh.b3d",Camera)
moveentity Mouse3d,0,0,Screen Width / 2
entityorder Mouse3d,-1

then in your main loop

Moveentity Mouse3d,MouseXSpeed(),-MouseYSpeed(),0

(I cannot remember if the function's name is MouseSpeedX() or MouseXSpeed() but whichever one it is use that)

You will need to use the pick commands to cause the mouse to interact with the
terrain.


FBEpyon(Posted 2004) [#4]
Coolness thanks

Im almost done with the terrain part of my editor now..


FBEpyon(Posted 2004) [#5]
Hmm that code didn't work :(


Bot Builder(Posted 2004) [#6]
Um, That would only work if you don't move the camera. try this:

(assuming terrain is the handle of your terrain)
;In the start of the program ,after creating the terrain:
EntityPickMode terrain,2

;In your editer's loop, do this to find the coordinates on the terrain the mouse is at:
CameraPick camera,MouseX(),MouseY()	;Assuming camera is your camera's handle
If PickedEntity()=terrain Then  
 x#=PickedX#()
 y#=PickedY#()
 z#=PickedZ#()
EndIf



FBEpyon(Posted 2004) [#7]
well neither of these two codes worked :(

Im lost now...


Matty(Posted 2004) [#8]
Try this as a basic program. You will need to supply
your own terrain height map (32x32) and your own grass
texture.

<code>
Graphics3D 800,600


camera=CreateCamera()
terrain=LoadTerrain("map.bmp")
grasstex=LoadTexture("grass.bmp")
EntityTexture terrain,grasstex
ScaleTexture grasstex,6,6
ScaleEntity terrain,8,10,6
mouse3d=CreateSphere(8,camera)
ScaleEntity mouse3d,10,10,10
PositionEntity mouse3d,EntityX(camera,True),EntityY(camera,True),EntityZ(camera,True)
EntityOrder mouse3d,-1
MoveEntity mouse3d,0,0,400
MoveMouse 400,300
MX=MouseX()
MY=MouseY()
TotalMX=0
TotalMY=0
PositionEntity camera,120,60,80

Repeat

simplecameramovement(camera)
MX=MouseXSpeed()
MY=MouseYSpeed()
MoveEntity mouse3d,MX,-MY,0
UpdateWorld
RenderWorld
Flip

Until KeyDown(1)
End
Function simpleCameraMovement(camera)
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
If KeyDown(200) Then MoveEntity camera,0,0,1
If KeyDown(208) Then MoveEntity camera,0,0,-1
If KeyDown(30) Then MoveEntity camera,0,1,0
If KeyDown(44) Then MoveEntity camera,0,-1,0
End Function
</code>

It works well on my PC and the mouse can be moved around
the screen regardless of the camera's motion.


FBEpyon(Posted 2004) [#9]
cool it worked, but its not excately what I was looking for.. I want it to follow the terrain...


Matty(Posted 2004) [#10]
Do you wish the mouse to be able to select points on the terrain or do you wish the mouse cursor to kind of act like a ball which rolls over the terrain in the direction the mouse moves..


FBEpyon(Posted 2004) [#11]
want it to select

sorry it took so long to reply, bad week :(

okay little more detail about the editor.. its for a MMORPG, but I want to create the full world off of one program loading like 9 terrain areas at once this way I can edit them and align them correctly, then I want to save all the information into a world file like (*.rwf) then load it into the game but having the game do the samething by loadin about 9 sections at a time this way Im not using up as much memory, but the game looks fluid.. so right now Im starting with the Terrain part and once thats done I will make it where I can add entities and other information to the map..

if you may have anyother information you can provide for please drop me a email fbepyon@... or the same at MSN IM using the same email :P thanks