Hi there;
I wanna try to give a small contribute to the community with a small function that allows to create a pyramid with variable basis width, pyramid height and number of faces.
For higher values of number of faces, pyramid will look like to a cone.
Rem Project: Dark Basic Pro Project
Rem Created: Saturday, October 29, 2011
rem this code allows to create pyramids
sync on: sync rate 60
obj_num = 1
rem changing the value of the following 3 lines, you can change
rem the position of the object
xvertex = 0
yvertex = 0
zvertex = 0
rem changing the value of the next 3 lines, you can change
rem the aspect of the pyramid; for higher values it will
rem look like a cone
basis = 7: rem width of basis of every triangle
height = 100
sides = 40: rem for higher values, set an high height/basis ratio to avoid umbrella-like objects
image = 1
rem red texture; image=1
ink rgb(255,0,0),0
box 0,0,16,16
get image image,0,0,16,16
rem syntax for MAKE_OBJECT_PYRAMID(object_number, xvertex_position, yvertex_position, zvertex_position, basis_width, height, number_of_sides)
polygons = make_object_pyramid(obj_num,xvertex,yvertex,zvertex,basis,height,sides)
texture object obj_num,1
rotation = 0
angle#=300
ink rgb(200,200,200),0
position camera 0,0,0,-height
do
text 0,0,"Press 's' to start object rotation and 'o' to stop"
text 0,20,"Control camera using arrowkeys"
text 0,40,"Number of polygons: "+str$(polygons)
if inkey$()="s" then rotation=1
if inkey$()="o" then rotation=0
if rotation then inc angle#,.5
rotate object obj_num,angle#,0,0
control camera using arrowkeys 0,2,2
sync
loop
end
function make_object_pyramid(obj_num,xvertex,yvertex,zvertex,width,height,faces)
first_free_obj=faces+1001
rem shift the real middle Y axis of the object that will be created
yvertex=yvertex+(height/2)
rem arrays
dim x(int(faces))
dim y(int(faces))
dim z(int(faces))
rem divides X/Z plain in alpha# areas
alpha#=360.0/faces
rem determines radius from the center of the divided plain to a vertex of the base
radius#=(width/2)/sin(alpha#/2)
rem start point of the base
x(1)=radius#*cos(alpha#)
y(1)=yvertex-height
z(1)=radius#*sin(alpha#)
polygons = 2
for lato=2 to faces
rem other points of the base
x(lato)=radius#*cos(lato*alpha#)
y(lato)=y(1)
z(lato)=radius#*sin(lato*alpha#)
rem makes triangles with two points of the base and the vertex
make object triangle 1000+(lato-1),x(lato),y(lato),z(lato),x(lato-1),y(lato-1),z(lato-1),xvertex,yvertex,zvertex
rem makes triangles with two points of the base and one perpendicular to vertex
make object triangle first_free_obj+(lato-1),x(lato-1),y(lato-1),z(lato-1),x(lato),y(lato),z(lato),xvertex,y(1),zvertex
center text screen width()/2,screen height()/2,"wait while object "+str$(obj_num)+" is been created ("+str$((lato*100)/faces)+"%)"
sync
inc polygons, 2
next lato
rem makes the triangle with the first and the last point of the base an the vertex
make object triangle 1000,x(1),y(1),z(1),x(faces),y(faces),z(faces),xvertex,yvertex,zvertex
rem makes the triangle with the first and the last point of the base an the perpendicular of the vertex
make object triangle first_free_obj,x(faces),y(faces),z(faces),x(1),y(1),z(1),xvertex,y(1),zvertex
counter=0
rem SIDES
for i=1000 to 1000+(faces-1)
rem makes every object reflecting the light correctly
set object normals i
inc counter
make mesh from object counter,i
delete object i
next i
rem BASIS
for i=first_free_obj to first_free_obj+(faces-1)
rem makes every object reflecting the light correctly
set object normals i
inc counter
make mesh from object counter,i
delete object i
next i
delete object obj_num
rem first triangle of the new object
make object obj_num,1,0
rem add sides to limbs
for i=1 to faces-1
add limb obj_num,i,i+1
next i
rem add basis to limbs
for i=faces to (2*faces)-1
add limb obj_num,i,i+1
next i
set object cull obj_num,0
endfunction polygons
Rem ***** Main Source File *****