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 <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "BMP.h"
|
#include "BMP.h"
|
||||||
|
#include "shapes/Shape.h"
|
||||||
|
#include "shapes/Sphere.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Scene::Scene(map<string, const char *> options,
|
Scene::Scene(map<string, const char *> options,
|
||||||
@ -50,10 +52,18 @@ Scene::~Scene()
|
|||||||
{
|
{
|
||||||
if (m_data != NULL)
|
if (m_data != NULL)
|
||||||
delete m_data;
|
delete m_data;
|
||||||
|
for (vector<Shape *>::iterator it = m_shapes.begin();
|
||||||
|
it != m_shapes.end();
|
||||||
|
it++)
|
||||||
|
{
|
||||||
|
delete (*it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::load(const char * filename)
|
void Scene::load(const char * filename)
|
||||||
{
|
{
|
||||||
|
/* TODO: parse file somehow */
|
||||||
|
m_shapes.push_back(new Sphere(2.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::render()
|
void Scene::render()
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include "shapes/Shape.h"
|
||||||
|
|
||||||
class Scene
|
class Scene
|
||||||
{
|
{
|
||||||
@ -23,6 +25,7 @@ class Scene
|
|||||||
std::string m_output_file_name;
|
std::string m_output_file_name;
|
||||||
bool m_verbose;
|
bool m_verbose;
|
||||||
unsigned char * m_data;
|
unsigned char * m_data;
|
||||||
|
std::vector<Shape *> m_shapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,5 +18,15 @@ Solver::Result Sphere::intersect(const Ray & ray)
|
|||||||
+ ray.getOrigin()[1] * ray.getOrigin()[1]
|
+ ray.getOrigin()[1] * ray.getOrigin()[1]
|
||||||
+ ray.getOrigin()[2] * ray.getOrigin()[2] );
|
+ ray.getOrigin()[2] * ray.getOrigin()[2] );
|
||||||
Solver::Result quadSolutions = solver.solve();
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ class Ray
|
|||||||
const Vector & getOrigin() const { return m_origin; }
|
const Vector & getOrigin() const { return m_origin; }
|
||||||
const Vector & getDirection() const { return m_direction; }
|
const Vector & getDirection() const { return m_direction; }
|
||||||
Vector getPositionAt(double dist) const;
|
Vector getPositionAt(double dist) const;
|
||||||
|
Vector operator[](double dist) const { return getPositionAt(dist); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector m_origin;
|
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 QuarticSolver::solve()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Solver::Result::Result()
|
||||||
|
{
|
||||||
|
numResults = 0;
|
||||||
|
}
|
||||||
|
@ -5,11 +5,13 @@
|
|||||||
class Solver
|
class Solver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef struct
|
class Result
|
||||||
{
|
{
|
||||||
int numResults;
|
public:
|
||||||
double results[4];
|
Result();
|
||||||
} Result;
|
int numResults;
|
||||||
|
double results[4];
|
||||||
|
};
|
||||||
|
|
||||||
Solver(double a = 0.0,
|
Solver(double a = 0.0,
|
||||||
double b = 0.0,
|
double b = 0.0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user