Well, i was bored again, so i decided to create a 3d rotating box from scratch. I know that it's extremely pointless. this code is basically a wireframe view at
make object box 1,1,2,1
do
yrotate camera 0, camera angle y(0)+mousemovex()
xrotate camera 0, camera angle x(0)+mousemovey()
sync
loop
Here it is, and since it uses d3d_line, I'll upload the .exe attached (it has no media, so you can just say open from the web browser).
type matrix44
a1 as float
a2 as float
a3 as float
a4 as float
b1 as float
b2 as float
b3 as float
b4 as float
c1 as float
c2 as float
c3 as float
c4 as float
d1 as float
d2 as float
d3 as float
d4 as float
endtype
type vector
x as float
y as float
z as float
endtype
type myobj
p1 as vector
p2 as vector
p3 as vector
p4 as vector
p5 as vector
p6 as vector
p7 as vector
p8 as vector
endtype
global cube as myobj
global cube2 as myobj
global screenx as float
global screeny as float
//loooong list of coordinates describing a cube...
cube.p1.x=-1
cube.p1.y=-1
cube.p1.z=-1
cube.p2.x=1
cube.p2.y=-1
cube.p2.z=-1
cube.p3.x=1
cube.p3.y=-1
cube.p3.z=1
cube.p4.x=-1
cube.p4.y=-1
cube.p4.z=1
cube.p5.x=-1
cube.p5.y=1
cube.p5.z=-1
cube.p6.x=1
cube.p6.y=1
cube.p6.z=-1
cube.p7.x=1
cube.p7.y=1
cube.p7.z=1
cube.p8.x=-1
cube.p8.y=1
cube.p8.z=1
// values for the cube
xoff=0
yoff=0
zoff=20
xrot=rnd(360)
yrot=rnd(360)
zrot=rnd(360)
xscale=2
yscale=2
zscale=1
//values for the camera
global xoffc = 0
global yoffc=0
global zoffc=-5
global xrotc=0
global yrotc=0
global zrotc=0
global col as float
type matrix41
a1 as float
b1 as float
c1 as float
d1 as float
endtype
global arg1 as matrix44
global arg2 as matrix44
global arg3 as matrix41
global arg4 as vector
global ret1 as matrix44
global ret2 as matrix41
global ret3 as vector
matrixificateIt(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
//now the cube has been rotated, scaled, and translated as desired.
//Next, we need to get the points into the camera's point of view.
//This is done by translating the points so that the viewer is the origin,
//and then rotating the points by the camera's negative angle values.
matrixificateItCamStyle(xoffc,yoffc,zoffc,xrotc,yrotc,zrotc)
//w00t!!! Now all objects are in the camera's coordinates!
sync on
sync rate 20
global asaa
global asbb
global ascc
do
cls
inc xrotc,mousemovey()
inc yrotc,mousemovex()
if upkey() then inc asaa,5
if rightkey() then inc asbb,5
if leftkey() then inc ascc,5
if mouseclick()=1 then inc zoffc, 0.1
if mouseclick()=2 then dec zoffc, 0.1
matrixificateIt(0,0,5,asaa,asbb,ascc,01,2,1)
matrixificateItCamStyle(xoffc,yoffc,zoffc,xrotc,yrotc,zrotc)
cubedotatpoint(0.1,2000)
sync
loop
function dotAtPoint(x as float, y as float, z as float,d as float, s as float)
campoint_to_xy(x,y,z,d,s)
col=10-z
if col>10.0 then col=10.0
if col<3 then col=3
col=col/10.0*255.0
ink rgb(col,col,col),0
dot screenx+screen width()/2,screeny+screen height()/2
endfunction
function cubedotatpoint(d as float, s as float)
campoint_to_xy(cube2.p1.x,cube2.p1.y,cube2.p1.z,d,s)
cube2.p1.x=screenx
cube2.p1.y=screeny
cube2.p1.z=col
campoint_to_xy(cube2.p2.x,cube2.p2.y,cube2.p2.z,d,s)
cube2.p2.x=screenx
cube2.p2.y=screeny
cube2.p2.z=col
campoint_to_xy(cube2.p3.x,cube2.p3.y,cube2.p3.z,d,s)
cube2.p3.x=screenx
cube2.p3.y=screeny
cube2.p3.z=col
campoint_to_xy(cube2.p4.x,cube2.p4.y,cube2.p4.z,d,s)
cube2.p4.x=screenx
cube2.p4.y=screeny
cube2.p4.z=col
campoint_to_xy(cube2.p5.x,cube2.p5.y,cube2.p5.z,d,s)
cube2.p5.x=screenx
cube2.p5.y=screeny
cube2.p5.z=col
campoint_to_xy(cube2.p6.x,cube2.p6.y,cube2.p6.z,d,s)
cube2.p6.x=screenx
cube2.p6.y=screeny
cube2.p6.z=col
campoint_to_xy(cube2.p7.x,cube2.p7.y,cube2.p7.z,d,s)
cube2.p7.x=screenx
cube2.p7.y=screeny
cube2.p7.z=col
campoint_to_xy(cube2.p8.x,cube2.p8.y,cube2.p8.z,d,s)
cube2.p8.x=screenx
cube2.p8.y=screeny
cube2.p8.z=col
d3d_line cube2.p1.x,cube2.p1.y,cube2.p2.x,cube2.p2.y,rgb(0,cube2.p1.z,0),rgb(0,cube2.p2.z,0)
d3d_line cube2.p1.x,cube2.p1.y,cube2.p4.x,cube2.p4.y,rgb(0,cube2.p1.z,0),rgb(0,cube2.p4.z,0)
d3d_line cube2.p1.x,cube2.p1.y,cube2.p5.x,cube2.p5.y,rgb(0,cube2.p1.z,0),rgb(0,cube2.p5.z,0)
d3d_line cube2.p2.x,cube2.p2.y,cube2.p3.x,cube2.p3.y,rgb(0,cube2.p2.z,0),rgb(0,cube2.p3.z,0)
d3d_line cube2.p2.x,cube2.p2.y,cube2.p6.x,cube2.p6.y,rgb(0,cube2.p2.z,0),rgb(0,cube2.p6.z,0)
d3d_line cube2.p3.x,cube2.p3.y,cube2.p4.x,cube2.p4.y,rgb(0,cube2.p3.z,0),rgb(0,cube2.p4.z,0)
d3d_line cube2.p3.x,cube2.p3.y,cube2.p7.x,cube2.p7.y,rgb(0,cube2.p3.z,0),rgb(0,cube2.p7.z,0)
d3d_line cube2.p4.x,cube2.p4.y,cube2.p8.x,cube2.p8.y,rgb(0,cube2.p4.z,0),rgb(0,cube2.p8.z,0)
d3d_line cube2.p5.x,cube2.p5.y,cube2.p8.x,cube2.p8.y,rgb(0,cube2.p5.z,0),rgb(0,cube2.p8.z,0)
d3d_line cube2.p5.x,cube2.p5.y,cube2.p6.x,cube2.p6.y,rgb(0,cube2.p5.z,0),rgb(0,cube2.p6.z,0)
d3d_line cube2.p7.x,cube2.p7.y,cube2.p8.x,cube2.p8.y,rgb(0,cube2.p7.z,0),rgb(0,cube2.p8.z,0)
d3d_line cube2.p7.x,cube2.p7.y,cube2.p6.x,cube2.p6.y,rgb(0,cube2.p7.z,0),rgb(0,cube2.p6.z,0)
endfunction
function campoint_to_xy(x as float, y as float, z as float,d as float, s as float)
//if z>=d
screenx=d*x/z*s+screen width()/2
screeny=d*y/z*s+screen height()/2
//endif
col=6-z
if col>6.0 then col=6.0
if col<1 then col=1
col=col/10.0*255.0
endfunction
function matrixificateIt(xoff as float, yoff as float, zoff as float, xrot as float, yrot as float, zrot as float,xscale as float, yscale as float, zscale as float)
setpoint(cube.p1.x,cube.p1.y,cube.p1.z)
transform_point(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
getpoint()
cube2.p1=ret3
setpoint(cube.p2.x,cube.p2.y,cube.p2.z)
transform_point(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
getpoint()
cube2.p2=ret3
setpoint(cube.p3.x,cube.p3.y,cube.p3.z)
transform_point(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
getpoint()
cube2.p3=ret3
setpoint(cube.p4.x,cube.p4.y,cube.p4.z)
transform_point(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
getpoint()
cube2.p4=ret3
setpoint(cube.p5.x,cube.p5.y,cube.p5.z)
transform_point(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
getpoint()
cube2.p5=ret3
setpoint(cube.p6.x,cube.p6.y,cube.p6.z)
transform_point(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
getpoint()
cube2.p6=ret3
setpoint(cube.p7.x,cube.p7.y,cube.p7.z)
transform_point(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
getpoint()
cube2.p7=ret3
setpoint(cube.p8.x,cube.p8.y,cube.p8.z)
transform_point(xoff,yoff,zoff,xrot,yrot,zrot,xscale,yscale,zscale)
getpoint()
cube2.p8=ret3
endfunction
function matrixificateItCamStyle(xoff as float, yoff as float, zoff as float, xrot as float, yrot as float, zrot as float)
setpoint(cube2.p1.x,cube2.p1.y,cube2.p1.z)
transform_point2(xoff,yoff,zoff,xrot,yrot,zrot)
getpoint()
cube2.p1=ret3
setpoint(cube2.p2.x,cube2.p2.y,cube2.p2.z)
transform_point2(xoff,yoff,zoff,xrot,yrot,zrot)
getpoint()
cube2.p2=ret3
setpoint(cube2.p3.x,cube2.p3.y,cube2.p3.z)
transform_point2(xoff,yoff,zoff,xrot,yrot,zrot)
getpoint()
cube2.p3=ret3
setpoint(cube2.p4.x,cube2.p4.y,cube2.p4.z)
transform_point2(xoff,yoff,zoff,xrot,yrot,zrot)
getpoint()
cube2.p4=ret3
setpoint(cube2.p5.x,cube2.p5.y,cube2.p5.z)
transform_point2(xoff,yoff,zoff,xrot,yrot,zrot)
getpoint()
cube2.p5=ret3
setpoint(cube2.p6.x,cube2.p6.y,cube2.p6.z)
transform_point2(xoff,yoff,zoff,xrot,yrot,zrot)
getpoint()
cube2.p6=ret3
setpoint(cube2.p7.x,cube2.p7.y,cube2.p7.z)
transform_point2(xoff,yoff,zoff,xrot,yrot,zrot)
getpoint()
cube2.p7=ret3
setpoint(cube2.p8.x,cube2.p8.y,cube2.p8.z)
transform_point2(xoff,yoff,zoff,xrot,yrot,zrot)
getpoint()
cube2.p8=ret3
endfunction
function transform_point(xoff as float, yoff as float, zoff as float, xrot as float, yrot as float, zrot as float,xscale as float, yscale as float, zscale as float)
arg1.a1=1 : arg1.a2=0 : arg1.a3=0 : arg1.a4=xoff
arg1.b1=0 : arg1.b2=1 : arg1.b3=0 : arg1.b4=yoff
arg1.c1=0 : arg1.c2=0 : arg1.c3=1 : arg1.c4=zoff
arg1.d1=0 : arg1.d2=0 : arg1.d3=0 : arg1.d4=1
setrot(xrot,yrot,zrot)
arg2=ret1
mult4444()
arg1=ret1
scale(xscale,yscale,zscale)
arg1=ret1
mult4441()
endfunction
function transform_point2(xpos as float, ypos as float, zpos as float, xrot as float, yrot as float, zrot as float)
dec arg3.a1,xpos
dec arg3.b1,ypos
dec arg3.c1,zpos
arg3.d1=1 //just ta make sure
//now the camera is the origin
setrot(-xrot,-yrot,-zrot)
arg1=ret1
mult4441()
cls
text 0,0,str$(ret2.d1)
endfunction
function setpoint(x as float,y as float, z as float) //returns arg3
arg3.a1=x
arg3.b1=y
arg3.c1=z
arg3.d1=1
endfunction
function getpoint()
ret3.x=ret2.a1
ret3.y=ret2.b1
ret3.z=ret2.c1
endfunction
remstart
never used
function offset(xoff as float, yoff as float, zoff as float)//arg1 returns ret1
arg2.a1=1 : arg2.a2=0 : arg2.a3=0 : arg2.a4=xoff
arg2.b1=0 : arg2.b2=1 : arg2.b3=0 : arg2.b4=yoff
arg2.c1=0 : arg2.c2=0 : arg2.c3=1 : arg2.c4=zoff
arg2.d1=0 : arg2.d2=0 : arg2.d3=0 : arg2.d4=1
mult4444()
endfunction
remend
function scale(xscale as float, yscale as float, zscale as float)//arg1 returns ret1
arg2.a1=xscale : arg2.a2=0 : arg2.a3=0 : arg2.a4=0
arg2.b1=0 : arg2.b2=yscale : arg2.b3=0 : arg2.b4=0
arg2.c1=0 : arg2.c2=0 : arg2.c3=zscale : arg2.c4=0
arg2.d1=0 : arg2.d2=0 : arg2.d3=0 : arg2.d4=1
mult4444()
endfunction
function setrot(xrot as float, yrot as float, zrot as float)
//if type arguments were allowed, it'd be...
//mult4444(mult4444(setzrot(zrot),setyrot(yrot)),setxrot(xrot))
setzrot(zrot)
arg1=ret1
setyrot(yrot)
arg2=ret1
mult4444()
arg1=ret1
setxrot(xrot)
arg2=ret1
mult4444()
endfunction
function setxrot(xrot as float) // returns ret1
ret1.a1=1 : ret1.a2=0 : ret1.a3=0 : ret1.a4=0
ret1.b1=0 : ret1.b2=cos(xrot) : ret1.b3=-sin(xrot) : ret1.b4=0
ret1.c1=0 : ret1.c2=sin(xrot) : ret1.c3=cos(xrot) : ret1.c4=0
ret1.d1=0 : ret1.d2=0 : ret1.d3=0 : ret1.d4=1
endfunction
function setyrot(yrot as float)// returns ret1
ret1.a1=cos(yrot) : ret1.a2=0 : ret1.a3=sin(yrot) : ret1.a4=0
ret1.b1=0 : ret1.b2=1 : ret1.b3=0 : ret1.b4=0
ret1.c1=-sin(yrot) : ret1.c2=0 : ret1.c3=cos(yrot) : ret1.c4=0
ret1.d1=0 : ret1.d2=0 : ret1.d3=0 : ret1.d4=1
endfunction
function setzrot(zrot as float)// returns ret1
ret1.a1=cos(zrot) : ret1.a2=-sin(zrot): ret1.a3=0 : ret1.a4=0
ret1.b1=sin(zrot) : ret1.b2=cos(zrot) : ret1.b3=0 : ret1.b4=0
ret1.c1=0 : ret1.c2=0 : ret1.c3=1 : ret1.c4=0
ret1.d1=0 : ret1.d2=0 : ret1.d3=0 : ret1.d4=1
endfunction
function mult4444() ///reeeealallllllly bulky matrix multiplication code o.O
//arg1 X arg2 returns ret1
ret1.a1=arg1.a1*arg2.a1 + arg1.a2*arg2.b1 + arg1.a3*arg2.c1 + arg1.a4*arg2.d1
ret1.a2=arg1.a1*arg2.a2 + arg1.a2*arg2.b2 + arg1.a3*arg2.c2 + arg1.a4*arg2.d2
ret1.a3=arg1.a1*arg2.a3 + arg1.a2*arg2.b3 + arg1.a3*arg2.c3 + arg1.a4*arg2.d3
ret1.a4=arg1.a1*arg2.a4 + arg1.a2*arg2.b4 + arg1.a3*arg2.c4 + arg1.a4*arg2.d4
ret1.b1=arg1.b1*arg2.a1 + arg1.b2*arg2.b1 + arg1.b3*arg2.c1 + arg1.b4*arg2.d1
ret1.b2=arg1.b1*arg2.a2 + arg1.b2*arg2.b2 + arg1.b3*arg2.c2 + arg1.b4*arg2.d2
ret1.b3=arg1.b1*arg2.a3 + arg1.b2*arg2.b3 + arg1.b3*arg2.c3 + arg1.b4*arg2.d3
ret1.b4=arg1.b1*arg2.a4 + arg1.b2*arg2.b4 + arg1.b3*arg2.c4 + arg1.b4*arg2.d4
ret1.c1=arg1.c1*arg2.a1 + arg1.c2*arg2.b1 + arg1.c3*arg2.c1 + arg1.c4*arg2.d1
ret1.c2=arg1.c1*arg2.a2 + arg1.c2*arg2.b2 + arg1.c3*arg2.c2 + arg1.c4*arg2.d2
ret1.c3=arg1.c1*arg2.a3 + arg1.c2*arg2.b3 + arg1.c3*arg2.c3 + arg1.c4*arg2.d3
ret1.c4=arg1.c1*arg2.a4 + arg1.c2*arg2.b4 + arg1.c3*arg2.c4 + arg1.c4*arg2.d4
ret1.d1=arg1.d1*arg2.a1 + arg1.d2*arg2.b1 + arg1.d3*arg2.c1 + arg1.d4*arg2.d1
ret1.d2=arg1.d1*arg2.a2 + arg1.d2*arg2.b2 + arg1.d3*arg2.c2 + arg1.d4*arg2.d2
ret1.d3=arg1.d1*arg2.a3 + arg1.d2*arg2.b3 + arg1.d3*arg2.c3 + arg1.d4*arg2.d3
ret1.d4=arg1.d1*arg2.a4 + arg1.d2*arg2.b4 + arg1.d3*arg2.c4 + arg1.d4*arg2.d4
endfunction
function mult4441() //arg1 X arg3 returns ret2
ret2.a1=arg1.a1*arg3.a1 + arg1.a2*arg3.b1 + arg1.a3*arg3.c1 + arg1.a4*arg3.d1
ret2.b1=arg1.b1*arg3.a1 + arg1.b2*arg3.b1 + arg1.b3*arg3.c1 + arg1.b4*arg3.d1
ret2.c1=arg1.c1*arg3.a1 + arg1.c2*arg3.b1 + arg1.c3*arg3.c1 + arg1.c4*arg3.d1
ret2.d1=arg1.d1*arg3.a1 + arg1.d2*arg3.b1 + arg1.d3*arg3.c1 + arg1.d4*arg3.d1
endfunction
The code is a bit... wierd. this is due to two things. One is that functions can't return user defined types, or accept them as arguments, so i had to make a bunch of global variables just to return numbers. The other is that i decided to write my own code for matrix multiplication. I figure that using the ones built into DBP would be cheating
use the arrowkeys to rotate the box, mouse move to look around.
The shading on the lines (why i used d3d_line) is to give the user a sense of depth. Without it, the shapes can play some wierd tricks on your mind. One second it can look like a 3d box, the next a bunch of wierd stretchy lines. I actually thought i had coded something horribly wrong before i realized it was my sense of depth that was off. If you want to see how it looks without shading, look behind you (in the program o'course

).
I do think there is one error with translations though. I can't really seem to get movement to work, but i haven't really tried to debug it.