Added world

main
Brett 2022-10-16 19:24:37 -04:00
parent eea8858ba9
commit cdfccf3af6
20 changed files with 124 additions and 66 deletions

View File

@ -39,7 +39,7 @@
{
"directoryIndex" : 0,
"id" : "Step_2::@6890427a1f51a3e7e1df",
"jsonFile" : "target-Step_2-Debug-1b9d92daa500881ba5b0.json",
"jsonFile" : "target-Step_2-Debug-f326f2bc76ba1d73161a.json",
"name" : "Step_2",
"projectIndex" : 0
}

View File

@ -26,7 +26,7 @@
"objects" :
[
{
"jsonFile" : "codemodel-v2-65c5e759a9cfc8190eac.json",
"jsonFile" : "codemodel-v2-ba5d61e3b487460a88f4.json",
"kind" : "codemodel",
"version" :
{
@ -86,7 +86,7 @@
},
"codemodel-v2" :
{
"jsonFile" : "codemodel-v2-65c5e759a9cfc8190eac.json",
"jsonFile" : "codemodel-v2-ba5d61e3b487460a88f4.json",
"kind" : "codemodel",
"version" :
{

View File

@ -69,7 +69,8 @@
0,
1,
2,
3
3,
4
]
}
],
@ -105,7 +106,8 @@
0,
1,
2,
3
3,
4
]
}
],
@ -134,6 +136,12 @@
"compileGroupIndex" : 0,
"path" : "src/util/parser.cpp",
"sourceGroupIndex" : 0
},
{
"backtrace" : 1,
"compileGroupIndex" : 0,
"path" : "src/world.cpp",
"sourceGroupIndex" : 0
}
],
"type" : "EXECUTABLE"

Binary file not shown.

View File

@ -1,50 +1,20 @@
# ninja log v5
1 833 1665950314933410550 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
1 678 1665961704287045738 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
1 759 1665944946266757803 CMakeFiles/Step_2.dir/src/util/parser.cpp.o dc1044c577ff67b5
1 669 1665950314769405803 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
833 898 1665950314997412403 Step_2 433ae0a1d1e6ff99
1 844 1665950079006588585 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
1 699 1665950363922828771 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
1 754 1665950363974830277 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
754 813 1665950364034832013 Step_2 433ae0a1d1e6ff99
1 661 1665950380443307133 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
1 800 1665950380583311190 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
800 861 1665950380643312924 Step_2 433ae0a1d1e6ff99
0 597 1665950391343622792 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
0 810 1665950391559629046 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
810 867 1665950391615630666 Step_2 433ae0a1d1e6ff99
1 640 1665950522607425534 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
0 823 1665950522791430867 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
823 898 1665950522863432955 Step_2 433ae0a1d1e6ff99
1 614 1665950622846331140 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
1 765 1665950622998335545 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
765 822 1665950623054337170 Step_2 433ae0a1d1e6ff99
0 692 1665950644830968566 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
0 867 1665950645002973552 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
867 949 1665950645086975987 Step_2 433ae0a1d1e6ff99
1 665 1665950683596092655 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
1 761 1665950683692095439 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
761 827 1665950683760097411 Step_2 433ae0a1d1e6ff99
0 610 1665953395918041854 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
0 701 1665953396010044394 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
701 749 1665953396058045718 Step_2 433ae0a1d1e6ff99
1 587 1665953461163849017 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
1 727 1665953461303852909 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
727 783 1665953461359854465 Step_2 433ae0a1d1e6ff99
0 591 1665953486568555963 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
0 704 1665953486680559083 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
704 752 1665953486728560421 Step_2 433ae0a1d1e6ff99
0 833 1665953506613114959 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
0 1007 1665953506761119089 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
1007 1054 1665953506833121100 Step_2 433ae0a1d1e6ff99
1 625 1665956064190838051 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
1 746 1665956064310841527 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
1 605 1665961704211044882 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
678 729 1665961704335046281 Step_2 433ae0a1d1e6ff99
1 794 1665956064358842916 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
794 842 1665956064406844308 Step_2 433ae0a1d1e6ff99
0 724 1665956208455019385 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
724 775 1665956208507020893 Step_2 433ae0a1d1e6ff99
1 606 1665956905387271404 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
1 676 1665956905459273496 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
676 724 1665956905503274776 Step_2 433ae0a1d1e6ff99
0 698 1665956972185214983 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
698 749 1665956972233216380 Step_2 433ae0a1d1e6ff99
1 666 1665962529309923565 CMakeFiles/Step_2.dir/src/world.cpp.o abef135c83fe5bb1
0 784 1665962529425926118 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
0 797 1665962529441926471 CMakeFiles/Step_2.dir/src/util/parser.cpp.o dc1044c577ff67b5
0 833 1665962529477927265 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
1 632 1665962555586503895 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
1 643 1665962555598504163 CMakeFiles/Step_2.dir/src/world.cpp.o abef135c83fe5bb1
1 763 1665962555718506820 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
1 792 1665962555746507439 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
1 807 1665962555762507796 CMakeFiles/Step_2.dir/src/util/parser.cpp.o dc1044c577ff67b5
807 858 1665962555814508947 Step_2 513d6b5f7b82bcb
0 716 1665962616055852133 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
716 766 1665962616103853211 Step_2 513d6b5f7b82bcb
0 714 1665962634216260280 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
714 764 1665962634268261450 Step_2 513d6b5f7b82bcb

