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 - BOOL D3dDevice::Picking(HWND hWnd, LPDIRECT3DDEVICE9 d3ddev, CXFileEntity *entity, int z)
-
{
-
D3DXVECTOR3 v;
-
D3DXMATRIX matProj;
-
POINT pt;
-
D3DVIEWPORT9 vp;
-
D3DXMATRIX matInverse, matWorld;
-
D3DXMATRIX m;
-
D3DXVECTOR3 rayOrigin,rayDir;
-
D3DXMATRIX matView;
-
D3DXVECTOR3 rayObjOrigin,rayObjDirection, rayDirection;
-
-
GetCursorPos(&pt);
-
ScreenToClient(hWnd, &pt);
-
d3ddev->GetTransform(D3DTS_PROJECTION, &matProj);
-
d3ddev->GetViewport(&vp);
-
-
d3ddev->GetTransform(D3DTS_VIEW, &matView);
-
-
// Use inverse of matrix
-
d3ddev->GetTransform(D3DTS_WORLD, &matWorld);
-
D3DXVECTOR3 vec3( pt.x, pt.y, 1.0f );
-
D3DXVec3Unproject( &rayObjSpace, &vec3, &vp, &matProj, &matView, &matWorld );
-
// Transform ray origin and direction by inv matrix
-
-
D3DXMATRIX invWorld;
-
D3DXMatrixInverse( &invWorld, NULL, &matWorld );
-
-
D3DXVECTOR3 camObjSpace;
-
camPos.x=0.0;
-
camPos.y=0.0;
-
camPos.z=z;
-
D3DXVec3TransformCoord( &camObjSpace, &camPos, &invWorld );
-
-
rayDir = rayObjSpace - camObjSpace;
-
-
BOOL hasHit;
-
float distanceToCollision;
-
-
if(FAILED(D3DXIntersect(entity->pDrawMesh, &rayObjSpace, &rayDir, &hasHit, NULL, NULL, NULL, &distanceToCollision, NULL, NULL)))
-
{
-
PostQuitMessage(0);
-
};
-
-
if(hasHit==1)
-
{
-
PostQuitMessage(0);
-
}
-
-
return hasHit;
-
}
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
0 1190 Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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...
|
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...
|
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
|
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...
|
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.
|
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...
|
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:
...
|
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
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |