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:
parent
7d844667c3
commit
4c5444f053
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -566,7 +568,23 @@ refptr<Shape> Scene::processExtrude(refptr<Node> node)
|
|||||||
}
|
}
|
||||||
else if ( typeid(**it) == typeid(OffsetNode) )
|
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() )
|
else if ( (*it)->isMaterial() )
|
||||||
{
|
{
|
||||||
@ -587,14 +605,38 @@ refptr<Shape> Scene::processExtrude(refptr<Node> node)
|
|||||||
refptr<Polygon> Scene::processPolygon(refptr<Node> node)
|
refptr<Polygon> Scene::processPolygon(refptr<Node> node)
|
||||||
{
|
{
|
||||||
refptr<Polygon> p = new Polygon();
|
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;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
refptr<Polygon> Scene::processNGon(refptr<Node> node)
|
refptr<Polygon> Scene::processNGon(refptr<Node> node)
|
||||||
{
|
{
|
||||||
refptr<Polygon> p = new Polygon();
|
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;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +307,10 @@ number: DEC_NUMBER { $$ = $1; }
|
|||||||
| REAL_NUMBER { $$ = $1; }
|
| REAL_NUMBER { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
ngon: NGON DEC_NUMBER { $$ = new NGonNode($2->getInteger()); }
|
ngon: NGON DEC_NUMBER COMMA number {
|
||||||
|
$$ = new NGonNode($2->getInteger());
|
||||||
|
$$->addChild(new RadiusNode($4->getNumber()));
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
offset: OFFSET number {
|
offset: OFFSET number {
|
||||||
|
@ -24,4 +24,11 @@ Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
|
|
||||||
void Extrude::addPolygon(refptr<Polygon> polygon)
|
void Extrude::addPolygon(refptr<Polygon> polygon)
|
||||||
{
|
{
|
||||||
|
m_polygons.push_back(polygon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Extrude::addOffset(double distance,
|
||||||
|
const Vector & scale, const Vector & shift)
|
||||||
|
{
|
||||||
|
m_offsets.push_back(Offset(distance, scale, shift));
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,23 @@ class Extrude : public Shape
|
|||||||
Extrude();
|
Extrude();
|
||||||
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
void addPolygon(refptr<Polygon> polygon);
|
void addPolygon(refptr<Polygon> polygon);
|
||||||
|
void addOffset(double distance,
|
||||||
|
const Vector & scale, const Vector & shift);
|
||||||
|
class Offset
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Offset(double d, const Vector & s, const Vector & p)
|
||||||
|
: distance(d), scale(s), shift(p)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
double distance;
|
||||||
|
Vector scale;
|
||||||
|
Vector shift;
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector< refptr<Polygon> > m_polygons;
|
std::vector< refptr<Polygon> > m_polygons;
|
||||||
|
std::vector<Offset> m_offsets;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user