slayer64 Heavy Poster
Posts : 143 Join date : 20080105
 Subject: 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,y1*ss2*ss,z1*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_x400)/fluff*cos((face90)*pi/180); my=(mouse_x400)/fluff*sin((face90)*pi/180); mz=(mouse_y300)/fluff*cos((face290)*pi/180);
mx+=(mouse_y300)/fluff*cos((face+180)*pi/180)*sin((face2+90)*pi/180); my=(mouse_y300)/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? 

Phantom107 Admin
Posts : 206 Join date : 20080103 Location : The Netherlands
 Subject: 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 = argument3argument0; dY = argument4argument1; dZ = argument5argument2; 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*dZdY*uZ; vY = uZ*dXdZ*uX; vZ = uX*dYdX*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*(12*mouse_y/height)+vX*(2*mouse_x/width1); mY = dY+uY*(12*mouse_y/height)+vY*(2*mouse_x/width1); mZ = dZ+uZ*(12*mouse_y/height)+vZ*(2*mouse_x/width1); 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. 

slayer64 Heavy Poster
Posts : 143 Join date : 20080105
 Subject: 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 

Sponsored content
 Subject: Re: mouse position in 3d  
 
