77 lines
2.1 KiB
C++
77 lines
2.1 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:
|
|
typedef std::pair< refptr<Shape> , Vector > Intersection;
|
|
class IntersectionList
|
|
{
|
|
public:
|
|
void add(const Intersection & i)
|
|
{
|
|
m_intersections.push_back(i);
|
|
}
|
|
Intersection & operator[](int i)
|
|
{
|
|
return m_intersections[i];
|
|
}
|
|
size_t size() { return m_intersections.size(); }
|
|
std::vector<Intersection>::iterator begin()
|
|
{
|
|
return m_intersections.begin();
|
|
}
|
|
std::vector<Intersection>::iterator end()
|
|
{
|
|
return m_intersections.end();
|
|
}
|
|
IntersectionList merge(const IntersectionList & other,
|
|
const Vector & startPoint);
|
|
protected:
|
|
std::vector< Intersection > m_intersections;
|
|
};
|
|
|
|
Shape();
|
|
virtual ~Shape();
|
|
virtual IntersectionList intersect(refptr<Shape> _this,
|
|
const Ray & ray) = 0;
|
|
virtual Vector getNormalAt(const Vector & pt) = 0;
|
|
|
|
void setTransform(Transform & t)
|
|
{
|
|
m_transform = t;
|
|
m_inverse = t.getInverse();
|
|
}
|
|
Transform & getTransform() { return m_transform; }
|
|
|
|
void setTransparency(double t) { m_transparency = t; }
|
|
double getTransparency() const { return m_transparency; }
|
|
|
|
void setMaterial(refptr<Material> material) { m_material = material; }
|
|
refptr<Material> getMaterial() const { return m_material; }
|
|
|
|
protected:
|
|
Transform m_transform;
|
|
Transform m_inverse;
|
|
double m_transparency;
|
|
refptr<Material> m_material;
|
|
};
|
|
|
|
#include "Box.h"
|
|
#include "Cyl.h"
|
|
#include "Plane.h"
|
|
#include "Sphere.h"
|
|
|
|
#endif
|
|
|