Binary file not shown.

View File

@ -1,3 +1,3 @@
Start testing: Oct 16 17:49 EDT
Start testing: Oct 16 19:23 EDT
----------------------------------------------------------
End testing: Oct 16 17:49 EDT
End testing: Oct 16 19:23 EDT

View File

@ -77,6 +77,13 @@ build CMakeFiles/Step_2.dir/src/util/parser.cpp.o: CXX_COMPILER__Step_2_Debug /h
OBJECT_DIR = CMakeFiles/Step_2.dir
OBJECT_FILE_DIR = CMakeFiles/Step_2.dir/src/util
build CMakeFiles/Step_2.dir/src/world.cpp.o: CXX_COMPILER__Step_2_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 2/src/world.cpp || cmake_object_order_depends_target_Step_2
DEP_FILE = CMakeFiles/Step_2.dir/src/world.cpp.o.d
FLAGS = -g -std=gnu++20
INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 2/include"
OBJECT_DIR = CMakeFiles/Step_2.dir
OBJECT_FILE_DIR = CMakeFiles/Step_2.dir/src
# =============================================================================
# Link build statements for EXECUTABLE target Step_2
@ -85,7 +92,7 @@ build CMakeFiles/Step_2.dir/src/util/parser.cpp.o: CXX_COMPILER__Step_2_Debug /h
#############################################
# Link the executable Step_2
build Step_2: CXX_EXECUTABLE_LINKER__Step_2_Debug CMakeFiles/Step_2.dir/src/image/image.cpp.o CMakeFiles/Step_2.dir/src/main.cpp.o CMakeFiles/Step_2.dir/src/raytracing.cpp.o CMakeFiles/Step_2.dir/src/util/parser.cpp.o
build Step_2: CXX_EXECUTABLE_LINKER__Step_2_Debug CMakeFiles/Step_2.dir/src/image/image.cpp.o CMakeFiles/Step_2.dir/src/main.cpp.o CMakeFiles/Step_2.dir/src/raytracing.cpp.o CMakeFiles/Step_2.dir/src/util/parser.cpp.o CMakeFiles/Step_2.dir/src/world.cpp.o
FLAGS = -g
OBJECT_DIR = CMakeFiles/Step_2.dir
POST_BUILD = :

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 101 KiB

View File

@ -85,7 +85,8 @@ namespace Raytracing {
PRECISION_TYPE length{0};
};
// return true if the ray intersects with this object, only between min and max
virtual HitData checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) = 0;
[[nodiscard]] virtual HitData checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const = 0;
virtual ~Object() = default;
};
class SphereObject : public Object {
@ -96,7 +97,7 @@ namespace Raytracing {
public:
SphereObject(const vec4& position, PRECISION_TYPE radius): position(position), radius(radius) {}
virtual HitData checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max);
[[nodiscard]] virtual HitData checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const;
};
}

View File

