TGC Codebase Backup



Function to work out the normals data of any face by eat much pie

3rd May 2004 5:35
Summary

This function will work out the normals data of the face between two world coord's.



Description

You must put the following code at the beginning of your program:

null = make vector3(1)
null = make vector3(2)
make object cube 30,0
make object cube 31,0
make object cube 32,0



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `You must put the following code at the beginning of your program (minus the rem's):
rem null = make vector3(1)
rem null = make vector3(2)
rem make object cube 30,0
rem make object cube 31,0
rem make object cube 32,0

`the actual function follows.  Put it outside of the main loop

function normals(obj,x#,y#,z#,endx#,endy#,endz#)

position object 30,x#,y#,z#
point object 30,endx#,endy#,endz#

position object 31,object position x(30),object position y(30),object position z(30)
set object to object orientation 31,30
move object up 31,0.1

position object 32,object position x(30),object position y(30),object position z(30)
set object to object orientation 32,30
move object right 32,0.1

x1#=object position x(30)
x2#=object position x(31)
x3#=object position x(32)

y1#=object position y(30)
y2#=object position y(31)
y3#=object position y(32)

z1#=object position z(30)
z2#=object position z(31)
z3#=object position z(32)

set vector3 1,0,0,0
set vector3 2,0,0,0

set vector3 1,x2#-x1#,y2#-y1#,z2#-z1#
set vector3 2,x3#-x1#,y3#-y1#,z3#-z1#

col=0

for t=0 to 2
if t=0 then k#=intersect object(obj,object position x(30+t),object position y(30+t),object position z(30+t),endx#,endy#,endz#)
if t=1 then k#=intersect object(obj,object position x(30+t),object position y(30+t),object position z(30+t),endx#+x vector3(1),endy#+y vector3(1),endz#+z vector3(1))
if t=2 then k#=intersect object(obj,object position x(30+t),object position y(30+t),object position z(30+t),endx#+x vector3(2),endy#+y vector3(2),endz#+z vector3(2))
move object 30+t,k#
if k#>0 then col=col+1
next t

if col=3

x1#=object position x(30)
x2#=object position x(31)
x3#=object position x(32)

y1#=object position y(30)
y2#=object position y(31)
y3#=object position y(32)

z1#=object position z(30)
z2#=object position z(31)
z3#=object position z(32)

xvec1#=x2#-x1#
xvec2#=x3#-x1#
yvec1#=y2#-y1#
yvec2#=y3#-y1#
zvec1#=z2#-z1#
zvec2#=z3#-z1#

set vector3 1,xvec1#,yvec1#,zvec1#
set vector3 2,xvec2#,yvec2#,zvec2#

cross product vector3 2, 1, 2

normalize vector3 2,2

endif

endfunction