Skip to main content
gamedev.net
🔒 Locked

Translating Mouse Coordinates

Started by TheJakub 2 replies 850+ views
Original Post
TheJakub
TheJakub
I have a windowed application in c#. I am using DirectX and Direct3D, so no OpenGL functions. What I am looking for is to convert my 2D(X,Y) mouse coordinates, when I click someplace in the window, into 3D(X,Y,Z) coordinates. I want to be able to simply insert an object into the 3D world with the click of the mouse button. And I want it to be created exactly where I have my mouse pointer. I''ve tried various things, but it just didn''t seem to work correctly. I just need a solid explanation and some good sample code to guide me through this. Thanks.
TheJakub
TheJakub
Nevermind, I just used UnProject to get my vector.
Dreddnafious Maelstrom
Dreddnafious Maelstrom
if i knew the answer directly i would tell you but i dont. i would recommend the Pick sample in the DX9 DOCS. it cast a ray from the mouse coordinates and detects a collision on the Tiger.x model, giving you per triangle collision detection. you could use this example to steal a similar approach for your issue.

Dredd
________________________________________

"To die with your sword still in its sheath is most regrettable" -- Miyomoto Musashi


"Let Us Now Try Liberty"-- Frederick Bastiat
TheJakub
TheJakub
Yeah, I wrote my own algorithm to un-project my mouse coordinates into 3d coordinates. I soon realized what I was doing wrong. I was using the dimensions of the window and not of the client rectangle where the view is. That would explain the weird X and Y values I kept getting. Which is also why each time I resized my window it was returning completely different values. It''s all good now. Thanks anyways.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.