fixed bug in QuadraticSolver, cheap lighting working
git-svn-id: svn://anubis/fart/trunk@45 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
761925220b
commit
d88f1ab5fd
2
Makefile
2
Makefile
@ -5,7 +5,7 @@ export CPPFLAGS += -I"$(shell cd)"
|
|||||||
else
|
else
|
||||||
export CPPFLAGS += -I"$(shell pwd)"
|
export CPPFLAGS += -I"$(shell pwd)"
|
||||||
endif
|
endif
|
||||||
export CXXFLAGS := -O3
|
export CXXFLAGS := -Wall -O3
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
@ -125,23 +125,22 @@ void Scene::renderPixel(int x, int y, unsigned char * pixel)
|
|||||||
{
|
{
|
||||||
/* transform the ray by the inverse of the shape's transform */
|
/* transform the ray by the inverse of the shape's transform */
|
||||||
Transform inv = (*it)->getTransform().getInverse();
|
Transform inv = (*it)->getTransform().getInverse();
|
||||||
Ray transformed_ray = inv.transform_ray(ray);
|
Ray local_ray = inv.transform_ray(ray);
|
||||||
|
|
||||||
/* then intersect this inversely transformed ray with the shape */
|
/* then intersect this inversely transformed ray with the shape */
|
||||||
Solver::Result intersections = (*it)->intersect(transformed_ray);
|
Solver::Result intersections = (*it)->intersect(local_ray);
|
||||||
|
|
||||||
if (intersections.numResults > 0)
|
if (intersections.numResults > 0)
|
||||||
{
|
{
|
||||||
Vector local_intersection_point =
|
Vector local_normal =
|
||||||
transformed_ray[intersections.results[0]];
|
(*it)->getNormalAt(local_ray[intersections.results[0]]);
|
||||||
Vector normal = (*it)->getNormalAt(local_intersection_point);
|
double dot = local_ray.getDirection() % local_normal;
|
||||||
double dot = -(normal % transformed_ray.getDirection());
|
dot = -dot;
|
||||||
cout << "got dot " << dot << endl;
|
|
||||||
if (dot < 0.0)
|
if (dot < 0.0)
|
||||||
dot = 0.0;
|
dot = 0.0;
|
||||||
pixel[BMP_RED] = (unsigned char) (0xFF * dot);
|
pixel[BMP_RED] = 0xFF * dot;
|
||||||
pixel[BMP_GREEN] = (unsigned char) (0xFF * dot);
|
pixel[BMP_GREEN] = 0xFF * dot;
|
||||||
pixel[BMP_BLUE] = (unsigned char) (0xFF * dot);
|
pixel[BMP_BLUE] = 0xFF * dot;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "Sphere.h"
|
#include "Sphere.h"
|
||||||
#include "util/Solver.h"
|
#include "util/Solver.h"
|
||||||
|
#include <math.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -22,14 +23,11 @@ Solver::Result Sphere::intersect(const Ray & ray)
|
|||||||
+ ray.getOrigin()[2] * ray.getOrigin()[2]
|
+ ray.getOrigin()[2] * ray.getOrigin()[2]
|
||||||
- m_radius2);
|
- m_radius2);
|
||||||
Solver::Result quadSolutions = solver.solve();
|
Solver::Result quadSolutions = solver.solve();
|
||||||
int resIdx = 0;
|
|
||||||
for (int i = 0; i < quadSolutions.numResults; i++)
|
for (int i = 0; i < quadSolutions.numResults; i++)
|
||||||
{
|
{
|
||||||
if (quadSolutions.results[i] >= 0.0)
|
if (quadSolutions.results[i] >= 0.0)
|
||||||
{
|
{
|
||||||
res.results[resIdx] = quadSolutions.results[i];
|
res.results[res.numResults++] = quadSolutions.results[i];
|
||||||
resIdx++;
|
|
||||||
res.numResults = resIdx;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -2,14 +2,20 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "util/Transform.h"
|
#include "util/Transform.h"
|
||||||
|
#include "shapes/Sphere.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Transform t;
|
Sphere s(1.0);
|
||||||
t.scale(3, 2, 1);
|
Ray ray(Vector(0, -2.5, 0), Vector(0, 1, 0));
|
||||||
t.translate(-1, 2, 3);
|
|
||||||
cout << "t:" << endl << t.getMatrix();
|
Solver::Result res = s.intersect(ray);
|
||||||
|
|
||||||
|
for (int i = 0; i < res.numResults; i++)
|
||||||
|
{
|
||||||
|
cout << "t: " << res.results[i] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ Solver::Result QuadraticSolver::solve()
|
|||||||
{
|
{
|
||||||
double sqrt_discriminant = sqrt(discriminant);
|
double sqrt_discriminant = sqrt(discriminant);
|
||||||
double two_a = 2.0 * a;
|
double two_a = 2.0 * a;
|
||||||
if (sqrt_discriminant = 0.0)
|
if (sqrt_discriminant == 0.0)
|
||||||
{
|
{
|
||||||
res.numResults = 1;
|
res.numResults = 1;
|
||||||
res.results[0] = (-b) / two_a;
|
res.results[0] = (-b) / two_a;
|
||||||
@ -61,6 +61,9 @@ CubicSolver::CubicSolver(double a, double b, double c, double d)
|
|||||||
|
|
||||||
Solver::Result CubicSolver::solve()
|
Solver::Result CubicSolver::solve()
|
||||||
{
|
{
|
||||||
|
Result res;
|
||||||
|
/* TODO: fill in */
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -74,6 +77,9 @@ QuarticSolver::QuarticSolver(double a, double b, double c, double d, double e)
|
|||||||
|
|
||||||
Solver::Result QuarticSolver::solve()
|
Solver::Result QuarticSolver::solve()
|
||||||
{
|
{
|
||||||
|
Result res;
|
||||||
|
/* TODO: fill in */
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Solver::Result::Result()
|
Solver::Result::Result()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user