#### Archived

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

# I'm 17,living in INDIA & i need help!!

This topic is 6914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i''m doin a 3d real time strategy game and have a small problem. well as usual i have my 3d terrain with customizable camera position. i have the mouse coords and how in the world do i find at what position in (x,y,z) he is clicking on the terrain?? I already have the code "CGameProgrammer" gave me which is workin great in returning the screen coords of the 3d object,but how do i reverse this cuz i hae 3 variables in just two eqns?? the code CG gave was - Temp = m_matWorld * m_matView; Final = Temp * matProj; XTemp = (Final._11 * x) + (Final._21 * y) +(Final._31 * z)+ Final._41; YTemp = (Final._12 * x) + (Final._22 * y) +(Final._32 * z)+ Final._42; ZTemp = (Final._13 * x) + (Final._23 * y) +(Final._33 * z)+ Final._43; WTemp = (Final._14 * x) + (Final._24 * y) + (Final._34 * z) + Final._44; RW = 1.0f / WTemp; ScreenX = (1.0f + (XTemp * RW)) * 640 / 2.0f; ScreenY = (1.0f - (YTemp * RW)) * 480 / 2.0f; ScreenZ = ZTemp * RW; ScreenW = WTemp; Pls help - my e-mail sandeep_kl@mailcity.com

##### Share on other sites
What you want to do is get a ray that goes through the cameras position and the mouse cursor. Then check where on the terrain this ray intersects, you can do this by testing for intersection with every triangle. Of course you would need some quick way to eliminate as many triangles as possible before computing the actual intersection, otherwise it will be terribly slow.

To compute the ray''s direction vector you take the mouse cursor position and apply the world-to-screen transform in inverse. Meaning you first transform the position to the normalized screen space, then unproject it and then transform it with the inverse viewmatrix.

Now, if you don''t know how to do this then you''ll most likely need to put your project on hold while you''re increasing your math skills.

The ray/triangle intersection test has been covered in so many questions here recently that I will not describe it again, search for a while and I''m sure you''ll find it.

- WitchLord

##### Share on other sites
meanwhile witchlord i found this in the boids program to calculate

D3DUtil_SetIdentityMatrix(matWorld);
D3DUtil_SetTranslateMatrix( matWorld, m_MeshObject[meshno].vLoc );

D3DMATRIX matTemp, matRotateX, matRotateY, matRotateZ;
D3DUtil_SetRotateYMatrix( matRotateY, m_MeshObject[meshno].fYaw );
D3DUtil_SetRotateXMatrix( matRotateX, m_MeshObject[meshno].fPitch );
D3DUtil_SetRotateZMatrix( matRotateZ, m_MeshObject[meshno].fRoll );
D3DMath_MatrixMultiply( matTemp, matRotateX, matRotateY );
D3DMath_MatrixMultiply( matTemp, matRotateZ, matTemp );
D3DMath_MatrixMultiply( matWorld, matTemp, matWorld );

m_MeshObject[meshno].matLocal = matWorld;

m_MeshObject[meshno].vDir.x = matWorld(2, 0);
m_MeshObject[meshno].vDir.y = matWorld(2, 1);
m_MeshObject[meshno].vDir.z = matWorld(2, 2);

the last three lines couldnt give the accurate y values so i had to recalculate the direction vector myself. everything works fine thnx for ur time

Jayanth.K

##### Share on other sites
that was a waste of topic. you shoulda said something else. nothing about age or nationality

- pouya
--------------
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean? It's a mystery, and that's why so is mankind

• 10
• 33
• 29
• 9
• 15