Hello,
I'm playing around with an isometric RPG and want to position a cursor object at the mouse coordinates.
I'm using Math 89's function from
here
Can someone tell me why the cursor object isn't positioned at the mouse coords?
`Attempt to setup an ortho camera with an object positioned at the mouse position
`results are good when the mouse is in the center of the screen
`but gets less accurate as the mouse is moved to the screen edges
sync on : sync rate 60
`globals
global cube gridplane gridimage as integer
global oldCurX oldCurZ as integer
global ObPos_X ObPos_Y ObPos_Z as integer
global gridsize# = 100.0
`object and image ids
cube = 1
gridplane = 2
gridimage = 1
make object cube cube, 32
c_SetupGridPlane(32000,32000,0)
m = new matrix4()
zoom# = 600
`camera setup
position camera 50, 50, 50
point camera 0, 0, 0
move camera -500
do
setCameraToOrtho(0,m,-zoom#,zoom#,-zoom#,zoom#,1,1000) `comment this line out to see the object positioned correctly without ortho
PositionCursorBlock()
sync
loop
function setCameraToOrtho(cam, matrix, left as float, right as float, bottom as float,top as float, near as float, far as float)
d1# = 2.0/(right-left)
d2# = 3.0/(top-bottom) `2.0
d3# = 1.0/(far-near)
c1# = - (right+left)/(right-left)
c2# = - (top+bottom)/(top-bottom)
c3# = - (near)/(far-near)
set matrix4 matrix, d1#,0,0,0,0,d2#,0,0,0,0,d3#,0,c1#,c2#,c3#,1
apply projection matrix4 matrix,cam
endfunction m
function PositionCursorBlock()
ongrid = pick object(mousex(),mousey(),gridplane,gridplane)
curx# = int((camera position x()+ get pick vector x())/gridsize#) * gridsize#
curz# = int((camera position z()+ get pick vector z())/gridsize#) * gridsize#
ObPos_X = curx# +50
ObPos_Z = curz# +50
ObPos_Y = 10
if oldCurX <> ObPos_X or oldCurZ <> ObPos_Z `detect if the cursor has moved
position object cube, ObPos_X, ObPos_Y, ObPos_Z `positions the cursor
endif
oldCurX = ObPos_X
oldCurZ = ObPos_Z
endfunction
function c_SetupGridPlane(sizex, sizey, ypos)
cls rgb(16,16,16)
for x=0 to 100 step 10
if x=0 then ink rgb(99,99,99),0 else ink rgb(33,33,33),0
if x=64 then ink rgb(66,66,66),0
line x,0,x,128
line 0,x,128,x
next x
get image gridimage,0,0,100,100,1
make object plain gridplane, sizex, sizey : rotate object gridplane,90,0,0 : fix object pivot gridplane
texture object gridplane, gridimage
ghost object on gridplane
set object cull gridplane, 0
position object gridplane, 0, 0, 0
set object light gridplane, 0
scale object texture gridplane,32,32
SET ALPHA MAPPING ON gridplane, 15
endfunction