strange DirectInput coordonates

Munku

05-02-2007 07:58:21

Hello, before I begin let me say that I have been using Mogre for a couple of days and I love it!

Anyways, on-topic:

I have DirectInput set up properly (as per numerous examples on the net), however, when I gather the mouse coordinates from the DI object, they are HUGE float values.

My question is simple: how do I convert the values into something that Mogre can use (specifically for Raycasting and picking).

Bekas

05-02-2007 11:19:23

See this mouse picking example.

Munku

05-02-2007 16:49:03

I have set a tank mesh in the middle of the screen, and when I click on it...the raycaster only registers a hit on the scene, not the tank. Any ideas?

Bekas

05-02-2007 18:18:25

the raycaster only registers a hit on the scene, not the tank.
With "scene" you mean a bigger mesh which contains the tank ?
AFAIK if the bounding box of an entity is inside another one, it won't get hit. I think you need polygon-level picking; Ogre Studio uses MogreNewt for polygon-level picking, you may want to check it out.

Munku

06-02-2007 17:37:18

No, the mesh is not in the "scene". As a scene, I am using a 3ds terrain-like scene as a tester before porting over to an actual terrain. The scene is below the tank.

[Update]

I tried to check the mousepicking without the scene, and I still could not pick the tank.

Here is the code for the tanks init, plain and simple:


Entity tank = smgr.CreateEntity("tank", "tank.mesh");
//tank.NormaliseNormals = true;

SceneNode node = smgr.RootSceneNode.CreateChildSceneNode("stuff",map.BoundingBox.Center);


And the raycasting (picking, whatever) code is:


public void middleClick(int mx,int my)
{
RaySceneQuery rsq;

float mX = (float)mRoot.AutoCreatedWindow.GetViewport(0).ActualWidth/mx ;
float mY = (float)mRoot.AutoCreatedWindow.GetViewport(0).ActualHeight/my;


Ray mray = cam.GetCameraToViewportRay(mX,mY);

rsq = smgr.CreateRayQuery(mray);
rsq.SetSortByDistance(true);
RaySceneQueryResult rresult = rsq.Execute();



OverlayElement gHit = OverlayManager.Singleton.GetOverlayElement("odebug/hit");
if (rresult.Count > 0)
{
gHit.Caption = "Scene Object Hit ("+rresult.Count+")";
}
else
{
gHit.Caption = "";
}


foreach (RaySceneQueryResultEntry entry in rresult)
{
Console.WriteLine("Entity Name: " + entry.movable.Name);
if (!entry.movable.Name.Equals("testmap"))
{
entry.movable.Visible = false;
}
}

//mRoot.AutoCreatedWindow.
smgr.DestroyQuery(rsq);
}




Any thoughts?

--Thanks in advance!

pjcast

06-02-2007 18:38:24

Not sure about your issue. Though, in regards to the first post, Directinput provides you mouse values in a very raw format. Hence, the extremely high values that do not corelate to the OS mouse or window positions. Use .Net methods to determine the position of the mouse when a click action happens. Though, maybe you already discovered that. Besides that, you can look at Ogre Studio's picking code for how to pick correctly with .Net + Mogre + Ogre (you should be able to ignore the Mogrenewt code there).

marc_antoine

09-02-2007 18:49:59

this is due to relative and absolute coordinates used by directX, i personally have tried to use directX to do a rayscenequery but i got to this problematic.

i ended using windows forms events or AXIOM for mouse and keyboard input :)

perhaps you can change between relative and absolute coordites the coordinates won't work as expected in a windowed application (since the coordinates are based in the screen resolution so the 0,0 doesn't match with the 0,0 in the applicattion, so you will have based in the position of the window in the screen the translated 0,0) i haven't tried in a fullscreen app.

if you got it to work please let us know.

pjcast

10-02-2007 20:00:34

Actually, it doesn't depand at all on screen resolution. Using Directinput for mouse accesses hardware values directly. And, the only reason you don't see it in relative motion, is because relative motion events are in the form of movement from last position to new position. It will also not respect the scren coordinates, and will also not repsect the users preference in the mouse control panel. .Net form input events however, will :D

marc_antoine

11-02-2007 03:41:11

that's true pjcast if you use mouse input for moving a camera since you just need the amount of movement (that's why in the tutorials you hve to substract: old position-new position= distance, which then is converted to an angle), but if you use that amount of movement in a rayscenequery you will get nothing but the floor in the best case (since you can miss hitting the biggest mesh in the scene hehehe), that's why you have to change to absolute coordinates, which you can in directinput, but it doesn't works the way expected since it does depends on the screen resolution becouse Using Directinput for mouse accesses hardware values directly

so the (0,0) is not in your windowed app it is in your screen if you debug the values you will see what i mean.


i have some links thay may help clearout this idea
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=138280&SiteID=1
http://gpwiki.org/index.php/DirectX:DirectInput:Tutorials:VB:DX7:Mouse_Handling
http://msdn2.microsoft.com/en-us/library/bb174605.aspx


also i had made tests getting the abolsute mouse position moving the mouse to till i get x=0 and y=0 and it is not in the window form, that's why i either use the window mouse and keyboard events or AXIOM

BTW i'm developing some sort of drivers to get data from VR input systems like trackers nd gloves, if anyone has done something similar specially for the CyberGlove let me know..