Solved

Batching Objects together

Posted on 2006-06-08
4
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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