improving Ray, Sphere, Solver, Scene a bit
git-svn-id: svn://anubis/fart/trunk@35 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
bdb648b84f
commit
73cdd1a5a1
@ -4,6 +4,8 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "BMP.h"
|
||||
#include "shapes/Shape.h"
|
||||
#include "shapes/Sphere.h"
|
||||
using namespace std;
|
||||
|
||||
Scene::Scene(map<string, const char *> options,
|
||||
@ -50,10 +52,18 @@ Scene::~Scene()
|
||||
{
|
||||
if (m_data != NULL)
|
||||
delete m_data;
|
||||
for (vector<Shape *>::iterator it = m_shapes.begin();
|
||||
it != m_shapes.end();
|
||||
it++)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::load(const char * filename)
|
||||
{
|
||||
/* TODO: parse file somehow */
|
||||
m_shapes.push_back(new Sphere(2.0));
|
||||
}
|
||||
|
||||
void Scene::render()
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "shapes/Shape.h"
|
||||
|
||||
class Scene
|
||||
{
|
||||
@ -23,6 +25,7 @@ class Scene
|
||||
std::string m_output_file_name;
|
||||
bool m_verbose;
|
||||
unsigned char * m_data;
|
||||
std::vector<Shape *> m_shapes;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -18,5 +18,15 @@ Solver::Result Sphere::intersect(const Ray & ray)
|
||||
+ ray.getOrigin()[1] * ray.getOrigin()[1]
|
||||
+ ray.getOrigin()[2] * ray.getOrigin()[2] );
|
||||
Solver::Result quadSolutions = solver.solve();
|
||||
int resIdx = 0;
|
||||
for (int i = 0; i < quadSolutions.numResults; i++)
|
||||
{
|
||||
if (quadSolutions.results[i] >= 0.0)
|
||||
{
|
||||
res.results[resIdx] = quadSolutions.results[i];
|
||||
resIdx++;
|
||||
res.numResults = resIdx;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ class Ray
|
||||
const Vector & getOrigin() const { return m_origin; }
|
||||
const Vector & getDirection() const { return m_direction; }
|
||||
Vector getPositionAt(double dist) const;
|
||||
Vector operator[](double dist) const { return getPositionAt(dist); }
|
||||
|
||||
private:
|
||||
Vector m_origin;
|
||||
|
@ -75,3 +75,8 @@ QuarticSolver::QuarticSolver(double a, double b, double c, double d, double e)
|
||||
Solver::Result QuarticSolver::solve()
|
||||
{
|
||||
}
|
||||
|
||||
Solver::Result::Result()
|
||||
{
|
||||
numResults = 0;
|
||||
}
|
||||
|
@ -5,11 +5,13 @@
|
||||
class Solver
|
||||
{
|
||||
public:
|
||||
typedef struct
|
||||
class Result
|
||||
{
|
||||
public:
|
||||
Result();
|
||||
int numResults;
|
||||
double results[4];
|
||||
} Result;
|
||||
};
|
||||
|
||||
Solver(double a = 0.0,
|
||||
double b = 0.0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user