Jump to content

  • Log In with Google      Sign In   
  • Create Account


Picking problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 MefistoManna   Members   -  Reputation: 139

Like
0Likes
Like

Posted 14 May 2012 - 12:14 PM

I am using this code:

bool IsPicked()
{
	BOOL pickedtmp;
		if(m_Input_->MouseButtonDown(0))
		{
			//getting location of mouse relative to game window, not whole screen
			POINT ptCursor;
			GetCursorPos( &ptCursor );
			ScreenToClient( hwnd, &ptCursor );
			//getting viewport (p_Device is LPDIRECT3DDEVICE9)
			D3DVIEWPORT9 view;
			m_D3D::GetDevice()->GetViewport( &view );
			//getting projection matrix
			D3DXMATRIX projMat;
			m_D3D::GetDevice()->GetTransform(D3DTS_PROJECTION,&projMat);
			//calculating.. mouse ray
			float vx = (+2.0f*ptCursor.x/view.Width  - 1.0f)/projMat._11;
			float vy = (-2.0f*ptCursor.y/view.Height + 1.0f)/projMat._22;
			//Vector is D3DVECTOR
			D3DXVECTOR3 Origin(0.0f, 0.0f, 0.0f);
			// I used Z as my UP VECTOR, not sure how it will work for you
			D3DXVECTOR3 Direction(vx, vy, 1.0f);
			//getting projection matrix
			D3DXMATRIX viewMat;
			m_D3D::GetDevice()->GetTransform(D3DTS_VIEW,&viewMat);
			//inversing projection matrix
			D3DXMATRIX iviewMat;
			D3DXMatrixInverse(&iviewMat, 0, &viewMat);
			D3DXVec3TransformCoord(&Origin, &Origin, &iviewMat);
			D3DXVec3TransformNormal(&Direction, &Direction, &iviewMat);
			//setting variables
			DWORD dwFace;
			FLOAT fBary1, fBary2, fDist;

	
			D3DXIntersect( g_Mesh, &Origin, &Direction, &pickedtmp, &dwFace, &fBary1, &fBary2, &fDist, NULL, NULL );
			
			return pickedtmp;
		}
}

it works, but in this situation, i have two mesh:
Posted Image

Now, when I click on the light, the mesh picked is first the street, and if I click again the light.
I want pick only the Light, because it is before.
Sorry, for my English.
It isn't my language

Edited by MefistoManna, 14 May 2012 - 12:17 PM.


Sponsor:

#2 Sesha   Members   -  Reputation: 107

Like
0Likes
Like

Posted 14 May 2012 - 08:47 PM

Hello mefistomanna,

Try clicking at other places of the screen(near light) if light gets selected at some other point then i think you have to tune your origin and direction vectors.

And also have a look at this http://toymaker.info/Games/html/picking.html.

#3 MefistoManna   Members   -  Reputation: 139

Like
0Likes
Like

Posted 15 May 2012 - 06:47 AM

Thx Sesha,
If I click in one place where there isn't the street behind, the light select correctly, else the selected mesh is light, street, light, street...
I don't know if I was clear.

Edited by MefistoManna, 15 May 2012 - 06:52 AM.


#4 ankhd   Members   -  Reputation: 1186

Like
0Likes
Like

Posted 16 May 2012 - 02:26 AM

use the distance you want the object nearest the viewer.Posted Image

#5 MefistoManna   Members   -  Reputation: 139

Like
0Likes
Like

Posted 16 May 2012 - 09:48 AM

Ok, I'll try.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS