Fixed the TriangleFunctor QUAD_STRIP code so that it produces consistent

results.
This commit is contained in:
Robert Osfield
2002-07-04 09:49:12 +00:00
parent 04a841bf93
commit 5957c21082
2 changed files with 39 additions and 6 deletions

View File

@@ -435,7 +435,7 @@ public:
for(GLsizei i=3;i<count;i+=2,vptr+=2)
{
operator()(*(vptr),*(vptr+1),*(vptr+2));
operator()(*(vptr),*(vptr+2),*(vptr+3));
operator()(*(vptr+1),*(vptr+3),*(vptr+2));
}
break;
}
@@ -501,7 +501,7 @@ public:
for(GLsizei i=3;i<count;i+=2,iptr+=2)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)]);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)]);
}
break;
}
@@ -570,7 +570,7 @@ public:
for(GLsizei i=3;i<count;i+=2,iptr+=2)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)]);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)]);
}
break;
}
@@ -637,7 +637,7 @@ public:
for(GLsizei i=3;i<count;i+=2,iptr+=2)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)]);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)]);
}
break;
}

View File

@@ -35,6 +35,29 @@
// with the various primitives in it, and the main() which sets up a basic viewer window and
// adds to the it the scene generated by createScene().
struct NormalPrint
{
void operator() (const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec3& v3) const
{
osg::Vec3 normal = (v2-v1)^(v3-v2);
normal.normalize();
std::cout << "\t("<<v1<<") ("<<v2<<") ("<<v3<<") "<<") normal ("<<normal<<")"<<std::endl;
}
};
// decompose Drawable primtives into triangles, print out these triangles and computed normals.
void printTriangles(const std::string& name, osg::Drawable& drawable)
{
std::cout<<name<<std::endl;
osg::TriangleFunctor<NormalPrint> tf;
drawable.applyPrimitiveOperation(tf);
std::cout<<std::endl;
}
osg::Node* createScene()
{
// create the Geode (Geometry Node) to contain all our osg::Geometry objects.
@@ -299,7 +322,8 @@ osg::Node* createScene()
// This time we simply use primitive, and hardwire the number of coords to use
// since we know up front,
polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::POLYGON,0,numCoords));
printTriangles("Polygon",*polyGeom);
// add the points geomtry to the geode.
geode->addDrawable(polyGeom);
@@ -347,6 +371,8 @@ osg::Node* createScene()
polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::QUADS,0,numCoords));
printTriangles("Quads",*polyGeom);
// add the points geomtry to the geode.
geode->addDrawable(polyGeom);
}
@@ -394,6 +420,8 @@ osg::Node* createScene()
polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::QUAD_STRIP,0,numCoords));
printTriangles("Quads strip",*polyGeom);
// add the points geomtry to the geode.
geode->addDrawable(polyGeom);
}
@@ -462,6 +490,8 @@ osg::Node* createScene()
polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::TRIANGLE_FAN,12,5));
printTriangles("Triangles/Strip/Fan",*polyGeom);
// add the points geomtry to the geode.
geode->addDrawable(polyGeom);
}
@@ -568,7 +598,7 @@ osg::Node* createBackground()
// contains unsigned char indicies, UShortDrawElements which contains unsigned short indices,
// and UIntDrawElements whcih contains ... unsigned int indices.
// The first parameter to DrawElements is
polyGeom->addPrimitive(new osg::UShortDrawElements(osg::Primitive::QUADS,4,myIndices));
polyGeom->addPrimitive(new osg::UShortDrawElements(osg::Primitive::QUADS,numIndices,myIndices));
// new we need to add the texture to the Drawable, we do so by creating a
// StateSet to contain the Texture StateAttribute.
@@ -600,6 +630,9 @@ osg::Node* createBackground()
return transform;
}
int main( int argc, char **argv )
{