Archived

This topic is now archived and is closed to further replies.

mouse selection

This topic is 5893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Something wrong goes on here. I''m trying to select 3d objects in a 3d world using the mouse. What I''m doing wrong. I have base plane XOZ D=0 NORM=[0,1,0]. I have camera pos CAM [XC,YC,ZC] I have camera LookAT[XL,YL,ZL] I have near cliping plane at NEAR and field of view FOV. I have aspect ratio ASPECT (WIDTH/HEIGHT). I calculate xy position of the mouse click on screen VMOUSE VMOUSE.x = TANG(FOV/2)*ASPECT; VMOUSE.y = TANG(FOV/2); VMOUSE.z = NEAR; Now I have tha ray Origin=CAM Direction = AT + VMOUSE. float dist = DotProd(NORM, CAM) + D; //D=0 if(dist !=0) //front back intersection { float dp = DotProduct(vNormal, Direction); VECTINTERSETCION = ((Direction * dist) / dp); } What''s wrong. Thanks.

Share this post


Link to post
Share on other sites
Why not use the BackBuffer? draw every object in a diffrent color, get back the pixel at mouse position and look what object it was.. simple and pixel accurate.. :o)

cya,
Phil


Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

Share this post


Link to post
Share on other sites
I dont want to select objects. I want to find the specific point of intersection beween eye, mouse pointer and whatever polygon.
Is easy if I have the mouse pointer in the middle of screen because there is a camera at vector, and then I build a ray
vector3 rayorigin = camera eye position
vector3 raydirection = cameraeyapos - cameralookat;
vector3 pointofintersection = plane.rayintersect(rayorigin,raydirection);
But if I''m rotating the raydirection by atang(dXmouse/near), (dYmouse/near), the y rotation is ok, but the x rotation happends around new y (already rotated). So the new ray direction is a wrong one (on my case)
Thanks.

Share this post


Link to post
Share on other sites
The wrong thing about your calculation is (as I see it) that you write Direction = AT + VMOUSE. This is not correct, why should you add VMOUSE? Normally you would do it this way:
Direction = INVTRANSFORMATION * VMOUSE
where INVTRANSFORMATION is the inverse of your transformation matrix (possibly multiplied with your projection matrix). So you simply do the inverse projection and transformation on VMOUSE. There is a good example shipping with DX8 SDK called "Pick". But you should also find examples somewhere else if you search "pick object".

Share this post


Link to post
Share on other sites