mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 15:31:59 +00:00
add ray constructor
This commit is contained in:
parent
29c5fe91d9
commit
e4e2d26a16
2 changed files with 23 additions and 2 deletions
|
@ -4,6 +4,13 @@ void Geometry::setTransform(const Matrix4f &transform) {
|
||||||
this->transform = transform;
|
this->transform = transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sphere::intersect(const Ray &r) const { return false; }
|
bool Sphere::intersect(const Ray &r) const {
|
||||||
|
Vector3f originCenter = r.getOrigin() - center;
|
||||||
|
int a = r.getDirection().dot(r.getDirection());
|
||||||
|
int b = 2 * originCenter.dot(r.getDirection());
|
||||||
|
int c = originCenter.dot(originCenter) - radius * radius;
|
||||||
|
|
||||||
|
return b * b - 4 * a * c >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool Rectangle::intersect(const Ray &r) const { return false; }
|
bool Rectangle::intersect(const Ray &r) const { return false; }
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "../external/simpleppm.h"
|
#include "../external/simpleppm.h"
|
||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
#include "Ray.h"
|
#include "Ray.h"
|
||||||
|
#include <Eigen/src/Core/Matrix.h>
|
||||||
|
|
||||||
void RayTracer::parse() {
|
void RayTracer::parse() {
|
||||||
for (auto i = json["output"].begin(); i != json["output"].end(); ++i)
|
for (auto i = json["output"].begin(); i != json["output"].end(); ++i)
|
||||||
|
@ -17,7 +18,20 @@ void RayTracer::parse() {
|
||||||
Ray getRay(int x, int y, const Vector3f &camPos, const Vector3f &lookat,
|
Ray getRay(int x, int y, const Vector3f &camPos, const Vector3f &lookat,
|
||||||
float fov, int width, int height) {
|
float fov, int width, int height) {
|
||||||
// TODO: compute ray
|
// TODO: compute ray
|
||||||
return Ray(Vector3f(), Vector3f());
|
float viewportHeight = 2.0f;
|
||||||
|
float viewportWidth = viewportHeight * width / height;
|
||||||
|
Vector3f viewportU = Vector3f(viewportWidth, 0, 0);
|
||||||
|
Vector3f viewportV = Vector3f(0, -viewportHeight, 0);
|
||||||
|
|
||||||
|
Vector3f deltaU = viewportU / width;
|
||||||
|
Vector3f deltaV = viewportV / height;
|
||||||
|
|
||||||
|
Vector3f viewportUpperLeft = camPos - lookat - viewportU / 2 - viewportV / 2;
|
||||||
|
Vector3f pixelUpperLeftPos = viewportUpperLeft + 0.5 * (deltaU + deltaV);
|
||||||
|
|
||||||
|
Vector3f pixelCenter = pixelUpperLeftPos + (x * deltaU) + (y * deltaV);
|
||||||
|
|
||||||
|
return Ray(camPos, pixelCenter - camPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayTracer::render(Scene *scene) {
|
void RayTracer::render(Scene *scene) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue