Ofir David
Ofir David

Reputation: 1

2D mouse picking in 3D world

I'm trying to implement object movement in OpenGL towards a mouse click event but the problem is that the coordinates that are returned are not in world space but rather within the window size. I know that it is called mouse picking but all the solutions that I've found online refer to 3D mouse picking when my object is in the 3D space but I don't care about the Z coordinate, I only care about the X and Y coordinates.

I tried implementing many mouse picking algorithms but all of them refer to all of the coordinates when I only care, also I think that mouse picking refers to dragging objects but I want movement towards my mouse coordinates instead

Upvotes: -1

Views: 247

Answers (1)

fana
fana

Reputation: 1870

Since the 2D coordinates on the window correspond to the ray on the 3D space, it is necessary to define at which position on the ray you want to know.

When using orthogonal projection, (X,Y) is the same for all positions on the ray. But if not (using perspective projection), (X,Y) value is depend on Z.

Therefore...

One conceivable simple way is that using the Z value of the object you want to move.

Upvotes: 1

Related Questions