19th January 2009 16:41 UTC
wanna create a single cube
ok i give up i want to create a preset what relies on cubes so i wrote something and after 2 hours of searching what's wrong with this code (because it displays nothing instead of a cube) i decided to shout out loudly "HELP!":
first i wanted to define the cube by its width, height and depth (the first 3 values of cube() ) then define its position in "space" (cntrx,~y,~z) then comes its position in megabuf (idc) (if i wanted more cubes) and than the "global" offset in megabuf (offsc) (and there is an offs0 variable what is an offset for my hmm let's call it some kind of beat detection... simply ignore it now)
>>>> avstrans's code:
001 #define mb(a) megabuf(a)
002 #define gmb(a) gmegabuf(a)
003 #define cube(wdth,hght,dpth,cntrx,cntry,cntrz,idc,offsc)
mb(idc*24+offs0+offsc)=wdth*.5+cntrx;
mb(idc*24+offs0+offsc+1)=hght*.5+cntry;
mb(idc*24+offs0+offsc+2)=dpth*.5+cntrz;
mb(idc*24+offs0+offsc+3)=wdth*.5+cntrx;
mb(idc*24+offs0+offsc+4)=hght*.5+cntry;
mb(idc*24+offs0+offsc+5)=-dpth*.5+cntrz;
mb(idc*24+offs0+offsc+6)=wdth*.5+cntrx;
mb(idc*24+offs0+offsc+7)=-hght*.5+cntry;
mb(idc*24+offs0+offsc+8)=dpth*.5+cntrz;
mb(idc*24+offs0+offsc+9)=wdth*.5+cntrx;
mb(idc*24+offs0+offsc+10)=-hght*.5+cntry;
mb(idc*24+offs0+offsc+11)=-dpth*.5+cntrz;
mb(idc*24+offs0+offsc+12)=-wdth*.5+cntrx;
mb(idc*24+offs0+offsc+13)=hght*.5+cntry...
blablabla you can get the logic until mb(idc*24+offs0+offsc+23)
004 // read a vertex of a cube (idc is the cube "id", idcv is the chosen vertex of the cube)
005 #define cubvx(idc,idcv,offsc) mb(idc*24+offs0+offsc+max(idcv,7)*3)
006 #define cubvy(idc,idcv,offsc) mb(idc*24+offs0+offsc+max(idcv,7)*3+1)
007 #define cubvz(idc,idcv,offsc) mb(idc*24+offs0+offsc+max(idcv,7)*3+2)
>>>> triangle's code
>> init
001 n=12; zbuf=1; zbclear=1
>> frame
001 cube(getspec(cbls1,.01,0)*20,getspec(cbls2,.01,0)*20,getspec(cbls2,.01,0)*20,0,0,0,0,0);
002 rx=rx+rsp1*.1; ry=ry+rsp2*.1; rz=rz+rsp3*.1;
003 srx=sin(rx); crx=cos(rx); sry=sin(ry); cry=cos(ry); srz=sin(rz); crz=cos(rz);
004 trc=0; sw=0;
>> beat
001 cbsl1=rand(10)/20;
002 cbsl2=rand(10)/20;
003 cbsl2=rand(10)/20;
004 rsp1=rand(20)/20;
005 rsp2=rand(20)/20;
006 rsp3=rand(20)/20;
so because i'm not so smart i cannot came out a better solution than telling all the triangles one-by-one that which vertex should choose from the above defined cube:
>> triangle
001 x1=below(trc,6)*cubvx(0,0,0)+below(trc,12)*cubvx(0,7,0)+);
002 x2=
equal(trc,0)*cubvx(0,1,0)+
equal(trc,1)*cubvx(0,2,0)+
equal(trc,2)*cubvx(0,2,0)+
equal(trc,3)*cubvx(0,4,0)+
equal(trc,4)*cubvx(0,4,0)+
equal(trc,5)*cubvx(0,1,0)+
equal(trc,6)*cubvx(0,6,0)+
equal(trc,7)*cubvx(0,5,0)+
equal(trc,8)*cubvx(0,5,0)+
equal(trc,9)*cubvx(0,3,0)+
equal(trc,10)*cubvx(0,3,0)+
equal(trc,11)*cubvx(0,6,0);
003 x3=
equal(trc,0)*cubvx(0,3,0)+
equal(trc,1)*cubvx(0,3,0)+
equal(trc,2)*cubvx(0,6,0)+
equal(trc,3)*cubvx(0,6,0)+
equal(trc,4)*cubvx(0,5,0)+
equal(trc,5)*cubvx(0,5,0)+
equal(trc,6)*cubvx(0,4,0)+
equal(trc,7)*cubvx(0,4,0)+
equal(trc,8)*cubvx(0,1,0)+
equal(trc,9)*cubvx(0,1,0)+
equal(trc,10)*cubvx(0,2,0)+
equal(trc,11)*cubvx(0,2,0);
and so on for y1,2,3,z1,2,3 only difference is the cubvx changes to cubvy or cubvz
010 //and now comes the rotation (from the gvm-tools samples)
011 xa=x1*crz-y1*srz; ya=x1*srz+y1*crz; za=z1*cry-xa*sry;
x1=z1*sry+xa*cry; y1=ya*crx-za*srx; z1=ya*srx+za*crx;
xa=x2*crz-y2*srz; ya=x2*srz+y2*crz; za=z2*cry-xa*sry;
x2=z2*sry+xa*cry; y2=ya*crx-za*srx; z2=ya*srx+za*crx;
xa=x3*crz-y3*srz; ya=x3*srz+y3*crz; za=z3*cry-xa*sry;
x3=z3*sry+xa*cry; y3=ya*crx-za*srx; z3=ya*srx+za*crx;
012 xc=(x1+x2+x3)/3; yc=(y1+y2+y3)/3; zc=(z1+z2+z3)/3;
013 za=fov/(z1*fov2-dist); z2=fov/(z2*fov2-dist); z3=fov/(z3*fov2-dist);
014 z1=400+z1+z2+z3; x1=x1*za; y1=y1*za; x2=x2*z2; y2=y2*z2; x3=x3*z3; y3=y3*z3;
015 nx=band(equal(y1,y2),equal(y2,y3));
016 ny=band(equal(z1,z2),equal(z2,z3));
017 nz=band(equal(x1,x2),equal(x2,x3));
018 //rotating normals (i'm not sure if the above method is good i'm a dumb in math
(especially in calculating normals so i again told the values one-by-one))
019 xa=nx*crz-ny*srz; ya=nx*srz+ny*crz; za=nz*cry-xa*sry;
nx=nz*sry+xa*cry; ny=ya*crx-za*srx; nz=ya*srx+za*crx;
020 norm=invsqrt(sqr(xc)+sqr(yc)+sqr(zc));
021 xc=-xc*norm; yc=-yc*norm; zc=-zc*norm;
022 dot=xc*nx+yc*ny+zc*nz;
023 rx=2*nx-xc; ry=2*ny-yc; rz=2*nz-zc;
024 spec=xc*rx+yc*ry+zc*rz;
025 skip=below(dot,0);
026 dr=.7; dg=.7; db=.7;
027 dot=1*max(dot,0);
028 spec=1*pow(max(spec,0),32);
029 red1=dr*dot+spec; blue1=db*dot+spec; green1=dg*dot+spec;
030 trc=trc+1; sw=bnot(sw);
end
so i say big thanks to anybody who can help and i hope it's in the right place in the right form:confused: