Archived

This topic is now archived and is closed to further replies.

Does This Seem Odd To You?

This topic is 4945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, im creating a simple 3D Mine Sweeper game, and it gets laggy when doing teh following: 1. I have 10x10x10 so 1000 cubes on the screen. 2. Each Cube is made of 2 triangles on each face so 12000 triangles. 3. Vertices are unoptimized meshes. 4. In order for alpha transparency, i sorted the cubes with distance from camera. I used an array 1000 long and put 0-999 in the array members, then compared the appropriate cubes indicated by this array. 5. Rendered them from back to front. All i was doing with the cubes was applying simple texture. This sorting routine really was the first attempt and im considering applying some sort of binary tree method. What could be the problem. BTW i have narrowed down the lag to when the sorting and rendering in order is on, so it is the sorting. I'm just wondering if this is the cause. regards ace EDIT: Back to front [edited by - ace_lovegrove on May 30, 2004 4:51:38 PM]

Share this post


Link to post
Share on other sites
I don't think you should be rendering them front to back, because then cubes that are behind other cubs will unnaturally cover the front cubes. Rendering them back to front is the appropriate brute force method, refered to as the Painter's Algorithm is some instances.

As for sorting, we need to know what algorithm you are using to know what the problem is. Most people end up writing something like bubble sort of selection sort their first time out, and they are both woefully innefficient. You'll probably want something like QuickSort.

Check out something like BSP trees. That will help to quickly sort your list of objects and display them quickly.

Or, look into a visibile surface determination algorithm. At any one time, you can only see three faces of a cube at the most, so you are rendering 6000 too many triangles. Also, quite a few of those faces will be covered up by other cubes. If I'm thinking right, I think the most triangles you can have visible at any one time is 10x10x3x2=600. That's only 1/20th the amount of rendering you need to do. I really think VSD is the way to go here.



capn_midnight | Captain Midnight | deviantArt
ACM | SIGGRAPH | Generation5

[edited by - capn_midnight on May 30, 2004 4:29:42 PM]

Share this post


Link to post
Share on other sites
He''s doing transperancy so back to front is the proper order.

As for sorting it''s easier (and fast) to use the built in calls to sort. qsort for c and sort for c++. I''ll give you an example of c++''s since it''s a little strange if never played with STL.


#include <algorithm>

int sortfunc(const int &n1,const int &n2){ //Exmple sorting function, greatest to smallest

return n1>n2;
}

int main(int argc, char *argv[])
{
int nums[10]={1,2,3,4,5,6,7,8,9,10};
std::sort(&nums[0],&nums[10],sortfunc); //Yes it''s supposed to be nums[10]

//all sorted now

return 0;
}


If your using stl countainers it changes a little bit.

Share this post


Link to post
Share on other sites