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 
AuthorMessage
slayer64
Heavy Poster
avatar

Posts : 143
Join date : 2008-01-05

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

Code:

//sets projection rotations
cc=cos(face*pi/180);
ss=sin(face*pi/180);
cc2=cos(face2*pi/180);
ss2=sin(face2*pi/180);

d3d_set_projection_ext(x,y,z,x+1*ss2*cc,y-1*ss2*ss,z-1*cc2,0,0,1,70,800/600,1,32000);

//finds mouse position in 3d, mx is mouse x and so on
mx=x;
my=y;
mz=z;

repeat(500)
{
    //fluff is usually 435, with 800x600 resolution and a projection angle of 70.
    mx+=(mouse_x-400)/fluff*cos((face-90)*pi/180);
    my-=(mouse_x-400)/fluff*sin((face-90)*pi/180);
    mz-=(mouse_y-300)/fluff*cos((face2-90)*pi/180);

    mx+=(mouse_y-300)/fluff*cos((face+180)*pi/180)*sin((face2+90)*pi/180);
    my-=(mouse_y-300)/fluff*sin((face+180)*pi/180)*sin((face2+90)*pi/180);
   
    mx+=1*ss2*cc;
    my-=1*ss2*ss;
    mz-=1*cc2;
       
    if mz<=0
        break;
}

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
Phantom107
Admin
avatar

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:

Code:
//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 http://phantom107.actieforum.com
slayer64
Heavy Poster
avatar

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
» Webdriver C# Mouseover
» 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

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