Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Submission #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**Dealine**: 28.10.2021

Please put your name here:
**Name:** .......
**Name:** Amartya Vats
## Problem 1
### Rendering complex geometry (Points 5)
Until now we have only hardcoded our scene geometry in main.cpp. This is of course not practical. In the new framework, a class ```CSolid``` is added. This class may contain complex geometry formed by multiple primitives. Such geometry may be saved / read from an .obj file. For this problem we will read _torus knot.obj_ file and rended this object, which consists of 12 960 triangles. To make the method work proceed as follows:
Expand Down
10 changes: 9 additions & 1 deletion src/BSPTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace {
{
CBoundingBox res;
// --- PUT YOUR CODE HERE ---
for (auto pPrim : vpPrims)
res.extend(pPrim->getBoundingBox());
return res;
}

// Returns the best dimension index for next split
Expand Down Expand Up @@ -55,7 +58,12 @@ class CBSPTree
bool intersect(Ray& ray) const
{
// --- PUT YOUR CODE HERE ---
return false;
double t0 = 0;
double t1 = ray.t;
m_treeBoundingBox.clip(ray, t0, t1);
if (t1 < t0) return false; // no intersection with the bounding box

return m_root->intersect(ray, t0, t1);
}


Expand Down
28 changes: 27 additions & 1 deletion src/BoundingBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,54 @@ namespace {
void CBoundingBox::extend(const Vec3f& p)
{
// --- PUT YOUR CODE HERE ---
m_minPoint = Min3f(p, m_minPoint);
m_maxPoint = Max3f(p,m_maxPoint);
}

void CBoundingBox::extend(const CBoundingBox& box)
{
// --- PUT YOUR CODE HERE ---
extend(box.m_maxPoint);
extend(box.m_minPoint);
}

std::pair<CBoundingBox, CBoundingBox> CBoundingBox::split(int dim, float val) const
{
// --- PUT YOUR CODE HERE ---
auto res = std::make_pair(*this, *this);
res.first.m_maxPoint[dim] = val;
res.second.m_minPoint[dim] = val;
return res;
}

bool CBoundingBox::overlaps(const CBoundingBox& box) const
{
// --- PUT YOUR CODE HERE ---
return false;
for (int dim = 0; dim < 3; dim++) {
if (box.m_minPoint[dim] - Epsilon > m_maxPoint[dim]) return false;
if (box.m_maxPoint[dim] + Epsilon < m_minPoint[dim]) return false;
}
return true;
}

void CBoundingBox::clip(const Ray& ray, double& t0, double& t1) const
{
// --- PUT YOUR CODE HERE ---
for (int i = 0; i < 3; i++) {
if (!ray.dir[i])
continue;

double tmin = (m_minPoint[i] - ray.org[i]) / ray.dir[i];
double tmax = (m_maxPoint[i] - ray.org[i]) / ray.dir[i];

if (tmin > tmax)
swap(tmin, tmax);

t0 = max(t0, tmin);
t1 = min(t1, tmax);

if (t0 > t1)
return;
}
}

2 changes: 1 addition & 1 deletion src/LightOmni.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "ILight.h"
#include "Ray.h"
#include "ray.h"

/**
* @brief Point light source class
Expand Down
6 changes: 4 additions & 2 deletions src/PrimPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ class CPrimPlane : public IPrim

virtual CBoundingBox getBoundingBox(void) const override
{
CBoundingBox bounds;
// CBoundingBox bounds;
// --- PUT YOUR CODE HERE ---
return bounds;
Vec3f minPoint = Vec3f::all(-Infty);
Vec3f maxPoint = Vec3f::all(Infty);
return CBoundingBox(minPoint, maxPoint);
}

private:
Expand Down
1 change: 1 addition & 0 deletions src/PrimSphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CPrimSphere : public IPrim
{
CBoundingBox res;
// --- PUT YOUR CODE HERE ---
res = CBoundingBox(m_origin - Vec3f::all(m_radius), m_origin + Vec3f::all(m_radius));
return res;
}

Expand Down
3 changes: 3 additions & 0 deletions src/PrimTriangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class CPrimTriangle : public IPrim
{
CBoundingBox res;
// --- PUT YOUR CODE HERE ---
res.extend(this->m_a);
res.extend(this->m_b);
res.extend(this->m_c);
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Mat RenderFrame(void)
#ifdef WIN32
const std::string dataPath = "../data/";
#else
const std::string dataPath = "../../data/";
const std::string dataPath = "/Users/amartyavats/Downloads/CG/HW5/eyden-tracer-03/data/";
#endif
CSolid solid(pShader, dataPath + "Torus Knot.obj");
scene.add(solid);
Expand Down