Phantom107 Forum

Phantom107's Forum. Discuss about games, GML, 3d, game design here. Enjoy your stay ;)
HomeFAQSearchRegisterMemberlistUsergroupsLog in

Share | 

 mouse position in 3d

Go down 
Heavy Poster

Posts : 143
Join date : 2008-01-05

PostSubject: mouse position in 3d   Sun Jan 20, 2008 11:49 pm


//sets projection rotations


//finds mouse position in 3d, mx is mouse x and so on

    //fluff is usually 435, with 800x600 resolution and a projection angle of 70.

    if mz<=0

has anyone made some code that can find the mouse position in 3d, i made this code and it barely works. when the mouse is near the edge it loses accuracy. i can't make it work with 1024x600 res or a projection angle of 90. is there a simpler way to convert between 3d mouse coordinates and 2d?
Back to top Go down
View user profile

Posts : 206
Join date : 2008-01-03
Location : The Netherlands

PostSubject: Re: mouse position in 3d   Mon Jan 21, 2008 12:20 am

First of all the 3d mouse position doesn't exist in any way. That's because if you think of it, the mouse in 3d is a line, not a point. Now I know of an extremely complicated script of Gamemaker's #1 user. The script returns the xup, yup and zup where the mouse is pointing in 3d. Unfortunately I've never understood the script, so I can't help in any way. I can supply you with it though:

//Script by Yourself

var mm,dX,dY,dZ,uX,uY,uZ,vX,vY,vZ,mX,mY,mZ, width, height, tFOV; 
dX = argument3-argument0; 
dY = argument4-argument1; 
dZ = argument5-argument2; 
mm = sqrt(dX*dX+dY*dY+dZ*dZ); 
dX /= mm; 
dY /= mm; 
dZ /= mm;
uX = argument6; 
uY = argument7; 
uZ = argument8; 
mm = uX*dX+uY*dY+uZ*dZ; 
uX -= mm*dX; 
uY -= mm*dY; 
uZ -= mm*dZ
 mm = sqrt(uX*uX+uY*uY+uZ*uZ); 
uX /= mm; 
uY /= mm; 
uZ /= mm; 
// v = u x d 
vX = uY*dZ-dY*uZ; 
vY = uZ*dX-dZ*uX; 
vZ = uX*dY-dX*uY; 
tFOV = tan(argument9*pi/360); 
uX *= tFOV; 
uY *= tFOV; 
uZ *= tFOV; 
vX *= tFOV*argument10;
vY *= tFOV*argument10; 
vZ *= tFOV*argument10; 
width = window_get_width(); 
height = window_get_height(); 
mX = dX+uX*(1-2*mouse_y/height)+vX*(2*mouse_x/width-1); 
mY = dY+uY*(1-2*mouse_y/height)+vY*(2*mouse_x/width-1); 
mZ = dZ+uZ*(1-2*mouse_y/height)+vZ*(2*mouse_x/width-1); 
mm = sqrt(mX*mX+mY*mY+mZ*mZ); 
global.mouse_dx = mX/mm; 
global.mouse_dy = mY/mm; 
global.mouse_dz = mZ/mm;}

Note: the arguments used are the same as used in d3d_set_projection_ext but without the two final arguments.
If you haven't fallen off your chair by now: Good Luck.
Back to top Go down
View user profile
Heavy Poster

Posts : 143
Join date : 2008-01-05

PostSubject: Re: mouse position in 3d   Mon Jan 21, 2008 2:01 am

yea, that looks more complicated than my code. i played with the "fluff" variable and found that 300 makes the mouse line up to the 3d coordinates. lol i dont need any help now.

but i would like to know another thing. how to make 3d coordinates 2d, reason for that is to calculate if the mouse clicked a line between two points, so i could create a new point. all in 3d.

i am making a modeling program, because i am too dumb to learn truespace, anim8tor doesn't work correctly on my computer, maybe cuz i have vista. blender makes me sick. lol
Back to top Go down
View user profile
Sponsored content

PostSubject: Re: mouse position in 3d   

Back to top Go down
mouse position in 3d
Back to top 
Page 1 of 1
 Similar topics
» Need to do a simple Left Click in a text box
» Unable to perform Actions on Mouse over Elements in Selenium WebDriver
» Actual movement of the mouse over an object
» Command for mouse over in webdriver
» [Top Rated] Mickey Mouse Clubhouse All Seasons

Permissions in this forum:You cannot reply to topics in this forum
Phantom107 Forum :: Questions and Answers-
Jump to: