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

Assignment2 #15

Open
wants to merge 1 commit 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 @@
**Deadline**: 21.10.2021

Please put your name here:
**Name**: .......
**Name**: Alexandru Rotileanu
## Problem 1
### Encapsulate camera and primitives from main application logic (Points 5)
1. Fork the current repository
Expand Down
Binary file added renders/flat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added renders/flat2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 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 Expand Up @@ -30,6 +30,8 @@ class CLightOmni : public ILight


private:

Vec3f m_intensity; ///< The emission (red, green, blue)
Vec3f m_org; ///< The light source origin

};
4 changes: 3 additions & 1 deletion src/PrimPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ class CPrimPlane : public IPrim

ray.t = dist;
// --- PUT YOUR CODE HERE ---
ray.hit = shared_from_this();

return true;
}

virtual Vec3f getNormal(const Ray& ray) const override
{
// --- PUT YOUR CODE HERE ---
return Vec3f();
return m_normal;
}

private:
Expand Down
4 changes: 3 additions & 1 deletion src/PrimSphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ class CPrimSphere : public IPrim

ray.t = dist;
// --- PUT YOUR CODE HERE ---

ray.hit = shared_from_this();
return true;
}

virtual Vec3f getNormal(const Ray& ray) const override
{
// --- PUT YOUR CODE HERE ---
return Vec3f();
return normalize(ray.org + ray.t * ray.dir - m_origin);
}

private:
Expand Down
6 changes: 5 additions & 1 deletion src/PrimTriangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ class CPrimTriangle : public IPrim

ray.t = f;
// --- PUT YOUR CODE HERE ---

ray.hit = shared_from_this();

return true;
}

virtual Vec3f getNormal(const Ray& ray) const override
{
// --- PUT YOUR CODE HERE ---
return Vec3f();
Vec3f normal = m_edge1.cross(m_edge2);
return normalize(normal);
}

private:
Expand Down
28 changes: 27 additions & 1 deletion src/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CScene
void add(const ptr_prim_t pPrim)
{
// --- PUT YOUR CODE HERE ---
m_vpPrims.push_back(pPrim);
}
/**
* @brief Adds a new light to the scene
Expand All @@ -38,6 +39,7 @@ class CScene
void add(const ptr_light_t pLight)
{
// --- PUT YOUR CODE HERE ---
m_vpLights.push_back(pLight);
}
/**
* @brief Adds a new camera to the scene and makes it to ba active
Expand All @@ -46,6 +48,8 @@ class CScene
void add(const ptr_camera_t pCamera)
{
// --- PUT YOUR CODE HERE ---
m_vpCameras.push_back(pCamera);
m_activeCamera = m_vpCameras.size() - 1;
}
/**
* @brief Returns the container with all scene light source objects
Expand All @@ -68,6 +72,21 @@ class CScene
bool intersect(Ray& ray) const
{
// --- PUT YOUR CODE HERE ---

/*std::vector<ptr_prim_t>::iterator it;

for(it = m_vpPrims.begin(); it != m_vpPrims.end(); it++)
{

}*/

int i = 0;
for(int i = 0; i < m_vpPrims.size(); i++)
{
if(m_vpPrims[i]->intersect(ray))
return true;
}

return false;
}

Expand All @@ -87,7 +106,14 @@ class CScene
Vec3f RayTrace(Ray& ray) const
{
// --- PUT YOUR CODE HERE ---
return Vec3f();
Vec3f col = RGB(0, 0 ,0); //black

if(intersect(ray))
{
col = ray.hit->getShader()->shade(ray);
}

return col;
}


Expand Down
14 changes: 13 additions & 1 deletion src/ShaderEyelight.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ class CShaderEyelight : public CShaderFlat
virtual Vec3f shade(const Ray& ray) const override
{
// --- PUT YOUR CODE HERE ---
return RGB(0, 0, 0);

Vec3f normal = ray.hit->getNormal(ray);


//theta is the angle between the primitive surface normal and the ray direction

float theta;
float dot = normal.dot(ray.dir);




return CShaderFlat::shade(ray) * fabs(dot);
}
};

2 changes: 1 addition & 1 deletion src/ShaderFlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CShaderFlat : public IShader
virtual Vec3f shade(const Ray& ray = Ray()) const override
{
// --- PUT YOUR CODE HERE ---
return RGB(0, 0, 0);
return m_color;
}

private:
Expand Down