Jump to content
  • Advertisement
Sign in to follow this  

can only pick certain parts of the terrain

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

why would i be only be able to pick only a certain part of the terrain
ive got the terrain in worldspace now along with the pick positon and direction (which is the inverse of view space), but it only seems to pick cerrtain parts of the terrain and not everywhere?, i am baffeled


[Edited by - Anddos on September 1, 2010 11:43:32 PM]

Share this post

Link to post
Share on other sites
You haven't told us a single thing about how you're doing your picking algorithm. Maybe if you give us a few more details people will be better able to see what's going wrong.

Until then I won't even try to hazard a guess at what's going wrong.

Share this post

Link to post
Share on other sites
I did explain i am doing picking and the ray origin and direction is in worldspace (inverse of camera matrix), and the terrain is Identity matrix, when i go to put the mouse cursor over the terrain , only certain area of faces on the terrain can be picked and not everywhere...

Share this post

Link to post
Share on other sites
Since it looks from the screenshot you got most of your code from Frank Luna's samples, maybe you could just include a snippet showing us your picking code? Until then I agree with Darg, I would have a hard time helping you, since I would just be guessing really.

Share this post

Link to post
Share on other sites

The ray origin and direction is in worldspace , which is the inverse of the camera matrix, the terrain is set to identity, i didnt know you can pick in clip space...

This is the pick function

void WalkTerrainDemo::getWorldPickingRay(D3DXVECTOR3& originW, D3DXVECTOR3& dirW)
// Get the screen point clicked.

// Make it relative to the client area window.
ScreenToClient(FindWindow(NULL,"Walk Terrain Demo"), &s);

// By the way we've been constructing things, the entire
// backbuffer is the viewport.

float w = (float)md3dPP.BackBufferWidth;
float h = (float)md3dPP.BackBufferHeight;

D3DXMATRIX proj = gCamera->proj();

float x = (2.0f*s.x/w - 1.0f) / proj(0,0);
float y = (-2.0f*s.y/h + 1.0f) / proj(1,1);

// Build picking ray in view space.
D3DXVECTOR3 origin(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 dir(x, y, 1.0f);

// So if the view matrix transforms coordinates from
// world space to view space, then the inverse of the
// view matrix transforms coordinates from view space
// to world space.
D3DXMatrixInverse(&invView, 0, &gCamera->view());

// Transform picking ray to world space.
D3DXVec3TransformCoord(&originW, &origin, &invView);
D3DXVec3TransformNormal(&dirW, &dir, &invView);
D3DXVec3Normalize(&dirW, &dirW);

This is how the terrain is rendering

HR(mFX->SetMatrix(mhViewProj, &gCamera->viewProj()));
HR(mFX->SetMatrix(mhWorld,&TerrainMatrix)); //Identity
UINT numPasses = 0;
HR(mFX->Begin(&numPasses, 0));

for(UINT i = 0; i < mSubGridMeshes.size(); ++i)


This is part of the terrain shader , just the vertex shader part where it takes the position and multiplys it by world..

OutputVS TerrainVS(float3 posW : POSITION0, // We assume terrain geometry is specified
float3 normalW : NORMAL0, // directly in world space.
float2 tex0: TEXCOORD0)
// Zero out our output.
OutputVS outVS = (OutputVS)0;
// Transform vertex position to world space.
float3 pW = mul(float4(posW, 1.0f), gWorld).xyz;

// Just compute a grayscale diffuse and ambient lighting
// term--terrain has no specular reflectance. The color
// comes from the texture.
outVS.shade = saturate(max(0.0f, dot(normalW, gDirToSunW)) + 0.3f);

// Transform to homogeneous clip space.
outVS.posH = mul(float4(pW, 1.0f), gViewProj);

// Pass on texture coordinates to be interpolated in rasterization.
outVS.tiledTexC = tex0 * gTexScale; // Scale tex-coord to tile.
outVS.nonTiledTexC = tex0; // Blend map not tiled.

// Done--return the output.
return outVS;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!