Mouse-Click (2d to 3d transmission)

Started by
9 comments, last by J-Fox 16 years, 4 months ago
I think the title is clear enough but I'm not sure that here is the right forum.. I'm using directx 9.0c and using WINAPI. Any help would be appreciated :) ps:And there are balls on the game field I want to know if the balls are clicked or the terrain.
Advertisement
Your title is awfully vague, but I think you might be looking for D3DXVec3Unproject()
Quote:Original post by SiCrane
Your title is awfully vague, but I think you might be looking for D3DXVec3Unproject()


oh sorry i tought it was clear enough but;
i have a game field and balls on it.i want to select a ball by clicking on it and move it somewhere else by clicking on the terrain..
I'll look if D3DXVec3Unproject() helps, thanks.
Quote:Original post by Eralp
Quote:Original post by SiCrane
Your title is awfully vague, but I think you might be looking for D3DXVec3Unproject()


oh sorry i tought it was clear enough but;
i have a game field and balls on it.i want to select a ball by clicking on it and move it somewhere else by clicking on the terrain..
I'll look if D3DXVec3Unproject() helps, thanks.


What you want to do, it's called picking. Check the DirectX SDK, there is a sample about picking there.

I hope that helps ;)

[Edited by - idloco on December 25, 2007 12:55:05 AM]
------------------------------------ IDLoco Game Studios
thanks mate I found it but I have a new problem (actually not a problem but a question)

I check if my "ray" hits the "targetmesh" but I draw ie 10 copies of targetmesh how can I understand which is hit? Do I need to make a mesh array,which will use much memory?

Here is my function if needed;

 void Intersect(float cursorx,float cursory,HWND hWnd) {		D3DVIEWPORT9 ViewPort;	d3ddev->GetViewport(&ViewPort);   D3DXMATRIXA16 World;  D3DXMatrixIdentity(&World);		D3DXVECTOR3 Start	= D3DXVECTOR3(cursorx, cursory, 0.0f);	D3DXVECTOR3 End		= D3DXVECTOR3(cursorx, cursory, 1.0f);	D3DXVECTOR3 Direction;	D3DXVec3Unproject(&Start, &Start, &ViewPort, &matProjection, &matView, &World);	D3DXVec3Unproject(&End, &End, &ViewPort, &matProjection, &matView, &World);			Direction = End - Start;	D3DXVec3Normalize(&Direction, &Direction);        BOOL Hit = FALSE; DWORD Face = 0, Count = 0;	D3DXIntersect(targetmesh, &Start, &Direction, &Hit, &Face, NULL, NULL, NULL, NULL, &Count);	if(Hit)	{                 //which is hit ?  	}}
Oh noooo!This function doesnt works when I change the position of my mesh. It treats like the mesh is in the middle and when i click the middle it works but doesnt matter where I drawed the mesh..
I think its because the world variable, it isnt the same as in the render_frame() function.. (cuz I create it again in my intersect function)
But it doesnt work when I write D3DTS_WORLD in the intersect function it gives me errors.

I'm new to c++ and directx so can you help me about this
http://www.mvps.org/directx/articles/improved_ray_picking.htm

However, if you are new to DirectX you might want to look at something easier first ;)
Quote:Original post by J-Fox
http://www.mvps.org/directx/articles/improved_ray_picking.htm

However, if you are new to DirectX you might want to look at something easier first ;)


I already downloaded it and understood NOTHING, because there were many included long files which makes no sense to me.. ( I need only one function :) )

--I'll try to do it myself by reading the other things on the web otherwise it will be "forum-pollution" or whatever you call it =)

Just "move" the ray into "objectspace" (for eatch object you want to test), be4 doing the D3DXIntersect.

  D3DXMatrixInverse( invMatrix, null, ObjectWorldMatrix );  rayOrigin = D3DVec3TransformCoord(rayOrigin, invMatrix );  rayDir    = D3DVec3TransformCoord(rayDir, invMatrix );  rayDir    = DirectionVector(rayDir, rayOrigin );
Quote:Original post by Mythar
Just "move" the ray into "objectspace"


Exactly thats the idea I've been looking for, thanks !

Quote:Original post by Mythar
  D3DXMatrixInverse( invMatrix, null, ObjectWorldMatrix );  rayOrigin = D3DVec3TransformCoord(rayOrigin, invMatrix );  rayDir    = D3DVec3TransformCoord(rayDir, invMatrix );  rayDir    = DirectionVector(rayDir, rayOrigin );



But can someone explain me what all these things are(cuz I cant import it in my function w/o knowing what they are) ? if I can finish this picking thing I will finish my application too(I can handle the rest) and I've been searhing it for 3 days :(
I'm waiting on you :)

This topic is closed to new replies.

Advertisement