Pyramid function by Sach7th Jul 2009 19:06
|
---|
Summary The code will create a pyramid mede out of triangles instead of boxes for smooth surfaces. I the MergeObjects function is based on something I found in the DB forums, but I can't r Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com sync on; sync rate 60 Pyramid(1,5,2,6,0,0.1,0) repeat until spacekey()=1 delete object 1 end rem Merges objects O1 and O2 into the resulting object Obj. rem If DelOld is set to 1, O1 and O2 will be deleted. function MergeObjects(O1,O2,Obj,DelOld) Make Mesh From Object 1,O1 Lock Vertexdata For Mesh 1 Make Mesh From Object 2,O2 Add Mesh To Vertexdata 2 Delete Mesh 2 Unlock Vertexdata Make Object Obj,1,0 delete mesh 1 if DelOld=1 delete object O1 delete object O2 endif Endfunction rem This merges objects, provided that they are all in the interval between rem OStart and OEnd, and it is all put in the resulting object Obj. function MergeMultipleObjects(OStart,OEnd,Obj) Obs1=OEnd-OStart+1 Obs2=Obs1-1 j=OEnd+1 for i=OStart to (OEnd+Obs2-1) step 2 MergeObjects(i,i+1,j,1) j=j+1 if j=(OEnd+Obs2) then j=Obj next i endfunction rem This draws the pyramid (or any other object with three or more corners in the base). rem Obj is the object number, Sides is number of corners/sides in the base of the pyramid. rem Radius# determines how far from the center of the pyramid the base corners are rem located. Height is obviously what it sounds like - distance from base to top, rem and the last three positions the object. function Pyramid(Obj,Sides,Radius#,Height#,Xp#,Yp#,Zp#) if Sides<3 then exitfunction Angle#=360/Sides for i=1 to Sides make object triangle Obj+1,(Radius#*sin(0+((i-1)*Angle#))),0,(Radius#*cos(0+((i-1)*Angle#))),0,Height#,0,(Radius#*sin(0+((i)*Angle#))),0,(Radius#*cos(0+((i)*Angle#))) make object triangle Obj+2,0,0,0,(Radius#*sin(0+((i-1)*Angle#))),0,(Radius#*cos(0+((i-1)*Angle#))),(Radius#*sin(0+((i)*Angle#))),0,(Radius#*cos(0+((i)*Angle#))) MergeObjects(Obj+1,Obj+2,Obj+2+i,1) next i MergeMultipleObjects(Obj+3,Obj+2+Sides,Obj) position object Obj,Xp#,Yp#,Zp# Endfunction |