Compare commits
No commits in common. "9f4868917d86fd836f96fa081067be5602399a78" and "b2265d26a323c2457c065848ff846e3a9b512c7b" have entirely different histories.
9f4868917d
...
b2265d26a3
2
vec3.h
2
vec3.h
@ -89,7 +89,7 @@ inline Vec3 operator/(const Vec3& v, double t) {
|
|||||||
inline double dot(const Vec3 &u, const Vec3& v) {
|
inline double dot(const Vec3 &u, const Vec3& v) {
|
||||||
return u.e[0] * v.e[0]
|
return u.e[0] * v.e[0]
|
||||||
+ u.e[1] * v.e[1]
|
+ u.e[1] * v.e[1]
|
||||||
+ u.e[2] * v.e[2];
|
+ u.e[2] * v.e[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vec3 cross(const Vec3 &u, const Vec3& v) {
|
inline Vec3 cross(const Vec3 &u, const Vec3& v) {
|
||||||
|
11
wtracer.cpp
11
wtracer.cpp
@ -4,18 +4,7 @@
|
|||||||
#include "vec3.h"
|
#include "vec3.h"
|
||||||
#include "ray.h"
|
#include "ray.h"
|
||||||
|
|
||||||
bool hit_sphere(const Point3& center, double radius, const Ray& r) {
|
|
||||||
Vec3 oc = r.origin() - center;
|
|
||||||
auto a = dot(r.direction(), r.direction());
|
|
||||||
auto b = 2.0 * dot(oc, r.direction());
|
|
||||||
auto c = dot(oc, oc) - radius * radius;
|
|
||||||
auto disciminant = b*b - 4*a*c;
|
|
||||||
return disciminant > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color ray_color(const Ray& r) {
|
Color ray_color(const Ray& r) {
|
||||||
if (hit_sphere(Point3(0, 0, -1), 0.5, r))
|
|
||||||
return Color(1, 0, 0);
|
|
||||||
Vec3 unit_direction = unit_vector(r.direction());
|
Vec3 unit_direction = unit_vector(r.direction());
|
||||||
auto t = 0.5 * (unit_direction.y() + 1.0);
|
auto t = 0.5 * (unit_direction.y() + 1.0);
|
||||||
return (1.0 - t) * Color(1.0, 1.0, 1.0) + t * Color(0.5, 0.7, 1.0);
|
return (1.0 - t) * Color(1.0, 1.0, 1.0) + t * Color(0.5, 0.7, 1.0);
|
||||||
|
Loading…
Reference in New Issue
Block a user