Solved

Batching Objects together

Posted on 2006-06-08
4
212 Views
Last Modified: 2010-04-16
I have a quick little C# app that draws 3D objects (primitives)

I have 3 objects that I want to draw:

Cubes
Cones
Spheres

At the moment I am drawing them as they come in. So I could have 3 cones, 1 Cube, 2 spheres, 1 cone, 5 cubes etc.

As you can imagine this is in-efficient. Basically what I would like to do is batch the objects together so that all like objects are together eg: all cones, all cubes, all spheres are together.

Just before I finish a frame I will refer to the batch and draw the primitives.

What I was planning was to create a simple design pattern that simply added the objects to the relevant structure (either an array list or perhaps a hash table.) Then iterate through the structures when ready.

Anyone have any ideas on how to organise or store basic objects in a structure that would all for the most efficient insertion and retrieval?

0
Comment
Question by:directxBOB
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16867796
>> As you can imagine this is in-efficient.
Why?

Drawing objects is 3D space is usually done by z-order, and not by their types. However, you can keep all your objects in 3 lists, every list contains objects of one type.
0
 

Author Comment

by:directxBOB
ID: 16867819
In this situation Z-Order isnt important, but rather squezzing that little bit extra out of it. I could pipe all objects into their various lists and pull them out as needed.
0
 
LVL 9

Accepted Solution

by:
pallosp earned 500 total points
ID: 16868262
I think the fastest data structure that meets your requirements is a generic FIFO queue for each type of objects. The insertion and the retrieval are both done in constant time.

http://msdn2.microsoft.com/en-US/library/7977ey2c.aspx
0
 
LVL 3

Expert Comment

by:solublefish
ID: 16868529
I think it probably doesn't matter. With 3d graphics, almost all the processing time is in the transforms, etc that go into processing the objects. Optimizing the storage is like taking an eyedropper of water out of niagra falls. The fastest order to process them is the one that eliminates the most transforming, lighting, texturing, and rendering. As someone said, that's usually done by descending z-order, but there are more complictated algorithms (BSP-trees come to mind) that are even better.

If really all you care about is the storage for some reason, pallosp is right - use 3 queues. If you need a single data structure to retrieve from, wrap the 3 queues in a simple class that inserts/retrieves from the right one.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question