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
|
||||
export CPPFLAGS += -I"$(shell pwd)"
|
||||
endif
|
||||
export CXXFLAGS := -O3
|
||||
export CXXFLAGS := -Wall -O3
|
||||
|
||||
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 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 */
|
||||
Solver::Result intersections = (*it)->intersect(transformed_ray);
|
||||
Solver::Result intersections = (*it)->intersect(local_ray);
|
||||
|
||||
if (intersections.numResults > 0)
|
||||
{
|
||||
Vector local_intersection_point =
|
||||
transformed_ray[intersections.results[0]];
|
||||
Vector normal = (*it)->getNormalAt(local_intersection_point);
|
||||
double dot = -(normal % transformed_ray.getDirection());
|
||||
cout << "got dot " << dot << endl;
|
||||
Vector local_normal =
|
||||
(*it)->getNormalAt(local_ray[intersections.results[0]]);
|
||||
double dot = local_ray.getDirection() % local_normal;
|
||||
dot = -dot;
|
||||
if (dot < 0.0)
|
||||
dot = 0.0;
|
||||
pixel[BMP_RED] = (unsigned char) (0xFF * dot);
|
||||
pixel[BMP_GREEN] = (unsigned char) (0xFF * dot);
|
||||
pixel[BMP_BLUE] = (unsigned char) (0xFF * dot);
|
||||
pixel[BMP_RED] = 0xFF * dot;
|
||||
pixel[BMP_GREEN] = 0xFF * dot;
|
||||
pixel[BMP_BLUE] = 0xFF * dot;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
#include "Sphere.h"
|
||||
#include "util/Solver.h"
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
@ -22,14 +23,11 @@ Solver::Result Sphere::intersect(const Ray & ray)
|
||||
+ ray.getOrigin()[2] * ray.getOrigin()[2]
|
||||
- m_radius2);
|
||||
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;
|
||||
res.results[res.numResults++] = quadSolutions.results[i];
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
@ -2,14 +2,20 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include "util/Transform.h"
|
||||
#include "shapes/Sphere.h"
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
Transform t;
|
||||
t.scale(3, 2, 1);
|
||||
t.translate(-1, 2, 3);
|
||||
cout << "t:" << endl << t.getMatrix();
|
||||
Sphere s(1.0);
|
||||
Ray ray(Vector(0, -2.5, 0), Vector(0, 1, 0));
|
||||
|
||||
Solver::Result res = s.intersect(ray);
|
||||
|
||||
for (int i = 0; i < res.numResults; i++)
|
||||
{
|
||||
cout << "t: " << res.results[i] << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ Solver::Result QuadraticSolver::solve()
|
||||
{
|
||||
double sqrt_discriminant = sqrt(discriminant);
|
||||
double two_a = 2.0 * a;
|
||||
if (sqrt_discriminant = 0.0)
|
||||
if (sqrt_discriminant == 0.0)
|
||||
{
|
||||
res.numResults = 1;
|
||||
res.results[0] = (-b) / two_a;
|
||||
@ -61,6 +61,9 @@ CubicSolver::CubicSolver(double a, double b, double c, double d)
|
||||
|
||||
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()
|
||||
{
|
||||
Result res;
|
||||
/* TODO: fill in */
|
||||
return res;
|
||||
}
|
||||
|
||||
Solver::Result::Result()
|
||||
|
Loading…
x
Reference in New Issue
Block a user