added Extrude and Polygon classes, still in progress
git-svn-id: svn://anubis/fart/trunk@269 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
ad017df3b5
commit
7d844667c3
@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
#include "Light.h"
|
#include "Light.h"
|
||||||
#include "parser/parser.h"
|
#include "parser/parser.h"
|
||||||
#include "parser/nodes.h"
|
#include "parser/nodes.h"
|
||||||
|
#include "util/Polygon.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -135,6 +137,10 @@ refptr<Shape> Scene::processShape(refptr<Node> node)
|
|||||||
{
|
{
|
||||||
return processBool(node);
|
return processBool(node);
|
||||||
}
|
}
|
||||||
|
else if ( typeid(*node) == typeid(ExtrudeNode) )
|
||||||
|
{
|
||||||
|
return processExtrude(node);
|
||||||
|
}
|
||||||
|
|
||||||
return refptr<Shape>(NULL);
|
return refptr<Shape>(NULL);
|
||||||
}
|
}
|
||||||
@ -539,6 +545,59 @@ refptr<Shape> Scene::processBool(refptr<Node> node)
|
|||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Scene::processExtrude(refptr<Node> node)
|
||||||
|
{
|
||||||
|
refptr<Material> material;
|
||||||
|
Extrude * extrude = new Extrude();
|
||||||
|
|
||||||
|
bool restore_transform = processTransforms(node);
|
||||||
|
|
||||||
|
for (Node_Iterator it = node->getChildren().begin();
|
||||||
|
it != node->getChildren().end();
|
||||||
|
it++)
|
||||||
|
{
|
||||||
|
if ( typeid(**it) == typeid(PolygonNode) )
|
||||||
|
{
|
||||||
|
extrude->addPolygon(processPolygon(*it));
|
||||||
|
}
|
||||||
|
else if ( typeid(**it) == typeid(NGonNode) )
|
||||||
|
{
|
||||||
|
extrude->addPolygon(processNGon(*it));
|
||||||
|
}
|
||||||
|
else if ( typeid(**it) == typeid(OffsetNode) )
|
||||||
|
{
|
||||||
|
/* FIXME */
|
||||||
|
}
|
||||||
|
else if ( (*it)->isMaterial() )
|
||||||
|
{
|
||||||
|
material = processMaterial(*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! material.isNull() )
|
||||||
|
extrude->setMaterial(material);
|
||||||
|
extrude->setTransform(m_transforms.top());
|
||||||
|
|
||||||
|
if (restore_transform)
|
||||||
|
m_transforms.pop();
|
||||||
|
|
||||||
|
return extrude;
|
||||||
|
}
|
||||||
|
|
||||||
|
refptr<Polygon> Scene::processPolygon(refptr<Node> node)
|
||||||
|
{
|
||||||
|
refptr<Polygon> p = new Polygon();
|
||||||
|
/* FIXME */
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
refptr<Polygon> Scene::processNGon(refptr<Node> node)
|
||||||
|
{
|
||||||
|
refptr<Polygon> p = new Polygon();
|
||||||
|
/* FIXME */
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
bool Scene::processTransforms(refptr<Node> node)
|
bool Scene::processTransforms(refptr<Node> node)
|
||||||
{
|
{
|
||||||
bool did_any = false;
|
bool did_any = false;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "util/Ray.h"
|
#include "util/Ray.h"
|
||||||
#include "util/Color.h"
|
#include "util/Color.h"
|
||||||
#include "util/Material.h"
|
#include "util/Material.h"
|
||||||
|
#include "util/Polygon.h"
|
||||||
|
|
||||||
#include "shapes/shapes.h"
|
#include "shapes/shapes.h"
|
||||||
|
|
||||||
@ -66,6 +67,9 @@ class Scene
|
|||||||
refptr<Shape> processSphere(refptr<Node> node);
|
refptr<Shape> processSphere(refptr<Node> node);
|
||||||
refptr<Shape> processShape(refptr<Node> node);
|
refptr<Shape> processShape(refptr<Node> node);
|
||||||
refptr<Shape> processBool(refptr<Node> node);
|
refptr<Shape> processBool(refptr<Node> node);
|
||||||
|
refptr<Shape> processExtrude(refptr<Node> node);
|
||||||
|
refptr<Polygon> processPolygon(refptr<Node> node);
|
||||||
|
refptr<Polygon> processNGon(refptr<Node> node);
|
||||||
bool processTransforms(refptr<Node> node);
|
bool processTransforms(refptr<Node> node);
|
||||||
void processCamera(refptr<Node> node);
|
void processCamera(refptr<Node> node);
|
||||||
void processOptions(refptr<Node> node);
|
void processOptions(refptr<Node> node);
|
||||||
|
@ -207,6 +207,7 @@ extrude_items: /* empty */
|
|||||||
extrude_item: polygon { $$ = $1; }
|
extrude_item: polygon { $$ = $1; }
|
||||||
| ngon { $$ = $1; }
|
| ngon { $$ = $1; }
|
||||||
| offset { $$ = $1; }
|
| offset { $$ = $1; }
|
||||||
|
| shape_item { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
intersect: INTERSECT LCURLY bool_items RCURLY {
|
intersect: INTERSECT LCURLY bool_items RCURLY {
|
||||||
@ -309,7 +310,33 @@ number: DEC_NUMBER { $$ = $1; }
|
|||||||
ngon: NGON DEC_NUMBER { $$ = new NGonNode($2->getInteger()); }
|
ngon: NGON DEC_NUMBER { $$ = new NGonNode($2->getInteger()); }
|
||||||
;
|
;
|
||||||
|
|
||||||
offset: OFFSET number { $$ = new OffsetNode($2->getNumber()); }
|
offset: OFFSET number {
|
||||||
|
$$ = new OffsetNode($2->getNumber());
|
||||||
|
}
|
||||||
|
| OFFSET number LCURLY offset_items RCURLY {
|
||||||
|
$$ = new OffsetNode($2->getNumber());
|
||||||
|
$$->addChildren($4);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
offset_items: /* empty */
|
||||||
|
| offset_item offset_items {
|
||||||
|
$$ = new ItemsNode();
|
||||||
|
$$->addChild($1);
|
||||||
|
$$->addChildren($2);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
offset_item: SCALE number {
|
||||||
|
$$ = new ScaleNode(new Vector($2->getNumber(), $2->getNumber(),
|
||||||
|
$2->getNumber()));
|
||||||
|
}
|
||||||
|
| SCALE vector2 {
|
||||||
|
$$ = new ScaleNode($2->getVector());
|
||||||
|
}
|
||||||
|
| POSITION vector2 {
|
||||||
|
$$ = new PositionNode($2->getVector());
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
options: OPTIONS LCURLY options_items RCURLY {
|
options: OPTIONS LCURLY options_items RCURLY {
|
||||||
|
27
shapes/Extrude.cc
Normal file
27
shapes/Extrude.cc
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "Extrude.h"
|
||||||
|
#include "util/Solver.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#define FP_EQUAL(x,y) (fabs((x)-(y)) < 0.000001)
|
||||||
|
|
||||||
|
Extrude::Extrude()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Shape::IntersectionList Extrude::intersect(refptr<Shape> _this, const Ray & ray)
|
||||||
|
{
|
||||||
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
|
IntersectionList res;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Extrude::addPolygon(refptr<Polygon> polygon)
|
||||||
|
{
|
||||||
|
}
|
22
shapes/Extrude.h
Normal file
22
shapes/Extrude.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
#ifndef EXTRUDE_H
|
||||||
|
#define EXTRUDE_H EXTRUDE_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "util/Polygon.h"
|
||||||
|
#include "Shape.h"
|
||||||
|
|
||||||
|
class Extrude : public Shape
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Extrude();
|
||||||
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
|
void addPolygon(refptr<Polygon> polygon);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::vector< refptr<Polygon> > m_polygons;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -2,6 +2,7 @@
|
|||||||
#include "BoolShape.h"
|
#include "BoolShape.h"
|
||||||
#include "Box.h"
|
#include "Box.h"
|
||||||
#include "Cyl.h"
|
#include "Cyl.h"
|
||||||
|
#include "Extrude.h"
|
||||||
#include "Intersect.h"
|
#include "Intersect.h"
|
||||||
#include "Plane.h"
|
#include "Plane.h"
|
||||||
#include "Sphere.h"
|
#include "Sphere.h"
|
||||||
|
2
util/Polygon.cc
Normal file
2
util/Polygon.cc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
#include "Polygon.h"
|
14
util/Polygon.h
Normal file
14
util/Polygon.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
#ifndef POLYGON_H
|
||||||
|
#define POLYGON_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "refptr.h"
|
||||||
|
#include "Vector.h"
|
||||||
|
|
||||||
|
class Polygon : public std::vector< refptr<Vector> >
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user