Lets say that I have an array of vertices:
Code: Select all
sVertex vert[99];
Code: Select all
sVertex vert[99];
That's not really what it does.jean wrote:The GPU will clip polys outside frustum and draw halfway polys the right way.
Really?????????? X|If 2 or more points of a triangle are outside the frustum, it will be clipped by the GPU.
Yeah, there are some major issues with polygon clipping here. A frustum will be needed.Is GE's hardware clipper doing such a bad job you need to clip manually?
I meant to say triangles. The idea of adding extra space to my vertex array sounds promising. I need to establish a good vertex strip system though. I'm not sure what I should do there because different .x file plug-ins organize the indices of the vertices differently, and take different amounts of vertices to make the shape. Some are more optimized than others...You don't clip vertices, you clip triangles. So each triangle which is 3 of those vertices gets clipped and might generate some extra vertices and some extra triangles. So, I guess, if you have 50 vertices, you can start adding extra vertices at the end of that space, 51, 52, etc - just make sure you allocate more space than you need.
This, along with creating a frustum is exactly what I'm after. =) I was not sure what I should do first, so I've been asking around first before I start writing up how everything should work. Like I said though, different .x file exporters spit out different versions of how to organize and use vertices. For different applications.1) 1 2 3 are the first triangle, 4 5 6 then following and so on...not so good, a gerarchical model should be preferred
2) triangle strip: 1 2 3 are the first triangle, 2 3 4 are the second and so on... a model needs to be stripped offline by particular programs
3) triangle fan: 1 2 3 are the first triangle, 1 3 4 the second, 1 4 5 the third and so on...not to say, this cannot draw a closed 3D surface, so it's unlikely to use only this...
Code: Select all
36; // number of vertices
0.000000, 0.000000, 0.000000;, // vertex data
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;,
0.000000, 0.000000, 0.000000;;
8; // number of faces
3;0,1,2;, // the first "3;" means that there are 3 indices for this face...
3;3,4,5;, // ...and the numbers following that are the indices
3;6,7,8;,
3;9,10,11;,
3;12,13,14;,
3;15,16,17;,
3;18,19,20;,
3;21,22,23;,
3;24,25,26;,
3;27,28,29;,
3;30,31,32;,
3;33,34,35;;
Code: Select all
0 1 2
3 4 5
6 7 8
9 10 11
12 13 14...
Code: Select all
0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 7 8
Yeah, I wanted to add some sort of node-tree system such as a bsp tree later on, and just apply my triangle clipping too just the node my camera is in since that is the only node that will be rendered (or will it?). I've got some pretty big polygons. I was aiming for really low-poly modeling. The sad thing is that I had to add hundreds of extra vertices to my floors in 3ds Max to tessellate my floors and walls. Just about any polygon will be clipped depending on how close you get to it. If I get that frustum knocked out, I it will take a lot of processing power to transform the frustum with the camera and clip those vertices, but the good news is that I can use way less vertices in my objects, and the biggest part will be that I won't have disappearing triangles.On the other side, the only algorithm that would REALLY improve sorting/culling /collision-checking a structure is BSP (or portal rendering, or my BubbleTree algorithm i'm so proud of...;) ) BUT believe me, it's a real mess. If i didn't understand the point, and your models are really made up of polys so large that tasselation is needed, you can do it offline with some modeling program or apply LOD techniques, but -again- it's not so easy. Try googling around.
I've looked into that, but I was not sure on how to add vertices to my array. I could add extra space in my arrays during load-time like Jim has suggested. The Sutherland-Hodgman algorithm looks promising, but I still have to get those frustum planes up and running first. I know I have to multiply my view and projection matrices together into a resultant matrix, but what is the order exactly? I think Raphael said that matrices were put together in this fashion:You need to ideally clip your triangles before this in camera space.
Google for Sutherland-Hodgman clipping.
He also mentions that the matrices are multiplied in a right-to-left order. Is that how gumMatrixMultiply() works as well:PROJ*VIEW*MODEL
Code: Select all
mat a: matrix on the left
mat b: matrix on the right
mat b X mat a