Drawing a Spherical Mesh
01-20-2014, 10:27 PM (This post was last modified: 01-20-2014 10:31 PM by cyrille de brébisson.)
Post: #4
 cyrille de brébisson Senior Member Posts: 1,047 Joined: Dec 2013
RE: Drawing a Spherical Mesh
Hello,

A couple of problems in your code...
First, your coordinates are in cartesian coordinates, from -1 to 1...
you should use triangle instead of triangle_p. Make sure that you set the xmin/xmax, ymin, ymax to -1, 1, -1, 1 if you want to see something...

ndiv=12 correspond to a HUGE number of triangles. put it to 6 or so to get started and debug... it does work with 12, but takes a LOT of time...

Code:

XX=.525731112119133606;
ZZ=.850650808352039932;
vdata={
{-XX, 0.0, ZZ}, {XX, 0.0, ZZ}, {-XX, 0.0, -ZZ}, {XX, 0.0, -ZZ},
{0.0, ZZ, XX}, {0.0, ZZ, -XX}, {0.0, -ZZ, XX}, {0.0, -ZZ, -XX},
{ZZ, XX, 0.0}, {-ZZ, XX, 0.0}, {ZZ, -XX, 0.0}, {-ZZ, -XX, 0.0}
};
tindices = {
{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
{8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
{7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
{6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };

normalize(aa)
begin
local dd;
dd:=sqrt(aa(1)*aa(1)+aa(2)*aa(2)+aa(3)*aa(3));
aa(1):=aa(1)/dd; aa(2):=aa(2)/dd; aa(3):=aa(3)/dd;
return aa;
end;

drawtri(aa,bb,cc,div,r)
begin
local ab={},ac={},bc={};
local grey,i;

grey:=rgb(25,125,25);
if div <= 0 then

triangle({aa(1),aa(2),grey,aa(3)},{bb(1),bb(2),grey,bb(3)},{cc(1),cc(2),gre​y,cc(3)});
//kill;
else
for i from 1 to 3 do
ab(i):=(aa(i)+bb(i))/2;
ac(i):=(aa(i)+cc(i))/2;
bc(i):=(bb(i)+cc(i))/2;
end;
ab:=normalize(ab);
ac:=normalize(ac);
bc:=normalize(bc);
drawtri(aa,ab,ac,div-1,r);
drawtri(bb,bc,ab,div-1,r);
drawtri(cc,ac,bc,div-1,r);
drawtri(ab,bc,ac,div-1,r);
end;
end;

export drawSphere()
begin
local white;

white:=rgb(255,255,255);
dimgrob_p(G1,320,240,white);
rect_p;

for i from 1 to 20 do
drawtri(vdata(tindices(i,1)+1),
vdata(tindices(i,2)+1),
end;
//    blit_p(G0,G1);
end;

If it still does not work, it might be due to confusion on the triangle inputs with the other forms (for full 3D drawing). Since my version of the app is later than the one that you have, I do not remember exactly how it was before...
you could try a form along the lines of:
triangle(x1, y1, z2, x2, y2, z2, x3, y3, z3, c1, c2, c3);

Cyrille
 « Next Oldest | Next Newest »

 Messages In This Thread Drawing a Spherical Mesh - jgreenb2 - 01-20-2014, 08:07 PM RE: Drawing a Spherical Mesh - Han - 01-20-2014, 09:47 PM RE: Drawing a Spherical Mesh - jgreenb2 - 01-20-2014, 09:58 PM RE: Drawing a Spherical Mesh - cyrille de brébisson - 01-20-2014 10:27 PM RE: Drawing a Spherical Mesh - jgreenb2 - 01-21-2014, 12:15 AM RE: Drawing a Spherical Mesh - patrice - 01-21-2014, 01:08 AM RE: Drawing a Spherical Mesh - patrice - 01-23-2014, 10:11 PM

User(s) browsing this thread: 1 Guest(s)