|
terrain drawing without sorting - uses camera azimuth |
altalena
Member #13,639
October 2011
|
Here's the program I was working on until Skyrim came along and stole all my time. I just fixed a bit of the terrain generation code. The camera rotation now uses a function to cut down on the number of lines of code. The .exe should work OK for windows 7. It's all my original code from scratch, except for the Mersenne Twister algorithm and some help with the Perlin noise 2d algorithm from SiegeLord. Edgar Reynaldo pointed out how to speed up the pixel drawing. ...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270 ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3 |
Edgar Reynaldo
Major Reynaldo
May 2007
|
So you draw the terrain from highest azimuth to lowest? How do you deal with two sections of terrain that pass through the same ray as cast from the camera? The terrain looks neat though. I used to have a fractal terrain generator program that I loved to mess with all the time. NSND[1] The large triangles in the upper middle look a little funny though - are they closer than the rest of the triangles, or are they larger and farther away? References
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
altalena
Member #13,639
October 2011
|
I don't really know what ray casting is, but I'll show you how I made it sort the terrain without needing a sort function. It still can draw the two triangles of each terrain square in the wrong order. I should fix that. OK. I first had it draw the terrain in a simple 2-level nested for loop with 0-32 and 0-32. Then I noticed that from a certain range of angles (1/4 of camera rotation) the terrain drew closer squares on top of farther squares. I reversed the order for the opposite 1/4 of the camera rotation, going from 32-0 and 32-0. I then tried to use a nested for loop going from 0-32 and 32-0 for one way and 32-0 and 0-32 for the other way, for the remaining 2 quarters of the rotation, but it didn't work. I switched the outer for loop's counter variable with the inner for loop's variable, then made it shorter by using the m2 and m3, but switching to m3 and m2. Here's the final code. 1 camdir=0; // terrain is drawn in a specific order based on camera azimuth
2 if (ra__cam[3]>=051&&ra__cam[3]<151) camdir=3;
3 if ((ra__cam[3]>=351&&ra__cam[3]<=400)||(ra__cam[3]>=000&&ra__cam[3]<051)) camdir=2;
4 if (ra__cam[3]>=251&&ra__cam[3]<351) camdir=1;
5 if (ra__cam[3]>=151&&ra__cam[3]<251) camdir=0;
6
7 m2 = 0;
8 m3 = 0;
9 if (camdir==0) m2=0;
10 if (camdir==2) m2=31;
11 if (camdir==3) m3=0;
12 if (camdir==1) m3=31;
13 for (n2=0; n2<=31; n2+=1)
14 {
15 if (camdir==0) m3=0;
16 if (camdir==2) m3=31;
17 if (camdir==3) m2=0;
18 if (camdir==1) m2=31;
19 for (n3=0; n3<=31; n3+=1)
20 {
21
22 // terrain drawing goes here
23
24 if (camdir==0) m3+=1; // draws terrain in the correct order
25 if (camdir==2) m3-=1; // the m2 and m3 variables are important here
26 if (camdir==3) m2+=1;
27 if (camdir==1) m2-=1;
28 }
29 if (camdir==0) m2+=1;
30 if (camdir==2) m2-=1;
31 if (camdir==3) m3+=1;
32 if (camdir==1) m3-=1;
33 }
...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270 ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3 |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I haven't the faintest idea what m2 and m3 are for there. Simply, what are the logical rules you use to determine terrain order? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
altalena
Member #13,639
October 2011
|
when the terrain draws in this order 01 - 02 - 03 - 04 it looks correct from 1/4 of the camera rotations. Note that for every square, the three that are behind - the ones above, to the left, and to the top left - are drawn before it. From the opposite 1/4 of camera angles, 16 - 15 - 14 - 13 looks correct. From the other two quarters of camera angles, the orders are 04 - 08 - 12 - 16 and 13 - 09 - 05 - 01 See how squares get drawn over squares that are farther away? The m2 and m3 are the x and y coordinates of the corner point of the square on the 33x33 mesh that is used to draw the two triangles of the terrain square ...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270 ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3 |
|