ok so here is my problem, I have come up with an physics object make, but at the mo Im using mousemove x & y but which moves a sphere around like a mouse pointer.
but what I won`t to do is move the mouse cursor on the x & y using ray casting to place objects
here is what Im doing with the ray cast and mouse
move the ray cast object with the mouse its a bit scetchy
hold mouse left button to rotate camera, up down or w & s keys to move camera.
sync on : sync rate 60
phy start
autocam off
`position camera 0,80,-20
xrotate camera 55
make object cube 1001,1
scale object 1001,10000,10,10000
position object 1001,0,-20,0
phy make rigid body static box 1001
for xx = 1 to 100
make object cube xx,1
position object xx, rnd(50)-rnd(50),10,rnd(50)-rnd(50)
color object xx, rgb(rnd(255),rnd(255),rnd(255))
phy make rigid body dynamic box xx
next xx
oldID = 1
ID = 100
`ray cast object
make object sphere 101,1
`camera object
make object sphere 102,1
`black ink
ink rgb(0,0,0),0
do
FPS = screen fps()
MMX = mousemovex()
MMY = mousemovey()
MC = mouseclick()
mx# = mousex()
my# = mousey()
po = pick object(mx#,my#,1,1001)
gpd# = get pick distance()
pick screen mx#,my#,1.0 :`phy get ray cast distance ( ) :` gpd# :`+po
` position camera object
position object 102,camera position x(),camera position y(),camera position z()
`*** ray cast object position ***
x# = object position x(102)
y# = object position y(102)
z# = object position z(102)
`*** ray cast object orientation ***
set object to camera orientation 102
move object 102, 1
`Work out x,y,z vectors by just subtracting the old position from the new position
xvec# = object position x(102) - x#
yvec# = object position y(102) - y#
zvec# = object position z(102) - z#
`*** camera position ***
`camx# = camera position x()
`camy# = camera position y()
`camz# = camera position z()
`*** vectors ***
gpvx# = get pick vector x() - camx#
gpvy# = get pick vector y() - camy#
gpvz# = get pick vector z() - camz#
newgpvx# = get pick vector x() - gpvx#
newgpvy# = get pick vector y() - gpvy#
newgpvz# = get pick vector z() - gpvz#
`*** ray cast hit point ***
grchpx# = phy get ray cast hit point x ( )
grchpy# = phy get ray cast hit point y ( )
grchpz# = phy get ray cast hit point z ( )
`**********************************************************************************************
`here is the problem a its a bit unstablen and I need help to fix this.
`*** old vector ***
rayvec1X# = x# + gpvx# * gpd#
rayvec1Y# = y# + gpvy# * gpd#
rayvec1Z# = z# + gpvz# * gpd#
`*** new vector ***
rayvec2X# = xvec# - newgpvx# * gpd#
rayvec2Y# = yvec# - newgpvy# * gpd#
rayvec2Z# = zvec# - newgpvz# * gpd#
`************************************************************************************************
`*** squere root ***
`ray_sqrt# = sqrt((camx# - )^2 + (camy# - )^2 + (camy# - )^2)
`*** get closest shape ***
ray = phy ray cast closest shape ( rayvec1X#,rayvec1Y#,rayvec1Z#,rayvec2X#,rayvec2Y#,rayvec2Z# )
`ray = phy ray cast closest shape ( x#,y#,z#,xvec#,yvec#,zvec# )
`ray = phy ray cast closest shape(x#+gpvx#,y#+gpvy#,z#+gpvz#,xvec#-newgpvx#,yvec#-newgpvy#,zvec#-newgpvz#)
obj = phy get ray cast object ()
grcd# = phy get ray cast distance()
position object 101,phy get ray cast hit point x ( ),phy get ray cast hit point y ( ),phy get ray cast hit point z ( )
set cursor 0,0 :print "the ray thats cast on to object: ";obj
set cursor 0,20 :print "this is from the object picker: ";po
set cursor 0,40 :print "pick distance: ";gpd#
set cursor 0,60 :print "get ray cast distance: ";grcd#
set cursor 0,80 :print "scancode: ",scancode()
`camera control by Dark Coder.
if MC = 1
cameraRotDestx# = cameraRotDestx# + MMY * 0.5
cameraRotDesty# = cameraRotDesty# + MMX * 0.5
if cameraRotDestx# > 85.0 then cameraRotDestx# = 85.0
if cameraRotDestx# < -85.0 then cameraRotDestx# = -85.0
cameraRotCurx# = CurveValue( cameraRotDestx#, cameraRotCurx#, FPS * 0.1 )
cameraRotCury# = CurveValue( cameraRotDesty#, cameraRotCury#, FPS * 0.1 )
cameraRotCurz# = CurveValue( cameraRotDestz#, cameraRotCurz#, FPS * 0.1 )
Rotate Camera cameraRotCurx#,cameraRotCury#, cameraRotCurz#
endif
if scancode() = 17 or upkey()=1 then move camera 0.5
if scancode() = 31 or downkey()=1 then move camera -0.5
phy update
sync
loop
here is what is going to be like as an physic object maker
`*** use 1 2 & 3 to pick objects objects, left click mouse to make object, press space to delete all objects ***
sync on :sync rate 60
phy start
hide mouse
`set display mode 800,600,32
`*** camera setup ***
autocam off
position camera 0,0,80,-20 :`x625
xrotate camera 0,45
`*** mouse values
type Mouse_values
Mxpos# as integer
Mypos# as integer
Mzpos# as integer
Mxmove as float
Mymove as float
Mzmove as float
Mobjx# as integer
Mobjy# as integer
Mobjz# as integer
mouse_click as boolean
endtype
global Mouse as Mouse_values
`*** object values ***
type Object_Values
xpos# as integer
ypos# as integer
zpos# as integer
xang# as integer
yang# as integer
zang# as integer
xsize# as integer
ysize# as integer
zsize# as integer
red as float
green as float
blue as float
total_obj as float
Load_Object$ as string
Phy_Mesh$ as string
endtype
dim Array(1000) as Object_Values
`*** make a floor object ***
make object cube 1001,1
scale object 1001,50000,10,50000
position object 1001,0,-20,0
`color object 1001,rgb(255,0,0)
phy make rigid body static box 1001
`*** make mouse object ***
make object sphere 1002,10
`position object 1002,625,20,0
set object 1002,0,1,1
color object 1002,rgb(0,0,0)
`*** colour ink black ***
ink rgb(0,0,0),0
`*** start the loop ***
do
`randomize timer()
`*** mouse values ***
Mouse.mouse_click = mouseclick()
Mouse.Mxpos# = mousex()
Mouse.Mypos# = mousey()
Mouse.Mzpos# = mousez()
Mouse.Mxmove = mousemovex()
Mouse.Mymove = mousemovey()
Mouse.Mzmove = mousemovez()
`*** print outs ***
set cursor 0,20 : print "ues numbers 1 2 3 to change objects"
set cursor 0,40 : print "left click mouse to make an object"
set cursor 0,60 : print "press space to delete all object"
set cursor 0,80 : print "mouse x pos: ";Mouse.Mxpos#;" mouse y pos: ";Mouse.Mypos#
set cursor 0,100 : print "mouse move x: ";Mouse.Mxmove;" mouse move y: ";Mouse.Mymove
set cursor 0,120 : print "object made: ";Array(ID).Load_Object$
set cursor 0,140 : print "object number: ";ID
set cursor 0,160 : print "fps: ";screen fps()
`*** object picker ***
if scancode() = 2
ID_object_picker = 1
for c = 1 to 1000
Array(c).xsize# = 1000 :`XYZ size#
Array(c).ysize# = 1000
Array(c).zsize# = 1000
next c
endif
if scancode() = 3
ID_object_picker = 2
for c = 1 to 1000
Array(c).xsize# = 1250 :`XYZ size#
Array(c).ysize# = 1250
Array(c).zsize# = 1250
next c
endif
if scancode() = 4
ID_object_picker = 3
for c = 1 to 1000
Array(c).xsize# = 1100 :`XYZ size#
Array(c).ysize# = 1100
Array(c).zsize# = 1100
next c
endif
`*** mouse movement controls ***
if Mouse.Mxmove < 0
dec Mouse.Mobjx#,3
endif
if Mouse.Mxmove > 0
inc Mouse.Mobjx#,3
endif
if Mouse.Mymove < 0
dec Mouse.Mobjy#,3
endif
if Mouse.Mymove > 0
inc Mouse.Mobjy#,3
endif
`*** mouse pointer object ***
position object 1002,Mouse.Mobjx#,0,-Mouse.Mobjy#
`*** object colour picker ***
for c = 1 to 1000
Array(c).red = rnd(255) :`red colour
Array(c).green = rnd(255) :`green colour
Array(c).blue = rnd(255) :`blue colour
if object exist(c) = 1
Array(c).xpos# = object position x(c) :`XYZ pos#
Array(c).ypos# = object position y(c)
Array(c).zpos# = object position z(c)
Array(c).xang# = object angle x(c) :`XYZ ang#
Array(c).xang# = object angle x(c)
Array(c).xang# = object angle x(c)
endif
next c
`*** make objects ***
if Mouse.mouse_click = 1 then on_off = 1
if on_off = 1
inc ID_timer :`this is to count down the ID timer.
if ID_timer = 25 then ID_timer = 0 : on_off = 0 :`this is the swich off for the timer.
OldID = ID :`store the old ID number in OldID
if ID < 1000 and ID_timer = 1 then inc ID
if OldID < ID and ID_timer = 1 and ID_object_picker > 0
if object exist(ID) = 0
Load_Object(ID_object_picker,ID)
color object ID,rgb(Array(ID).red,Array(ID).green,Array(ID).blue)
position object ID,Array(ID).xpos#+Mouse.Mobjx#,Array(ID).ypos#,Array(ID).zpos#-Mouse.Mobjy#
scale object ID,Array(ID).xsize#,Array(ID).ysize#,Array(ID).zsize#
if ID_object_picker = 1 or ID_object_picker = 3 then phy make rigid body dynamic box ID
if ID_object_picker = 2 then phy make rigid body dynamic sphere ID
endif
endif
endif
`*** delete objects and reset scene ***
if spacekey()=1
for c = 1 to ID
if object exist(c) = 1
phy delete rigid body c
Array(c).xpos# = 0
Array(c).ypos# = 0
Array(c).zpos# = 0
delete object c
endif
next c
ID = 0
endif
phy update
sync
loop
`*** load object ***
function Load_Object(ID_object_picker,ID)
if ID_object_picker = 0 then exitfunction
if ID_object_picker = 1
make object cube ID,1
Array(ID).Load_Object$ = "Cube"
endif
if ID_object_picker = 2
make object sphere ID,1
Array(ID).Load_Object$ = "Sphere"
endif
if ID_object_picker = 3
make object cylinder ID,1
set object ID,1,1,0
Array(ID).Load_Object$ = "Cylinder"
endif
endfunction
Help please! any one...
soul sucking devils, twisted body of the damed, slivering slim drips from every poor, sin licking at your ears, and the smell stinging your eyes, and if you don't like it, get out of my kitchen!