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

Assignment 1 : Submission #13

Open
wants to merge 17 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
181 changes: 181 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.21

# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:

#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:

# Disable VCS-based implicit rules.
% : %,v

# Disable VCS-based implicit rules.
% : RCS/%

# Disable VCS-based implicit rules.
% : RCS/%,v

# Disable VCS-based implicit rules.
% : SCCS/s.%

# Disable VCS-based implicit rules.
% : s.%

.SUFFIXES: .hpux_make_needs_suffix_list

# Command-line flag to silence nested $(MAKE).
$(VERBOSE)MAKESILENT = -s

#Suppress display of executed commands.
$(VERBOSE).SILENT:

# A target that is always out of date.
cmake_force:
.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/local/Cellar/cmake/3.21.3/bin/cmake

# The command to remove a file.
RM = /usr/local/Cellar/cmake/3.21.3/bin/cmake -E rm -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /Users/amartyavats/Downloads/CG/HW3/eyden-tracer-01

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /Users/amartyavats/Downloads/CG/HW3/eyden-tracer-01

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/local/Cellar/cmake/3.21.3/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast

# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/local/Cellar/cmake/3.21.3/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast

# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /Users/amartyavats/Downloads/CG/HW3/eyden-tracer-01/CMakeFiles /Users/amartyavats/Downloads/CG/HW3/eyden-tracer-01//CMakeFiles/progress.marks
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /Users/amartyavats/Downloads/CG/HW3/eyden-tracer-01/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean
.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named eyden-tracer

# Build rule for target.
eyden-tracer: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 eyden-tracer
.PHONY : eyden-tracer

# fast build rule for target.
eyden-tracer/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/eyden-tracer.dir/build.make CMakeFiles/eyden-tracer.dir/build
.PHONY : eyden-tracer/fast

src/main.o: src/main.cpp.o
.PHONY : src/main.o

# target to build an object file
src/main.cpp.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/eyden-tracer.dir/build.make CMakeFiles/eyden-tracer.dir/src/main.cpp.o
.PHONY : src/main.cpp.o

src/main.i: src/main.cpp.i
.PHONY : src/main.i

# target to preprocess a source file
src/main.cpp.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/eyden-tracer.dir/build.make CMakeFiles/eyden-tracer.dir/src/main.cpp.i
.PHONY : src/main.cpp.i

src/main.s: src/main.cpp.s
.PHONY : src/main.s

# target to generate assembly for a file
src/main.cpp.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/eyden-tracer.dir/build.make CMakeFiles/eyden-tracer.dir/src/main.cpp.s
.PHONY : src/main.cpp.s

# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... eyden-tracer"
@echo "... src/main.o"
@echo "... src/main.i"
@echo "... src/main.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

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**: 30.09.20201

Please put your name here:
**Name**: .......
**Name**: Amartya Vats
## Foreword
### Implementation of a Minimal Ray Tracing System

Expand Down
45 changes: 43 additions & 2 deletions src/CameraEnvironmental.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@


#pragma once

#include "ICamera.h"
#include "ray.h"

// --- IMPLENET class CCameraEnvironmental ---
// --- PUT YOUR CODE HERE ---
class CCameraEnvironmental: public ICamera {

public:

CCameraEnvironmental(Size resolution, const Vec3f& pos, const Vec3f& dir, const Vec3f& up) :
ICamera(resolution),
m_pos(pos),
m_dir(dir),
m_up(up)

{

}

virtual ~CCameraEnvironmental(void) = default;

virtual void InitRay(Ray& ray, int x, int y) {
Size res = getResolution();


float theta = Pif * (static_cast<float>(y) / res.height);
float phi = Pif * 2 * (static_cast<float>(x) / res.width);

m_zAxis = m_dir;
m_xAxis = normalize(m_zAxis.cross(m_up));
m_yAxis = normalize(m_zAxis.cross(m_xAxis));

ray.org = m_pos;
ray.dir = normalize(cosf(phi) * sinf(theta) * m_xAxis + sinf(theta) * sinf(phi) * m_zAxis - cosf(theta) * m_yAxis);
ray.t = std::numeric_limits<float>::infinity();
}

private:
Vec3f m_pos;
Vec3f m_dir;
Vec3f m_up;

Vec3f m_xAxis;
Vec3f m_yAxis;
Vec3f m_zAxis;
};
23 changes: 18 additions & 5 deletions src/CameraPerspective.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,29 @@ class CCameraPerspective : public ICamera
, m_dir(dir)
, m_up(up)
{
// --- PUT YOUR CODE HERE ---

this -> m_focus = 1.0f / tanf(angle * Pif / 360);
}
virtual ~CCameraPerspective(void) = default;

