Removed cmath dependency.
This commit is contained in:
2
Makefile
2
Makefile
@@ -3,7 +3,7 @@ HEADERS = ray.hpp figure.hpp sphere.hpp plane.hpp disk.hpp material.hpp light.hp
|
|||||||
OBJECTS = main.o sphere.o plane.o disk.o directional_light.o tracer.o
|
OBJECTS = main.o sphere.o plane.o disk.o directional_light.o tracer.o
|
||||||
CXX = g++
|
CXX = g++
|
||||||
CXXFLAGS = -ansi -pedantic -Wall -g -DGLM_FORCE_RADIANS -fopenmp
|
CXXFLAGS = -ansi -pedantic -Wall -g -DGLM_FORCE_RADIANS -fopenmp
|
||||||
LDLIBS = -lm
|
LDLIBS =
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
#include <cmath>
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/constants.hpp>
|
#include <glm/gtc/constants.hpp>
|
||||||
|
|
||||||
@@ -8,12 +6,14 @@
|
|||||||
using glm::pi;
|
using glm::pi;
|
||||||
using glm::reflect;
|
using glm::reflect;
|
||||||
using glm::dot;
|
using glm::dot;
|
||||||
|
using glm::pow;
|
||||||
|
using glm::max;
|
||||||
|
|
||||||
vec3 DirectionalLight::shade(vec3 normal, Ray & r, Material & m) const {
|
vec3 DirectionalLight::shade(vec3 normal, Ray & r, Material & m) const {
|
||||||
float n_dot_l, r_dot_l;
|
float n_dot_l, r_dot_l;
|
||||||
vec3 color, ref;
|
vec3 color, ref;
|
||||||
|
|
||||||
n_dot_l = max(dot(normal, m_position), 0.0);
|
n_dot_l = max(dot(normal, m_position), 0.0f);
|
||||||
color += (m.m_diffuse / pi<float>()) * m_diffuse * n_dot_l;
|
color += (m.m_diffuse / pi<float>()) * m_diffuse * n_dot_l;
|
||||||
|
|
||||||
ref = reflect(m_position, normal);
|
ref = reflect(m_position, normal);
|
||||||
|
@@ -16,10 +16,6 @@ public:
|
|||||||
vec3 m_specular;
|
vec3 m_specular;
|
||||||
vec3 m_ambient;
|
vec3 m_ambient;
|
||||||
|
|
||||||
float max(float a, float b) const {
|
|
||||||
return a >= b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~Light() { }
|
virtual ~Light() { }
|
||||||
|
|
||||||
virtual vec3 shade(vec3 normal, Ray & r, Material & m) const = 0;
|
virtual vec3 shade(vec3 normal, Ray & r, Material & m) const = 0;
|
||||||
|
19073
output.ppm
19073
output.ppm
File diff suppressed because one or more lines are too long
@@ -1,16 +1,14 @@
|
|||||||
#include <cmath>
|
|
||||||
|
|
||||||
#include "plane.hpp"
|
#include "plane.hpp"
|
||||||
|
|
||||||
#define TOL 1e-6
|
#define TOL 1e-6
|
||||||
|
|
||||||
using std::fabs;
|
using glm::abs;
|
||||||
using glm::dot;
|
using glm::dot;
|
||||||
|
|
||||||
bool Plane::intersect(Ray & r, float & t) const {
|
bool Plane::intersect(Ray & r, float & t) const {
|
||||||
float d = dot(r.m_direction, m_normal);
|
float d = dot(r.m_direction, m_normal);
|
||||||
|
|
||||||
if (fabs(d) > TOL) {
|
if (abs(d) > TOL) {
|
||||||
t = dot(m_normal, (m_point - r.m_origin)) / d;
|
t = dot(m_normal, (m_point - r.m_origin)) / d;
|
||||||
return t >= 0.0f;
|
return t >= 0.0f;
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
#include <cmath>
|
|
||||||
|
|
||||||
#include "sphere.hpp"
|
#include "sphere.hpp"
|
||||||
|
|
||||||
using glm::normalize;
|
using glm::normalize;
|
||||||
|
using glm::sqrt;
|
||||||
|
|
||||||
bool Sphere::intersect(Ray & r, float & t) const {
|
bool Sphere::intersect(Ray & r, float & t) const {
|
||||||
float t1, t2;
|
float t1, t2;
|
||||||
|
@@ -17,7 +17,7 @@ using glm::reflect;
|
|||||||
using glm::refract;
|
using glm::refract;
|
||||||
using glm::clamp;
|
using glm::clamp;
|
||||||
using glm::tan;
|
using glm::tan;
|
||||||
using glm::cos;
|
using glm::sqrt;
|
||||||
|
|
||||||
static const vec3 BCKG_COLOR = vec3(0.16f, 0.66f, 0.72f);
|
static const vec3 BCKG_COLOR = vec3(0.16f, 0.66f, 0.72f);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user