Mouse by JamesBlond25th Sep 2003 17:37
|
---|
Summary This function calculates the mouse vector from the camera into open space and then travels along it until it hits the matrix. Description Here's how it works: Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com ` To get the mouse coordinates call the function like this: ` eg. mmcoord(mousex(),mousey(),1,4000,60) ` - scrx# and scry# are the screen coordinates ` - matnum is the matrix number ` - r# is the length of the vector and should ideally be equal to the camera range ` - FOV# is the field of view of the camera (make sure you get this value right!) function mmcoord(scrx#,scry#,matnum,r#,FOV#) ax#=camera angle x() ay#=camera angle y() scrw#=screen width() scrh#=screen height() hmax# = r#*tan(FOV#/2) mh# = (((scrh#/2-scry#)*2)/scrh#)*hmax# wmax# = r#*scrw#/scrh#*tan(FOV#/2) mw# = (((scrx#-scrw#/2)*2)/scrw#)*wmax# cl# = r#*cos(ax#) ch# = -r#*sin(ax#) sl# = mh#*cos(90-ax#) sh# = mh#*sin(90-ax#) ox# = camera position x() + (cl#+sl#)*sin(ay#) + mw#*cos(ay#) oy# = camera position y() + (ch#+sh#) oz# = camera position z() + (cl#+sl#)*cos(ay#) - mw#*sin(ay#) for i#=0 to 1 step (1.0/r#) x# = camera position x() + (ox#-camera position x())*i# y# = camera position y() + (oy#-camera position y())*i# z# = camera position z() + (oz#-camera position z())*i# if y#-get ground height(matnum,x#,z#)<=0 position object 1,x#,y#,z# exitfunction endif next i# endfunction |