Jump to content
  • Advertisement

Archived

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

mickey

i have pickrayorig and pickraydir, how do i know how far my click is?

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

hi, ie, dungeon siege, neverwinter nights, how do i move my character to the spot click by the mouse, i have the rays from the sdk sample, thanks,

Share this post


Link to post
Share on other sites
Advertisement
D3DXVECTOR3 clickspot = rayorigin + (raydirection * raylength)

You already know the rayorigin + raydirection... The ray function to determine if it hits anything will return the length of the ray if it does hit something.

If you know the clickspot you know how to make the guy move from its current location to the clickspot right? Its almost 2d at that time.

Share this post


Link to post
Share on other sites
I dont think it''s working this way. :D Length of the ray is useless. I''m working on the same problem. You need to know how far you clicked from your character''s previous position right?

If you can figure something out let me know :D

Share this post


Link to post
Share on other sites
hi JoeyBlow2,

i think me and dracoon have exactly the same problem,

you see your formula is correct,

clickspot = rayorigin + (raydirection * x)

where x is the value the character should go to.., but how do calculate for x? or probably it''s up to us to implement a collision detection?

Share this post


Link to post
Share on other sites
quote:
Original post by mickey
hi JoeyBlow2,

i think me and dracoon have exactly the same problem,

you see your formula is correct,

clickspot = rayorigin + (raydirection * x)

where x is the value the character should go to.., but how do calculate for x? or probably it''s up to us to implement a collision detection?




If i understand correctly then you can simply rearrange for x:

x = (clickspot - rayorigin) / raydirection

Share this post


Link to post
Share on other sites
I may place one mesh as the ground. It''s a simple square from two triangles. Then D3DXIntersect returns the barycentric u and v coords.
----
|1/|
|/2|
----

1st triangle
Upper Left corner 0,0
Upper Right corner 1,0
Bottom Left corner 0,1

combined with the 2nd triangle (using "1-")
Bottom Right corner 1,1

I can multiply the value with the square''s width so I got the exact coords. I also know the character''s previous position, so I can simply calculate the angle and the distance. I can also move and zoom and rotate the camera freely.


Just an idea, I will try it tomorrow. What do you think?

Share this post


Link to post
Share on other sites
Maybe another way with D3DXIntersect, if I can set the Picking Ray''s origin to the character, and the direction to the point I clicked. But I dont even fully understand the sample''s coords...

D3DXMATRIXA16 matProj;
pd3dDevice->GetTransform( D3DTS_PROJECTION, &matProj );
D3DXVECTOR3 v;

v.x=(((2.0f*ptCursor.x)/Width)-1)/matProj._11;
v.y=-(((2.0f*ptCursor.y)/Height)-1)/matProj._22;
v.z=1.0f;

D3DXMATRIXA16 matView, m;
pd3dDevice->GetTransform( D3DTS_VIEW, &matView );
D3DXMatrixInverse( &m, NULL, &matView );

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;

Do you? :D

Share this post


Link to post
Share on other sites

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