virtual void InitRay(Ray& ray, int x, int y) override
{
// --- PUT YOUR CODE HERE ---
}
Size resolution = getResolution();

float ndcx = static_cast<float>(x) / resolution.width;
float ndcy = static_cast<float>(y) / resolution.height;

float sscx = 2 * ndcx - 1;
float sscy = 2 * ndcy - 1;

Vec3f zAxis = this -> m_dir;
Vec3f xAxis = normalize(zAxis.cross(this -> m_up));
Vec3f yAxis = normalize(zAxis.cross(xAxis));

ray.org = m_pos;
ray.dir = normalize(getAspectRatio() * sscx * xAxis + sscy * yAxis + m_dir * zAxis);
ray.t = std::numeric_limits<float>::infinity();
}

private:
// input values
Expand All @@ -49,5 +63,4 @@ class CCameraPerspective : public ICamera
Vec3f m_xAxis; ///< Camera x-axis in WCS
Vec3f m_yAxis; ///< Camera y-axis in WCS
Vec3f m_zAxis; ///< Camera z-axis in WCS
};

};
42 changes: 41 additions & 1 deletion src/PrimDisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,44 @@
#include "ray.h"

// --- IMPLENET class CPrimDisc ---
// --- PUT YOUR CODE HERE ---
// --- PUT YOUR CODE HERE ---

class CPrimDisc : public IPrim {

public:

CPrimDisc(const Vec3f& origin, const Vec3f& normal, float radius):
IPrim(),
m_origin(origin),
m_normal(normal),
m_radius(radius)
{
normalize(m_normal);
}

virtual ~CPrimDisc(void) = default;

virtual bool intersect(Ray& ray) const override{
float dist = (this -> m_origin - ray.org).dot(this -> m_normal) / ray.dir.dot(this -> m_normal);
if (dist < Epsilon || isinf(dist) || ray.t < dist) {
return false;
}
Vec3f vec_from_org = (ray.org + dist * ray.dir) - m_origin;

float dist_from_org = (sqrt(vec_from_org.dot(vec_from_org)));

if (dist_from_org > m_radius) {
return false;
}

ray.t = dist;
return true;
}

private:

Vec3f m_normal;
Vec3f m_origin;
float m_radius;

};
34 changes: 20 additions & 14 deletions src/PrimPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,45 @@
#pragma once

#include "IPrim.h"
#include "ray.h"

// ================================ Infinite Plane Primitive Class ================================
/**
* @brief The Plane Geometrical Primitive class
* @ingroup modulePrimitive
* @author Sergey G. Kosov, [email protected]
*/
class CPrimPlane : public IPrim
* @brief The Plane Geaometrical Primitive class
*/
class CPrimPlane : public CPrim
{
public:
/**
* @brief Constructor
* @param origin Point on the plane
* @param normal Normal to the plane
* @param color Color of the primitive
*/
CPrimPlane(const Vec3f& origin, const Vec3f& normal)
: IPrim()
CPrimPlane(Vec3f color, Vec3f origin, Vec3f normal)
: CPrim(color)
, m_normal(normal)
, m_origin(origin)
{
normalize(m_normal);
}
virtual ~CPrimPlane(void) = default;

virtual bool intersect(Ray& ray) const override
virtual bool Intersect(Ray& ray) override
{
// --- PUT YOUR CODE HERE ---
return false;
float x;
if(m_normal.dot(ray.dir) == 0)
return false;
else
x = (m_origin.dot(m_normal)-ray.org.dot(m_normal))/ray.dir.dot(m_normal);

if(x<Epsilon || x>ray.t)
return false;

ray.t = x;
return true;
}


private:
Vec3f m_normal; ///< Point on the plane
Vec3f m_origin; ///< Normal to the plane
Vec3f m_normal; ///< Normal on the plane
Vec3f m_origin; ///< Point to the plane
};
Loading