• Announcements

Archived

This topic is now archived and is closed to further replies.

a question concerning speed....

Recommended Posts

hi, i used the first piece of code to access a face´s point within it´s triangle list. the first method is convenient but i think that the division and modulo may be too time consumpting since i do a call of GetVertex to thousands of vertices each rendering frame. is it better to use the second piece of code? currently there is no noticable decrease in performance but this may change at the world grows.... on the other side, if i have more than, say 10 triangles, i need to switch-case for over 30 points!!!
  CVector* CFace::GetVertex (int index) { int vIndex = index%3; int triIndex = (index-vIndex)/3; return (GetTriangle(triIndex)->vertices[vIndex]); } CVector* CFace::GetVertex (int index) { switch (index) { case 0: return GetTriangle(0)->vertices[0]; case 1: return GetTriangle(0)->vertices[1]; case 2: return GetTriangle(0)->vertices[2]; case 3: return GetTriangle(1)->vertices[0]; case 4: return GetTriangle(1)->vertices[1]; case 5: return GetTriangle(1)->vertices[2]; // ...... and so on for the rest of vertices } } 
what would you say to this? thanks gammastrahler Edited by - gammastrahler on January 31, 2002 8:34:23 AM Edited by - gammastrahler on January 31, 2002 8:37:01 AM

Share on other sites
Null and Void    1088
Use the first one, just don''t make it so ''overly safe.'' Just have it be:
  CVector *CFace::GetVertex(int Tri, int Index) { return GetTriangle(Tri)->vertices[Index];}

And make it inline. A commonly accessed routine like that with expensive bounds checking is going to kill performance. I personally think you arranged how you''re going about it a little less than optimally, but maybe I''m not seeing enough to make a fair judgement.

Share on other sites
DrPizza    160
That doesn''t look like bounds checking, that looks like how to calculate the particular offsets when provided with only a single index. I would assume that the calculation needs to be done either inside the function or outside it, and so would be better off done inside it.

Share on other sites
Null and Void    1088
quote:
Original post by DrPizza
That doesn''t look like bounds checking...

I wrote the message before the code, and just forgot to change the assumed reasoning to the real reasoning. I still think his implementation is somewhat flawed if there''s any reason for having to doing something like that with primitives.