Quote: "Someone please just write a function to get the angle of the face the ray is colliding with."
The normal is the vector - the direction of the face the ray is colliding with. Since it is 3d, there are actually three angles that could represent the vector's angular orientation in world space. And depending on the order of rotation, the angle combination (x,y and z) could be anything - so the easiest way to represent the normal, is by a vector.
If you have to represent it by angles, then you might take the approach TheComet was suggesting - but you could make it a little easier on yourself.
Based on the example that comes with Sparky's (where the planes are angled according to the ray collision), create a dummy object, place it at the center of the object that the ray is colliding with, get the normal coordinates of the ray collision, and use POINT OBJECT to point the dummy object at the x,y and z of the normal. Then use OBJECT ANGLE X() y and z of the dummy object to get the x,y and z angle of the normal.
Quote: "I am interested though how the normals work."
The normal is a perpendicular to a face - it's 90 degrees away projected away from a face. The normal determines how light is reflected from the face for color and lighting effects. A vertex normal is the average face normals of faces that share the same vertex. Just remember a normal is a vector 90 degrees from the face. It tells the direction a face is facing.
Quote: "Bump. I saw in the example a mention of getCollisionBounceX(), but I couldn't find that function anywhere!"
The functions:
function getCollisionBounceX()
result#=call dll(1,"getCollisionBounceX")
endfunction result#
function getCollisionBounceY()
result#=call dll(1,"getCollisionBounceY")
endfunction result#
function getCollisionBounceZ()
result#=call dll(1,"getCollisionBounceZ")
endfunction result#
And an example: move the mouse around to position a big sphere on the screen. From the big sphere a ray is cast towards the cube in the center. The ray will reflect when hitting the cube and the resulting vector will be where the little sphere ends up.
remstart
==============================================================
= Title : ricochet test
= Author : Latch
= Date : 07/31/2009
= Update :
= Version: .01
==============================================================
Comments bounce vector using sparkys dll
==============================================================
remend
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
autocam off
set display mode 800,600,32
sync on
sync rate 60
hide mouse
#include "DBCcollisions.dba"
rem =============================================================
rem = MAIN
rem =============================================================
_main:
gosub _init
do
gosub _move_sphere
gosub _bounce
sync
loop
end
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
_init:
rem make a few objects
make object cube 1,25
setupObjectDBC(1,0,2)
make object sphere 2,25
set object collision off 2
make object sphere 3,5
set object collision off 3
rem position camera
position camera 0,0,-150
return
`----------------------------------------------------------------
_move_sphere:
x1#=object position x(2)+mousemovex()
y1#=object position y(2)-mousemovey()
z1#=object position z(2)
position object 2,x1#,y1#,z1#
x2#=object position x(1)
y2#=object position y(1)
z2#=object position z(1)
return
`----------------------------------------------------------------
_bounce:
rem cast ray from big sphere towards cube
bang=intersectObjectDBC(1,0,x1#,y1#,z1#,x2#,y2#,z2#,0)
rem get bounce vector
if bang
x3#=getCollisionBounceX()
y3#=getCollisionBounceY()
z3#=getCollisionBounceZ()
endif
rem position the little sphere at the bounce position
position object 3,x3#,y3#,z3#
rem draw lines between objects to show reflection
ink rgb(255,255,0),0
line object screen x(2),object screen y(2),object screen x(1),object screen y(1)
ink rgb(255,0,0),0
line object screen x(1),object screen y(1),object screen x(3),object screen y(3)
return
Enjoy your day.