Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm practicing primitives rendering in XNA and I want to create something like pipe or tunnel. I have base class called PipeSegment from which I inherit classes like RotatingSegment and NormalSegment (and whatever I imagine). To combine this segments I have created class called Pipe, which have List of PipeSegment objects.This is what I have so far :

Image

It's ok, except the fact that I'm generating way more vertices than necessary. For each segment I'm generating 36 vertices for 'front side', and 36 for 'back side'.

Illustration :

Image

Now, my question. How can I optimize this, how to generate less vertices ? Is there any way to 'share' vertices between Segments to preserve my current code structure and is my code structure suitable for this ?

Thanks

share|improve this question
    
    
I know what indices are, but I don't know how to apply them in my example..Thank You –  Nikola Ninkovic Feb 5 '13 at 19:41
    
That is why I linked you to and XNA tutorial that tells you how to apply then in your situation. –  ClassicThunder Feb 5 '13 at 19:43

2 Answers 2

up vote 1 down vote accepted

You could set up your DrawableGameComponents like links in a linked node list.

For instance, each PipeSegment would have a reference to the next PipeSegment in the line. Then when you want to draw the current PipeSegment you call some interface function that returns the vertices you need. RotatingSegment and NormalSegment implement the interface function however they want.

If all you're concerned with is not storing the data for the vertices multiple times, then you can just draw each segment separately at this point. If, however, you are trying to only make 1 draw call then you can have the segments all send there vertices to the first node through the list, then only make 1 draw call there.

share|improve this answer
    
I'll try your solution with linked lists, thank You –  Nikola Ninkovic Feb 5 '13 at 18:06
    
Did it work for you? Let me know if it isn't clear enough. –  Thomas Marnell Feb 7 '13 at 19:19
    
Yes it is, thank you :) –  Nikola Ninkovic Feb 7 '13 at 20:04

I think the real problem here is the PipeSegment having any vertices at all. Rather the PipeSegment should have two Ring objects that are a collection of points around the pipe and are shared between adjacent PipeSegments. The rings would come in two flavors to offset the points.

share|improve this answer
    
Thank You, I will try this too, but I worry becouse I don't know how to generate combined VertexBuffer containing vertices from ring1 and ring2... –  Nikola Ninkovic Feb 6 '13 at 13:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.