I am working on a project that will eventually use raycasting for collision, since sparky's doesn't seem to like sliding collision. My solution has been to cast multiple rays from each face to detect for collision at different points.
This program was a test one that I wrote that should place spheres at each point for the ray (a + on the face). My problem is that when turning the object, the spheres will turn with the object for a little bit, then rotate the wrong way until they hit the right point again (run the program if you are confused)
Here is the code:
Make object box 65535,20,60,10
Dim ObjectColPoints(65535,6,5)
For i=1 to 5
make object sphere i,1
NEXT i
Front=1
Left=2
Back=3
Right=4
Top=5
Bottom=6
ObjectColpoints(65535,Front,1)=rgb(100,100,105)
ObjectColPoints(65535,Front,2)=rgb(100,130,105)
ObjectColPoints(65535,Front,3)=rgb(100,70,105)
ObjectColPoints(65535,Front,4)=rgb(90,100,105)
ObjectColPoints(65535,Front,5)=rgb(110,100,105)
DO
angle#=angle#+mousemovex()
SET CAMERA TO FOLLOW Object Position X(65535),Object Position Y(65535),Object Position Z(65535),angle#,60,Object Position y(65535)+10,1.0,0
angle2#=wrapvalue(object angle y(65535))
FOR i= 1 to 5
xdiff#=(rgbr(ObjectColPoints(65535,Front,i))-100)*cos(angle2#)-(rgbb(ObjectColPoints(65535,Front,i))-100)*sin(angle2#)
ydiff#=(rgbg(ObjectColPoints(65535,Front,i))-100)
zdiff#=(rgbr(ObjectColPoints(65535,Front,i))-100)*sin(angle2#)+(rgbb(ObjectColPoints(65535,Front,i))-100)*cos(angle2#)
position object i,object position x(65535)+xdiff#,object position x(65535)+ydiff#,object position x(65535)+zdiff#
Next
if rightkey()=1 then turn object right 65535,.1
if leftkey()=1 then turn object left 65535,.1
LOOP
Notes on the code:
-I was lazy and decided to store the initial offset values in one number using RGB (I didn't feel like 3 lines of code for each point)
-The "center" point for the rgb values is (100,100,100). I did this since you can't put negative values in. The solution was just to subtract 100 from the rgb values (so instead of -30, I put 70 and later subtract 100 from it).
-The Xdiff# and Zdiff# equations that have the xcos-zsin and xsin+zcos come from a rotation matrix:
|cos -sin|
|sin cos| Which gets multiplied by the normal offsets to find the new ones. If you aren't familiar with the math, assume its right.
Thanks
Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose