Thanks Graham,
Sorry, I guess I didn't explain my code very well. It's hard sometimes to figure out what is relevant and what is not.
Unfortunatley, some of your assumptions are wrong, so your code fragments aren't right. I'll try to clarify a bit.
Quote:
1) The "index" is an index into a linear framebuffer/pixelbuffer/bitmap and basically tells you which memory address to color, and therefore is relative to the start of the framebuffer rather than the start of the row.
No. None of the code I have shown has anything to do with the drawing routines, it's a level above that. I have omitted the code controlling the drawing of the map, as I don't think it is relevant. So don't think in terms of pixel buffers or frame buffers.
Index is simply a reference into a set of points (actually a vector of a class that holds data about each individual point). The points go from 0 (which will be found at the north pole) to roughly 411,000 (which is found at the south pole). It is strictly sequential, there is no projection of any sort associated with these points.
The Mollweide projection, as you surmised, comes from the MapExtents vector, which tells the program how many of those points are in each row (so, since there is exactly 1 point in the first row, MapExtents[0] is 1. MapExtents[1] is 90, there being 90 points in the second row, and so on for all the rest of the rows.
The calculation for MapExtents is probably irrelevent, but just in case, it looks like this:
WorldBuilderRow = 0.0; while (WorldBuilderRow < 2.0 * WORLDBUILDER_WORLD_RADIUS) { //Get the circumference of the horizontal circle at this lattitude Circumference = 2.0 * PI * sqrt((2.0 * WORLDBUILDER_WORLD_RADIUS * WorldBuilderRow) - (WorldBuilderRow*WorldBuilderRow)); NumPointsInRow = RoundFloatToInt(Circumference); if (NumPointsInRow == 0) NumPointsInRow = 1; MapExtents.push_back(NumPointsInRow); WorldBuilderRow += (2.0/PI); }
The radius (a constant) is set such that there ends up being exactly 512 rows, with the circumference at the equator as 1024 points. Anyway, that is where the projection comes from.
FirstPointInRow is simply a shortcut. It is the equivelent of:
Total = 0; for (unsigned int i=0; i<MapExtents[CurrentRow]-1; i++) { Total += MapExtents; } FirstPointInRow.push_back(Total);
Where CurrentRow would be the row you are looking for the index of the first point of. It's just a shortcut so I don't have to keep running through that loop every time I want to know the index of the first point of a given row. Does that make more sense?
Quote:
2) CurrentIndex is the index for your seed point. And from assumption #1 is relative to the start of the frame buffer not the row.
The first sentence is right, the second is not. It is neither relative to the frame buffer nor the row. CurrentIndex is relative to the sequential set of points (in other words, it is simply a number that runs anywhere from 0 to 411,000).
Quote:
3) If you're marching north or south from a seed point, you appropriately update CurrentIndex after each pixel is colored...outside of the code you listed. And...you're basically doing something like CurrentIndex += FindMapPointIndexByDirection(CurrentIndex, NORTH | SOUTH);
More or less the right idea, although it's not a += function. What we want to return is the absolute index, they are not additive. What it comes out to is (and I'm paraphrasing my code here, as it's actually much more complex than this):
NeighborIndex = FindMapPointIndexByDirection(CurrentIndex, NORTH);
Once I have the NeighborIndex value, I can then set the color of the point.
Quote:
4) WorldBuilderPoint.GetData(...) returns the (x,y) *pixel* coordinate (integer values) within the frame buffer for the current index. I am blindly assuming that this gives you a correct pixel coordinate since I see no code.
No. Definitely NOT pixel coordinates, although there is a bit of a relationship. The centering of the points on the rows is done in the drawing routines. Here, the X and Y values are the column and row, just like pixel coordinates, but the X value is not centered. Therefore the first point (which would be WorldBuilderPoint[0]) would return 0,0 for X and Y. The second point (WorldBuilderPoint[1]) would return 0, 1 (this would be the first point on the second row), while WorldBuilderPoint[2] would return 1, 1.
I know, it's a horrendously complicated system, and I'm asking a lot for someone to come in and look at a fragment of code and try to see a problem that I myself can't see.
Maybe the problem DOES lie in the equation. The equation I came up with (in pseudo code] was:
NewIndex = FirstPointInRow[DesiredRow] + X/MapExtents[StartingRow]*MapExtents[DesiredRow]
Anyway, I hope my clarifications help. Like I said, it's kind of hard to know how deep to go into it when describing complex code like this.