@ -23,6 +23,7 @@
#include <locale>
#include <sstream>
#include <algorithm>
#include <limits>
/**
* defines
@ -32,12 +33,18 @@
#define RAYTRACING_VERSION_PATCH 1
#define RAYTRACING_VERSION_STRING "0.0.1"
/**
* Constants
*/
const double infinity = std::numeric_limits<double>::infinity();
const double PI = 3.1415926535897932385;
/**
* classes
*/
static inline double degreeeToRadian(double deg){
return deg * 3.1415/180;
return deg * PI/180.0;
}
namespace Raytracing {

30
Step 2/include/world.h Normal file
View File

@ -0,0 +1,30 @@
/*
* Created by Brett Terpstra 6920201 on 16/10/22.
* Copyright (c) 2022 Brett Terpstra. All Rights Reserved.
*/
#ifndef STEP_2_WORLD_H
#define STEP_2_WORLD_H
#include <util/std.h>
#include <raytracing.h>
namespace Raytracing {
class World {
private:
// store all the objects in the world,
std::vector<Object*> objects;
/*TODO: create a kd-tree or bvh version to store the objects
* this way we can easily tell if a ray is near and object or not
* saving on computation
*/
public:
World() {}
inline void add(Object* object) {objects.push_back(object);}
[[nodiscard]] virtual Object::HitData checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const;
~World();
};
}
#endif //STEP_2_WORLD_H

View File

@ -2,15 +2,15 @@
#include "util/parser.h"
#include "image/image.h"
#include <raytracing.h>
#include <world.h>
/**
* Brett Terpstra 6920201
*
*/
Raytracing::vec4 getRayColor(const Raytracing::Ray& ray){
Raytracing::SphereObject obj(Raytracing::vec4(0,0,-1,0), 0.5);
auto hit = obj.checkIfHit(ray, 0, 1000);
Raytracing::vec4 getRayColor(const Raytracing::World& world, const Raytracing::Ray& ray){
auto hit = world.checkIfHit(ray, 0, 1000);
if (hit.hit) {
return 0.5*Raytracing::vec4(hit.normal.x()+1, hit.normal.y()+1, hit.normal.z()+1);
}
@ -57,11 +57,15 @@ int main(int argc, char** args) {
Raytracing::Image image(1366, 768);
Raytracing::Camera camera(90, image);
camera.lookAt(Raytracing::vec4(0,2,0), Raytracing::vec4(0, 0, -1), Raytracing::vec4(0, 1, 0));
camera.lookAt(Raytracing::vec4(0,1,0), Raytracing::vec4(0, 0, -1), Raytracing::vec4(0, 1, 0));
Raytracing::World world;
world.add(new Raytracing::SphereObject(Raytracing::vec4(0,0,-1,0), 0.5));
world.add(new Raytracing::SphereObject(Raytracing::vec4(0,-100.5,-1,0), 100));
for (int i = 0; i < image.getWidth(); i++){
for (int j = 0; j < image.getHeight(); j++){
image.setPixelColor(i, j, getRayColor(camera.projectRay(i, j)));
image.setPixelColor(i, j, getRayColor(world, camera.projectRay(i, j)));
}
}

View File

@ -30,7 +30,7 @@ namespace Raytracing {
// TODO:
}
Object::HitData SphereObject::checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) {
Object::HitData SphereObject::checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const {
PRECISION_TYPE radiusSquared = radius * radius;
// move the ray to be with respects to the sphere
vec4 RayWRTSphere = ray.getStartingPoint() - position;
@ -48,11 +48,11 @@ namespace Raytracing {
return {false, vec4(), vec4(), 0};
// now we have to find the root which exists inside our range [min,max]
auto root = (-b - sqrt(discriminant)) / a;
auto root = (-b - std::sqrt(discriminant)) / a;
// if the first root isn't in our range
if (root < min || root > max) {
// check the second root
root = (-b + sqrt(discriminant)) / a;
root = (-b + std::sqrt(discriminant)) / a;
if (root < min || root > max) {
// if the second isn't in the range then we also must return false.
return {false, vec4(), vec4(), 0};
@ -62,6 +62,12 @@ namespace Raytracing {
auto RayAtRoot = ray.along(root);
// The normal of a sphere is just the point of the hit minus the center position
auto normal = (RayAtRoot - position).normalize();
/*if (Raytracing::vec4::dot(ray.getDirection(), normal) > 0.0) {
tlog << "ray inside sphere\n";
} else
tlog << "ray outside sphere\n";
*/
return {true, RayAtRoot, normal, root};
}
}

25
Step 2/src/world.cpp Normal file
View File

@ -0,0 +1,25 @@
/*
* Created by Brett Terpstra 6920201 on 16/10/22.
* Copyright (c) 2022 Brett Terpstra. All Rights Reserved.
*/
#include <world.h>
namespace Raytracing {
World::~World() {
for (auto* p : objects)
delete(p);
}
Object::HitData World::checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const {
auto hResult = Object::HitData{false, vec4(), vec4(), max};
for (auto* obj : objects){
// check up to the point of the last closest hit,
// will give the closest object's hit result
auto cResult = obj->checkIfHit(ray, min, hResult.length);
if (cResult.hit)
hResult = cResult;
}
return hResult;
}
}