No what yall gave is perfect. I almost got it working perfectly. I just used repeated right triangle math except without the confusing ratios that yall used and i don't have all that cosine stuff. I knew i would have to rotate it from the camera's angles and I would have never been able to figure out how without yalls rotation matrix help. I'll paste the function as soon as I get it working. may be able to benefit some people. it will use sparky's and what it does is returns the object the mouse collided with. =)
Edit:
Here's the function so far. I've just got to add when you rotate the camera up or down and figure out why the location is just a little off =)
For the function to work, you need sparky's and the object needs to be loaded into sparky's.
function pickobject(mx,my,distance,num,flag,exclude)
cax#=camera angle x()
cay#=camera angle y()
cx#=newxvalue(camera position x(),cy#,1)
cy#=newyvalue(camera position y(),cx#,1)
cz#=newzvalue(camera position z(),cy#,1)
fov#=62
my=screen height()-my
xdist#=(screen width()/2)/tan(fov#/2)
ydist#=(screen height()/2)/tan(fov#/2)
xwidth=mx-(screen width()/2)
ywidth=my-(screen height()/2)
if mx=screen width()/2
xang#=0
xpos#=(cx#*cos(cay#))+((cz#+distance)*sin(cay#))
zpos#=(-1*cx#*sin(cay#))+((cz#+distance)*cos(cay#))
else
xang#=atanfull(xdist#,xwidth)
xpos#=((cx#+((xdist#+distance)/tan(xang#)))*cos(cay#))+((cz#+distance)*sin(cay#))
zpos#=(-1*(cx#+((xdist#+distance)/tan(xang#)))*sin(cay#))+((cz#+distance)*cos(cay#))
endif
if my=screen height()/2
yang#=0
ypos#=cy#
else
yang#=atanfull(ydist#,ywidth)
ypos#=cy#+((ydist#+distance)/tan(yang#))
endif
object=intersectObjectDBC(num,flag,cx#,cy#,cz#,xpos#,ypos#,zpos#,exclude)
endfunction object
Edit:
I got it working perfectly now, besides a y matrix rotation. I'm having a bit of trouble with it.
function pickobject(mx,my,distance,num,flag,exclude)
cax#=camera angle x()
cay#=camera angle y()
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
fov#=62
my=screen height()-my
xdist#=(screen width()/2)/tan(fov#/2)
ydist#=(screen height()/2)/tan(fov#/2)
xwidth#=(mx-(screen width()/2))/1.15
ywidth#=(my-(screen height()/2))/1.4
if mx=screen width()/2
xang#=0
xpos#=(cx#*cos(cay#))+((cz#+distance)*sin(cay#))
zpos#=(-1*cx#*sin(cay#))+((cz#+distance)*cos(cay#))
else
xang#=atanfull(xdist#,xwidth#)
xpos#=((cx#+((xdist#+distance)/tan(xang#)))*cos(cay#))+((cz#+distance)*sin(cay#))
zpos#=(-1*(cx#+((xdist#+distance)/tan(xang#)))*sin(cay#))+((cz#+distance)*cos(cay#))
endif
if my=screen height()/2
yang#=0
ypos#=(cy#*cos(cax#))-(zpos#*sin(cax#))
else
yang#=atanfull(ydist#,ywidth#)
ypos#=(cy#+((ydist#+distance)/tan(yang#)))*cos(cax#)-((cz#+distance)*sin(cax#))
endif
object=intersectObjectDBC(num,flag,cx#,cy#,cz#,xpos#,ypos#,zpos#,exclude)
endfunction object
There is one strange thing about the selection. For some reason when I got the distance for the mouse. I had to multiply them by a random ratio, different number for the height and width. I can't find the numbers relation to the equation tho. I'm not sure if it has to do with ratio's or not. Thats just my guess.
xwidth#=(mx-(screen width()/2))/1.15
ywidth#=(my-(screen height()/2))/1.4
I have no idea what the 1.15 or 1.14 are used for but they make it work.
Edit:
Finally done!
I still don't understand the ratios and would love for someone to explain them, but in the meantime. Here's the function if anyone would like it. you just need sparky's and to set the object up as a collision object.
function pickobject(mx,my,distance,num,flag,exclude)
cax#=camera angle x()
cay#=camera angle y()
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
fov#=62
my=screen height()-my
xdist#=(screen width()/2)/tan(fov#/2)
ydist#=(screen height()/2)/tan(fov#/2)
xwidth#=(mx-(screen width()/2))/1.15
ywidth#=(my-(screen height()/2))/1.4
if mx=screen width()/2
xang#=0
xpos#=(cx#*cos(cay#))+((cz#+distance)*sin(cay#))
zpos#=(-1*cx#*sin(cay#))+((cz#+distance)*cos(cay#))
else
xang#=atanfull(xdist#,xwidth#)
xpos#=((cx#+((xdist#+distance)/tan(xang#)))*cos(cay#))+((cz#+distance)*sin(cay#))
zpos#=(-1*(cx#+((xdist#+distance)/tan(xang#)))*sin(cay#))+((cz#+distance)*cos(cay#))
endif
if my=screen height()/2
yang#=0
ypos#=(cy#*cos(cax#))-(zpos#*sin(cax#))
else
yang#=atanfull(ydist#,ywidth#)
ypos#=((cy#+((ydist#+distance)/tan(yang#)))*cos(cax#))-(zpos#*sin(cax#))
zpos#=(zpos#*cos(cax#))+((cy#+((ydist#+distance)/tan(yang#)))*sin(cax#))
endif
object=intersectObjectDBC(num,flag,cx#,cy#,cz#,xpos#,ypos#,zpos#,exclude)
endfunction object
EdIt:
Just found a bug where if the x and y angles are both changed. the calculations are off. Will fix
This has been a lot of edits. guess you gotta do what it takes to not double post lol