git-svn-id: svn://anubis/fart/branches/scene-file-scripting@330 7f9b0f55-74a9-4bce-be96-3c2cd072584d
132 lines
4.0 KiB
C++
132 lines
4.0 KiB
C++
|
|
#ifndef SHAPE_H
|
|
#define SHAPE_H SHAPE_H
|
|
|
|
#include "util/Solver.h"
|
|
#include "util/Ray.h"
|
|
#include "util/Vector.h"
|
|
#include "util/Transform.h"
|
|
#include "util/Material.h"
|
|
#include "util/refptr.h"
|
|
#include <vector>
|
|
#include <utility>
|
|
|
|
class Shape
|
|
{
|
|
public:
|
|
class Intersection
|
|
{
|
|
public:
|
|
Intersection() {};
|
|
Intersection(refptr<Shape> shape,
|
|
const Vector & position,
|
|
const Vector & normal)
|
|
{
|
|
this->shape = shape;
|
|
this->position = position;
|
|
this->normal = normal;
|
|
}
|
|
refptr<Shape> shape;
|
|
Vector position;
|
|
Vector normal;
|
|
Intersection transform(Transform & t)
|
|
{
|
|
return Intersection(shape,
|
|
t.transform_point(position),
|
|
t.transform_normal(normal));
|
|
}
|
|
};
|
|
class BoolIntersection
|
|
{
|
|
public:
|
|
BoolIntersection() {};
|
|
BoolIntersection(const Intersection & intersection, bool left)
|
|
{
|
|
this->intersection = intersection;
|
|
this->left = left;
|
|
}
|
|
Intersection intersection;
|
|
bool left;
|
|
};
|
|
class IntersectionList
|
|
{
|
|
public:
|
|
void add(const Intersection & i)
|
|
{
|
|
m_intersections.push_back(i);
|
|
}
|
|
Intersection & operator[](int i)
|
|
{
|
|
return m_intersections[i];
|
|
}
|
|
const Intersection & operator[](int i) const
|
|
{
|
|
return m_intersections[i];
|
|
}
|
|
size_t size() const { return m_intersections.size(); }
|
|
std::vector<Intersection>::iterator begin()
|
|
{
|
|
return m_intersections.begin();
|
|
}
|
|
std::vector<Intersection>::iterator end()
|
|
{
|
|
return m_intersections.end();
|
|
}
|
|
protected:
|
|
std::vector< Intersection > m_intersections;
|
|
};
|
|
class BoolIntersectionList
|
|
{
|
|
public:
|
|
BoolIntersectionList(const IntersectionList & l1,
|
|
const IntersectionList & l2,
|
|
const Vector & startPoint);
|
|
BoolIntersection & operator[](int i)
|
|
{
|
|
return m_intersections[i];
|
|
}
|
|
const BoolIntersection & operator[](int i) const
|
|
{
|
|
return m_intersections[i];
|
|
}
|
|
size_t size() const { return m_intersections.size(); }
|
|
std::vector<BoolIntersection>::iterator begin()
|
|
{
|
|
return m_intersections.begin();
|
|
}
|
|
std::vector<BoolIntersection>::iterator end()
|
|
{
|
|
return m_intersections.end();
|
|
}
|
|
|
|
protected:
|
|
std::vector< BoolIntersection > m_intersections;
|
|
};
|
|
|
|
Shape();
|
|
virtual ~Shape();
|
|
virtual IntersectionList intersect(refptr<Shape> _this,
|
|
const Ray & ray) = 0;
|
|
virtual refptr<Shape> clone() = 0;
|
|
|
|
void setTransform(const Transform & t)
|
|
{
|
|
m_transform = t;
|
|
m_inverse = m_transform.getInverse();
|
|
}
|
|
Transform & getTransform() { return m_transform; }
|
|
|
|
virtual void setMaterial(refptr<Material> material);
|
|
refptr<Material> getMaterial() const { return m_material; }
|
|
|
|
protected:
|
|
Transform m_transform;
|
|
Transform m_inverse;
|
|
refptr<Material> m_material;
|
|
};
|
|
|
|
typedef refptr<Shape> ShapeRef;
|
|
|
|
#endif
|
|
|