As i moved from moving somple boxes to my models, i ran into a problem. My mouse keeps loosing the object very easily, especially if its a complex or a small object. and sometimes it just behaves in a strange way. if i click on the object, it would jerk it away from the mouse and sometimes it just wouldnt move the object at all. it differs from the angle of the camera.
i am making small a world editor type thingy and i import terrains into this program along with other models, that could be part of the problem. but i think its the pick object command. Part of the problem may be that the terrain is getting in the way sometimes. Mybe there is a way to make thepickobject command completley ignotre the terrain so it will not loose sight of te object
is there a way to make the pick object function more stable like so the object would be completley attached to the mouse instead of just follow it.
here is the stripped down code with the function that has this.
global objnum
objnum=4
global sizex#
global sizey#
global sizez#
sizex#=10
sizey#=10
sizez#=10
sync on
sync rate 30
make object box 1,10,10,10
hide object 1
make matrix 1,1000,1000,30,30
make object cube 4,30
do
edit()
sync
loop
function edit()
set ambient light 80
rotate = mousemovez()
cursorobj = pick object(mousex(),mousey(),2,9999)
fade object objnum,60
`higlight the object when mouse is over it
if cursorobj = objnum
fade object objnum,100
`position object instance, object position x(objnum), object position y(objnum), object position z(objnum)
`scaling using the mousewheel
if shiftkey()=0
if rotate < 0
sizex#=sizex#+3
sizey#=sizey#+3
sizez#=sizez#+3
scale object objnum,sizex#,sizey#,sizez#
endif
if rotate> 0
sizex#=sizex#-3
sizey#=sizey#-3
sizez#=sizez#-3
scale object objnum,sizex#,sizey#,sizez#
endif
endif
`move object up or down
endif
`rotateing using rightclick
if mouseclick()=2
rotate object objnum,0,mousex(),0
endif
`///////////////////////////////////////////////////
o = pick object(mouseX(), mouseY(), 2, 2)
`//////////////////////////////////////////////////
objx = camera position x(0) + get pick vector x()
objy = camera position y(0) + get pick vector y()
objz = camera position z(0) + get pick vector z()
`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
oldobjx=object position x(objnum)
oldobjy=object position y(objnum)
oldobjz=object position z(objnum)
`///////////////////////////////////////////////////
if mouseclick() = 1 and cursorobj = objnum
` In your main loop / function that is called from there
` For the Y-coordinate, you can also use the height of the ground
` object at the particular (x, y) position
position object objnum, objx, oldobjy, objz
endif
`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
oldobjx=object position x(objnum)
oldobjy=object position y(objnum)
oldobjz=object position z(objnum)
if shiftkey()=1 and cursorobj = objnum
if rotate > 0
oldobjy=oldobjy+3
endif
if rotate < 0
oldobjy=oldobjy-3
endif
endif
`////////////////////////////////////////////////////
`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
position object objnum, oldobjx, oldobjy, oldobjz
`/////////////////////////////////////////////////////
`record object position
ox#=object position x(1)
oy#=object position y(1)
oz#=object position z(1)
`record camera x and z positions
cx# = camera position x()
cz# = camera position z()
cy# = camera position y()
`camera rotate positions
crx#=camera angle x()
cry#=camera angle y()
crz#=camera angle z()
`mouse position
mx# = mousemovex()
my# = mousemovey()
`/////////////////////////////////////////////////////
position camera ox#, oy#, oz#
`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
`the movement of the camera in 3d space
`(in combination with the moselook)
`still cant get strafing to work for some reason
`use middle mouse button to use mouse look
`and W,S to go forward and backward
`//////////////////////////////////////////////////////
if spacekey()=1
hide mouse
`360 camera movement
rotate camera crx#+((my#+0.0)/2.0),cry#+((mx#+0.0)/2.0),0
rotate object 1,crx#,cry#,crz#
`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
if keystate(17)=1 then move object 1,20
if keystate(31)=1 then move object 1,-20
`here i want to add camera strafing
if keystate(32)
endif
`//////////////////////////////////////////////////////
if keystate(30)
endif
`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
endif
`///////////////////////////////////////////////////
if spacekey()=0
show mouse
endif
`/////////////////////////////////////////////////////
endfunction
space+mouselook is to look around, w,s to go forward backward and shift plus mousewheel(while mouse over the object) to move it up or down, pain mouswheel to scale it
now i am not sure if this is the problem because in this stripped down version, i cant notice it as much, if anyone want to take a closer look, i can upload my entire program with a few models.
dont hate people who rip you off,cheat and get away with it, learn from them