• Advertisement

Archived

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

Detecting 'MouseOver' event on mesh...

This topic is 5922 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 all, 3D objects such as mesh, faces, vertices etc. have their co-ordinates in vectors. But the mouse operates on normal screen x,y co-ordinates. How do I convert the co-ordinates such that I can detect whether the mouse is moving over a 3d object? And just another question - how do I get the absolute position of the mouse? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
In the SDK there is an sample of mouse of mesh.. I havent looked into exactly how to do it yet, but I did come across that example..

Share this post


Link to post
Share on other sites
This seems t o be a common problem, but one of our members has a great example of turning 3d coords into screen coords. This might be to inacurate for use in an iregular mesh

the SDK does have a sample called PickPoly, which is prefect if you get it to work!

Share this post


Link to post
Share on other sites
quote:
Original post by Cybertron
This seems t o be a common problem, but one of our members has a great example of turning 3d coords into screen coords. This might be to inacurate for use in an iregular mesh

the SDK does have a sample called PickPoly, which is prefect if you get it to work!


Where can I find the source to this program that you are mentioning about? (transforming 3d coords to screen coordinate)

Share this post


Link to post
Share on other sites
you can have d3d do the task for you.
just push everything in a vb, and IDirect3DDevice8:rocessVertices() them.
read result back and be happy.

if you want to do it by hand, have a look at the SDK under "Fixed Function Vertex and Pixel Processing" (use search function)

you just the world-matrix for you object, multiply it by your view matrix, and multiply the result by the projection matrix.

then you take every single vertey-vector (x, y, z), convert it to (x, y, z, 1) and multiply the vertex with the 4x4 matrix you got from the last step. the 4th parameter (that you set to 1.0 before multiplying) is called "w" as you might already know.

then you''ve got a (x, y, z, w) vector. from this:
x_screen = x/w
and
y_screen = y/w

well thats nearly all there is to do. the coordinates you will get range from -1 to +1. to convert them to screen-space, do:

x_640_screen = floor(x_screen*320.0+0.5)+320;
y_480_screen = floor(y_screen*240.0+0.5)+240;

this should give the exact location of the projected vertex.

bye,


--- foobar
We push more polygons before breakfast than most people do in a day

Share this post


Link to post
Share on other sites

  • Advertisement