Jump to content
  • Advertisement

Archived

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

lly20000

How can I implement this effect

This topic is 5262 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

Now In my software I want implement a effect I don''t know what can I do? In my scene I want when I click a point the other object move this point but I was write a some code and can''t implement this effect I think the problem is the ground''s triangle is too big when I was add some triangle the run it too slow can you tell me a good method to solve this problem this is my code: HRESULT CMyD3DApplication:ick() { HRESULT hr; if(GetCapture() ) { D3DXMATRIXA16 matProj; m_pd3dDevice->GetTransform( D3DTS_PROJECTION, &matProj ); POINT ptCursor; GetCursorPos( &ptCursor ); ScreenToClient( m_hWnd, &ptCursor ); // Compute the vector of the pick ray in screen space D3DXVECTOR3 v; v.x = ( ( ( 2.0f * ptCursor.x ) / m_d3dsdBackBuffer.Width ) - 1 ) / matProj._11; v.y = -( ( ( 2.0f * ptCursor.y ) / m_d3dsdBackBuffer.Height ) - 1 ) / matProj._22; v.z = 1.0f; // Get the inverse view matrix D3DXMATRIXA16 m; m_pd3dDevice->GetTransform( D3DTS_VIEW, &matView ); D3DXMatrixInverse( &m, NULL, &matView ); // Transform the screen space pick ray into 3D space vPickRayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31; vPickRayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32; vPickRayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33; vPickRayOrig.x = m._41; vPickRayOrig.y = m._42; vPickRayOrig.z = m._43; } if(GetCapture()) { LPD3DXBASEMESH pMesh = m_pbuilding2->GetLocalMesh(); LPDIRECT3DVERTEXBUFFER9 pVB; LPDIRECT3DINDEXBUFFER9 pIB; pMesh->GetVertexBuffer(&pVB); pMesh->GetIndexBuffer(&pIB); WORD* pIndices; D3DVERTEX* pVertices; pIB->Lock(0, 0, (void**)&pIndices, 0); pVB->Lock(0, 0, (void**)&pVertices,0); DWORD dwNumFaces = m_pbuilding2->GetLocalMesh()->GetNumFaces(); FLOAT fBary1, fBary2; FLOAT fDist; for( DWORD i=0; iUnlock(); pIB->Unlock(); pVB->Release(); pIB->Release(); } return S_OK; } BOOL CMyD3DApplication::IntersectTriangle( const D3DXVECTOR3& orig, const D3DXVECTOR3& dir, D3DXVECTOR3& v0, D3DXVECTOR3& v1, D3DXVECTOR3& v2, FLOAT* t, FLOAT* u, FLOAT* v ) { // Find vectors for two edges sharing vert0 D3DXVECTOR3 edge1 = v1 - v0; D3DXVECTOR3 edge2 = v2 - v0; // Begin calculating determinant - also used to calculate U parameter D3DXVECTOR3 pvec; D3DXVec3Cross( &pvec, &dir, &edge2 ); // If determinant is near zero, ray lies in plane of triangle FLOAT det = D3DXVec3Dot( &edge1, &pvec ); D3DXVECTOR3 tvec; if( det > 0 ) { tvec = orig - v0; } else { tvec = v0 - orig; det = -det; } if( det < 0.0001f ) return FALSE; // Calculate U parameter and test bounds *u = D3DXVec3Dot( &tvec, &pvec ); if( *u < 0.0f || *u > det ) return FALSE; // Prepare to test V parameter D3DXVECTOR3 qvec; D3DXVec3Cross( &qvec, &tvec, &edge1 ); // Calculate V parameter and test bounds *v = D3DXVec3Dot( &dir, &qvec ); if( *v < 0.0f || *u + *v > det ) return FALSE; // Calculate t, scale parameters, ray intersects triangle *t = D3DXVec3Dot( &edge2, &qvec ); FLOAT fInvDet = 1.0f / det; *t *= fInvDet; *u *= fInvDet; *v *= fInvDet; return TRUE; }

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!