creating polygons for extrude objects, ngon takes radius parameter

git-svn-id: svn://anubis/fart/trunk@270 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2010-07-01 20:35:20 +00:00
1 parent 7d844667c3
commit 4c5444f053
4 files changed
+70 -4

No files matched your search

+45 -3
View File
@@ -1,4 +1,6 @@
#include <math.h>
#include <typeinfo>
#include <iostream>
@@ -566,7 +568,23 @@ refptr<Shape> Scene::processExtrude(refptr<Node> node)
}
else if ( typeid(**it) == typeid(OffsetNode) )
{
/* FIXME */
double distance = (*it)->getNumber();
Vector scale(1, 1, 1);
Vector position(0, 0, 0);
for (Node_Iterator it2 = (*it)->getChildren().begin();
it2 != (*it)->getChildren().end();
it2++)
{
if ( typeid(**it2) == typeid(ScaleNode) )
{
scale = * (*it2)->getVector();
}
else if ( typeid(**it2) == typeid(PositionNode) )
{
position = * (*it2)->getVector();
}
}
extrude->addOffset(distance, scale, position);
}
else if ( (*it)->isMaterial() )
{
@@ -587,14 +605,38 @@ refptr<Shape> Scene::processExtrude(refptr<Node> node)
refptr<Polygon> Scene::processPolygon(refptr<Node> node)
{
refptr<Polygon> p = new Polygon();
/* FIXME */
for (Node_Iterator it = node->getChildren().begin();
it != node->getChildren().end();
it++)
{
if ( typeid(**it) == typeid(VectorNode) )
{
p->push_back((*it)->getVector());
}
else
{
cerr << "Error: Unknown polygon sub-object" << endl;
exit(3);
}
}
return p;
}
refptr<Polygon> Scene::processNGon(refptr<Node> node)
{
refptr<Polygon> p = new Polygon();
/* FIXME */
double radius = node->getChildren()[0]->getNumber();
int n = node->getInteger();
if (n < 3)
n = 3;
double astep = 2.0 * M_PI / n;
for (int i = 0; i < n; i++)
{
p->push_back(new Vector(
radius * cos(i * astep),
radius * sin(i * astep),
0.0));
}
return p;
}