Solved

Batching Objects together

Posted on 2006-06-08
4
210 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now