473,385 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C++ directx picking is not working

14
i got help writing my picking function... but it still doesn't work im not sure if it is because the my function or because of my mesh it is one of them. someone suggest me to draw the ray, i drew my rays it basically followed my cursor(mouse).
here is my code

Expand|Select|Wrap|Line Numbers
  1.     BOOL D3dDevice::Picking(HWND hWnd, LPDIRECT3DDEVICE9 d3ddev, CXFileEntity *entity, int z)
  2.     {
  3.         D3DXVECTOR3 v;
  4.         D3DXMATRIX matProj;
  5.         POINT pt;
  6.         D3DVIEWPORT9 vp;
  7.         D3DXMATRIX matInverse, matWorld;
  8.         D3DXMATRIX m;
  9.         D3DXVECTOR3 rayOrigin,rayDir;
  10.         D3DXMATRIX matView;
  11.         D3DXVECTOR3 rayObjOrigin,rayObjDirection, rayDirection;
  12.  
  13.         GetCursorPos(&pt);
  14.         ScreenToClient(hWnd, &pt);
  15.         d3ddev->GetTransform(D3DTS_PROJECTION, &matProj);
  16.         d3ddev->GetViewport(&vp);
  17.  
  18.         d3ddev->GetTransform(D3DTS_VIEW, &matView);
  19.  
  20.         // Use inverse of matrix
  21.         d3ddev->GetTransform(D3DTS_WORLD, &matWorld);
  22.         D3DXVECTOR3 vec3( pt.x, pt.y, 1.0f );
  23.         D3DXVec3Unproject( &rayObjSpace, &vec3, &vp, &matProj, &matView, &matWorld );
  24.         // Transform ray origin and direction by inv matrix
  25.  
  26.         D3DXMATRIX invWorld;
  27.         D3DXMatrixInverse( &invWorld, NULL, &matWorld );
  28.  
  29.         D3DXVECTOR3 camObjSpace;
  30.         camPos.x=0.0;
  31.         camPos.y=0.0;
  32.         camPos.z=z;
  33.         D3DXVec3TransformCoord( &camObjSpace, &camPos, &invWorld ); 
  34.  
  35.         rayDir = rayObjSpace - camObjSpace;
  36.  
  37.         BOOL hasHit;
  38.         float distanceToCollision;
  39.  
  40.         if(FAILED(D3DXIntersect(entity->pDrawMesh, &rayObjSpace, &rayDir, &hasHit, NULL, NULL, NULL, &distanceToCollision, NULL, NULL)))
  41.         {
  42.             PostQuitMessage(0);
  43.         };
  44.  
  45.         if(hasHit==1)
  46.         {
  47.             PostQuitMessage(0);
  48.         }
  49.  
  50.         return hasHit;
  51.     }
i have no idea why it is not working, by the way i did a that `rayObjSpace.z` never equals to 0, it is always in the 80s. entity->pDrawMesh is not `LPD3DXMESH` not `LPD3DXBASEMESH`.
thanks in advance
Nov 23 '10 #1
0 1190

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dr Paul A Daniels | last post by:
I've got Visual Studio 7.0.9466 and have installed the Framework 1.1 and its SDK and DirectX 9.0 (Summer 2003 release) SDK. OS is Windows XP Pro. I'm logged on with Administrator rights. I...
1
by: Chuck Glenn | last post by:
I installed visual studio 2002 (aka 7.0) enterprise architect, then directx 9.0b. Directx acted like it was installing .net extensions, but I when I open someone else's (tested and working) code,...
6
by: ammd | last post by:
Hi, I installed Microsoft DirectX 9.0 SDK (Summer 2004) but when I create a project and try to add the necessary references I can't find them. Does anybody know where to look for them? BTW, I have VS...
0
by: John Marco | last post by:
I'm working on adding some dialogs to a DirectX app that I've been working on. The DirectX app by itself works fine, but when I try to define a DialogBox and call the DialogBox function, I get the...
6
by: poldoj | last post by:
Its possible to get directX working with vb.net? I have heard something about "managed code", where I can find more infos? thanks
0
by: Harvey Cohen | last post by:
Hello all, I have some C# code that implements calls to DirectX.DirectSound. It compiles under both VS .NET 2003 and VS 2005 and runs under VS .NET 2003 and VS 2005 on a Compaq laptop (Windows...
14
by: Jessica Weiner | last post by:
I am writing an application in C# which need to plot graphs and simple shapes (polygons, circles, squares etc). Which library is better for this purpose and why? Thanks.
10
by: gerry | last post by:
i just downloaded and installed the directx aug 2006 sdk the machine i installed it on had both vs2003 & vs2005 the visual studio extensions were installed into vs2003 but not into vs2005. does...
3
by: Edward Mitchell | last post by:
I am converting a project that uses DirectX and worked under VS.NET 2003. Now when I convert the project to .NET 2005, there are linker errors for _Xran and _Xlen as follows: ...
3
by: Robert Hooker | last post by:
Does anyone have any information on when MDX2.0 will come out of Beta? It seems like its been in Beta for a looong time... Rob
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.