2 gph-math - math library for graphics programs
3 Copyright (C) 2016 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software. Feel free to use, modify, and/or redistribute
6 it under the terms of the MIT/X11 license. See LICENSE for details.
7 If you intend to redistribute parts of the code without the LICENSE file
8 replace this paragraph with the full contents of the LICENSE file.
22 Ray() : dir(0, 0, 1) {}
23 Ray(const Vector3 &o, const Vector3 &d) : origin(o), dir(d) {}
26 inline Ray operator *(const Ray &r, const Matrix4x4 &m)
29 up[0][3] = up[1][3] = up[2][3] = up[3][0] = up[3][1] = up[3][2] = 0.0;
32 return Ray(r.origin * m, r.dir * up);
35 inline Ray operator *(const Matrix4x4 &m, const Ray &r)
38 up[0][3] = up[1][3] = up[2][3] = up[3][0] = up[3][1] = up[3][2] = 0.0;
41 return Ray(m * r.origin, m * r.dir);
45 inline Ray reflect(const Ray &ray, const Vector3 &n)
47 return Ray(ray.origin, reflect(ray.dir, n));
50 inline Ray refract(const Ray &ray, const Vector3 &n, float ior)
52 return Ray(ray.origin, refract(ray.dir, n, ior));
55 inline Ray refract(const Ray &ray, const Vector3 &n, float from_ior, float to_ior)
57 return Ray(ray.origin, refract(ray.dir, n, from_ior, to_ior));
63 #endif // GMATH_RAY_H_