News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

can't get RayIntersectWorld to work

Started by monkeybot, March 06, 2011, 06:48:30 PM

Previous topic - Next topic

monkeybot

i can't get RayIntersectWorld  to work......


PlayBASIC Code: [Select]
explicit on
global world=newWorld()
global cam=newcamera()
global bs,x,y,x2,y2;,gx#,gy#
global bx,by
setfps(30)
print "Create a line"
print "press left mouse"
sync
repeat
bs= MouseButton()
if bs=1
checkMb()
repeat
bs= MouseButton()
if bs=1 then bx=mousex():by=mousey()
until bs=1
endif
until bs=1

do
CaptureToscene
ClsScene

CameraGrabWorld cam,world
doball()

checkball()
drawcamera cam
sync
loop

Function checkMb()
local gx#,gy#
FlushMouse
x=mousex()
y=mousey()
Cls
print "press right mouse"
sync
repeat
bs= MouseButton()
x2=mousex()
y2=mousey()
until bs=2
gx#=x2-x
gy#=y2-y
print "x:"+str$(gx#) + " y:"+str$(gy#) + " gradient:"+str$(gx#/gy#)
print "place ball then left button"
line x,y,x2,y2
sync
capturetoworld world
line x,y,x2,y2
partitionworld world,32
EndFunction

Function checkball()
if RayIntersectWorld(world,bx,by,bx,by+20)=true
end
endif
line bx,by,bx,by+20
EndFunction

function doball()
circle bx,by,10,0
by=by+5
EndFunction






kevin

#1
 The wall is defined back to front.  

PlayBASIC Code: [Select]
   capturetoworld world   
; line x,y,x2,y2
line x2,y2,x,y

partitionworld world,32




monkeybot


monkeybot

#3
i can't get rayintersect working in a different situation.

I am drawing the square to a world(wld) and i cant work out why rayintersect isn't working....again.Doh!

PlayBASIC Code: [Select]
explicit on 



global cam

cam=newcamera()
global wld=GetFreeWorld()
CreateWorld wld


CaptureToWorld wld
text 0,0,"world "
box 100,100,200,200,1
partitionworld wld,32
DrawGFXImmediate
repeat
;DrawGFXImmediate
; RenderToScreen
; text 0,0,"Actual screen"
capturetoscene
clsscene
CameraGrabWorld cam,wld
; if spacekey() then MoveCamera cam,10,0
raytest()
drawcamera cam
sync
until false
end


Function raytest()
local rayA,x#,y#
for rayA= 0 to 359 step 360/8
x#=mousex()
y#=mousey()
if RayIntersectWorld(wld ,x#,y# ,x#+sin(rayA)*40 ,y#+cos(rayA)*40 )
end
endif
line x#,y#,x#+sin(rayA)*40,y#+cos(rayA)*40
next
;sync
endfunction





monkeybot

i worked it out.you can only use lines,i thought it would work on anything drawn to the world.