Coolzero
06-04-2010 13:01:43
Can some please tell me how i get a Vector3 while i'm moving my mouse over terrain ?
At the moment i'm using this:
Shared Function MouseMovedListener(ByVal e As MOIS.MouseEvent) As Boolean
Dim mouseRay As Ray = myCamera.GetCameraToViewportRay(myMouse.MouseState.X.abs, myMouse.MouseState.Y.abs)
Console.WriteLine(mouseRay.GetPoint(0))
...
When i move the mouse in the middle of the terrain (see picture), then mouseRay.GetPoint() gives me very high values (see console):
[attachment=0]vector3.jpg[/attachment]
Ray.GetPoint(t as Single)
What does the t is standing for ?
Sweenie
07-04-2010 11:43:00
the t in GetPoint stands for how many units along the ray direction from the ray origin you want to get the point in world space.
For example, GetPoint(1000) will get the point in worldspace 1000 units away from the ray origin along the ray direction.
If I remember correctly GetCameraToViewportRay wants normalised screen coordinates.
That is, float values between 0 and 1.
If the mouse x-position is 400 and the screen width is 800 the x-value passed should be 0.5
So in short, divide the mouse x-position with the screen width and the mouse y-position with the screen height.
Coolzero
07-04-2010 18:12:04
thanks for your reply,
the t in GetPoint stands for how many units along the ray direction from the ray origin you want to get the point in world space.
For example, GetPoint(1000) will get the point in worldspace 1000 units away from the ray origin along the ray direction.
Ok, thanks for the description.
That means the t in GetPoint must be the Camera.Position.y value if the point in world space is x, 0, y right ?
All i wanna do is to select an object by mouse (is working).
When i move the mouse, the selected object must also moving (here's my problem
![Rolling Eyes :roll:]({SMILIES_PATH}/icon_rolleyes.gif)
).
The terrain is an simple plane (moveable object) with gras material. It's located at the middle of the world space (0, 0, 0).
On this terrain the selected object must slide over when the mouse is moving. I tryed this code:
Dim mouseRay As Ray = myCamera.GetCameraToViewportRay(myMouse.MouseState.X.abs / MyWindow.Width, myMouse.MouseState.Y.abs / MyWindow.Height)
Dim myRaySceneQuery As RaySceneQuery = myScene.CreateRayQuery(mouseRay)
myRaySceneQuery.QueryMask = QueryFlags.TERRAIN_MASK
Dim results As RaySceneQueryResult = myRaySceneQuery.Execute
For Each result As RaySceneQueryResultEntry In results
If result.movable.Name = "Raster" Then
selObject.Position = mouseRay.GetPoint(myCamera.Position.y)
End If
Next
So far so good, the selected object is moving and centered at the cursor but in the whole 3d space:
You see the shadow and the bottom of the building ? How can i say mogre to use only the x and z cords ?
[attachment=0]img1.jpg[/attachment]
Sweenie
08-04-2010 08:42:57
I assume you want the point there the ray intersect the terrain?
Then try this...
If result.movable.Name = "Raster" Then
selObject.Position = mouseRay.GetPoint(result.distance)
End If
If "Raster" is the name of your terrainobject that is.
Coolzero
08-04-2010 14:58:34
![Very Happy :D]({SMILIES_PATH}/icon_biggrin.gif)
... IT WORKS IT WORKS IT WORKS ...
Thanks Sweenie