Do 3D input with the mouse?

Hello!

Does anyone know how i can insert a point in 3d space using the mouse? One axis can be constant during the insert. For example: I want to insert a point at mouseX and mouseY and where z = 10. And it should work even if matrix has a 30 degrees rotation around the y-axis or what ever. I hope you get the point. I have tried several methods but i can’t get anyone to work properly. (

A piece of code, a link, a suggestion or anything else is welcommed!

/Peter - Thanx…

I am not entirely sure about your question… but hey, ever played HomeWorld? it’s got an awesome 3d mouse input… and the “camera” model is awesome!!

basically when you press the ‘M’ key it zooms you out a bit and you can move the mouse vertically on the screen (which moves along the z axis - or + ) or you can move it horizontally (which moves along the x axis + or -), but if you hold shift… you can specify the y co-ordinate… hard to explain over the forum, I suggest you go over a buddy’s house and take a look at it…

By the way, it won the game of the year award, by PCGamer :smiley:

But…

Thank you nigll for your input and congratulation to your award.

Now, this was not the main reason for these postings. What i had in mind was, how do i implement a 3d mouse function in opengl using gluUnproject() or in any other way.
So if anyone knows how this is done or know of a tutorial or something, please let me know!

/Peter…

sorry about that, hehe, and I did not win the award…

-Navreet

controlling anthing in 3d with a 2d cursor is nigh on impossible to do acurately. try it with a 3d modelling program.
back to your question using gluUnProject is quite easy the only hard part is getting the z depth of the thing thats under the mouse , theres an example in the red book 1.1 pg 148 also it comes with the glut under examples/redbook called unproject.c

How about defining the Plane that you want your point to lie on, and when the button is pressed, the X,Y screen location is ratio’d to find out the directional vector…

With that vector, project a ray until it clips the plane, and work out the intersection coordinates.

Is this what you are trying to do??

Thanx for participating!

The reason i need this feature is because i’m trying to make a 3D modeller. As you mentioned earlier, the z plane is trouble. I found a way round this, whithout tricky math. I made a mouse pointer which i define in world space just as an ordinary object with (x,y,z). It has world coordinates instead of screen coordinats and therefor i do not need any conversions. So i simply let OpenGL draw my mouse pointer at (x,y,z). And i move the mousepointer by intercepting the mouse movements.

There is one thing with this way´. I need to hold one plane constant at all time. To me it’s ok, because editing in 3D is really hard, almost impossible. Yes, there’s my solution to the problem. I hope you understand it.

//Peter - Over and out!

i noticed a little confusion
with the way i worded my reply of course its easy to get the zdepth of whats under the cursor eg by going.
float depth;
glReadPixels(pt.x,pt.y,1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);

what i meant was getting the depth in a 3d modelling program when the objects floating in space

I don’t understand why you just don’t use ray-tracing…

Isn’t ray-tracing once faster than using a selection buffer (and having to render twice)…

Sorry if I have the facts all wrong…
Which i probably do

youre correct you could use raytracing, and i would use it if ure trying to find out whats under the cursor every frame or a game but for me i just wanna know whats under the cursor when i press the mouse button