Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Batching Objects together

Posted on 2006-06-08
4
Medium Priority
?
218 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview

824 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