2013-09-05 22:54:45 -07:00
|
|
|
/* basics.h
|
|
|
|
*
|
2013-09-09 23:03:41 -07:00
|
|
|
* Declaration of basic types.
|
|
|
|
*
|
|
|
|
* - Vector3 is a three tuple vector of x, y, and z.
|
|
|
|
* - Ray is a vector plus a direction.
|
|
|
|
* - Color is a four tuple of red, green, blue, and alpha.
|
2013-09-05 22:54:45 -07:00
|
|
|
*
|
|
|
|
* Eryn Wells <eryn@erynwells.me>
|
|
|
|
*/
|
|
|
|
|
2013-09-09 23:03:41 -07:00
|
|
|
#ifndef __BASICS_H__
|
|
|
|
#define __BASICS_H__
|
2013-09-05 22:54:45 -07:00
|
|
|
|
2013-09-22 10:15:41 -07:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
2013-09-09 22:47:19 -07:00
|
|
|
struct Vector3
|
|
|
|
{
|
|
|
|
Vector3();
|
|
|
|
Vector3(float x, float y, float z);
|
2013-09-05 22:54:45 -07:00
|
|
|
|
2013-09-10 16:25:12 -07:00
|
|
|
Vector3 &operator=(const Vector3 &v);
|
2013-09-12 14:59:33 -07:00
|
|
|
Vector3 &operator*=(const float &rhs);
|
|
|
|
Vector3 &operator/=(const float &rhs);
|
|
|
|
Vector3 &operator+=(const Vector3 &rhs);
|
|
|
|
Vector3 &operator-=(const Vector3 &rhs);
|
|
|
|
Vector3 operator*(const float &rhs) const;
|
|
|
|
Vector3 operator/(const float &rhs) const;
|
|
|
|
Vector3 operator+(const Vector3 &rhs) const;
|
|
|
|
Vector3 operator-(const Vector3 &rhs) const;
|
2013-09-10 15:34:08 -07:00
|
|
|
Vector3 operator-() const;
|
|
|
|
|
2013-09-13 11:09:37 -07:00
|
|
|
bool operator==(const Vector3 &rhs) const;
|
|
|
|
bool operator!=(const Vector3 &rhs) const;
|
|
|
|
|
2013-09-10 15:34:08 -07:00
|
|
|
float length2() const;
|
|
|
|
float length() const;
|
2013-09-12 14:59:33 -07:00
|
|
|
float dot(const Vector3 &v) const;
|
2013-09-22 08:37:58 -07:00
|
|
|
Vector3 cross(const Vector3 &v) const;
|
2013-09-05 22:54:45 -07:00
|
|
|
|
2013-09-11 22:07:34 -07:00
|
|
|
Vector3 &normalize();
|
2013-09-05 22:54:45 -07:00
|
|
|
|
2013-09-09 22:47:19 -07:00
|
|
|
static const Vector3 Zero;
|
2013-09-16 16:32:41 -07:00
|
|
|
// Unit vectors in each of the three cartesian directions.
|
|
|
|
static const Vector3 X, Y, Z;
|
|
|
|
|
2013-09-09 22:47:19 -07:00
|
|
|
float x, y, z;
|
|
|
|
};
|
2013-09-05 22:54:45 -07:00
|
|
|
|
2013-09-12 14:59:33 -07:00
|
|
|
const Vector3 operator*(const float &lhs, const Vector3 &rhs);
|
2013-09-22 10:15:41 -07:00
|
|
|
std::ostream &operator<<(std::ostream &os, const Vector3 &v);
|
2013-09-06 19:01:02 -07:00
|
|
|
|
|
|
|
|
2014-07-16 23:23:26 -07:00
|
|
|
Vector3 LinearCombination(const double k1, const Vector3& v1,
|
|
|
|
const double k2, const Vector3& v2,
|
|
|
|
const double k3, const Vector3& v3);
|
|
|
|
|
|
|
|
|
2013-09-09 22:47:19 -07:00
|
|
|
struct Ray
|
|
|
|
{
|
|
|
|
Ray();
|
|
|
|
Ray(Vector3 o, Vector3 d);
|
2013-09-06 19:01:02 -07:00
|
|
|
|
2013-09-11 08:56:53 -07:00
|
|
|
Vector3 parameterize(const float t) const;
|
2013-09-06 21:15:56 -07:00
|
|
|
|
2013-09-09 22:47:19 -07:00
|
|
|
Vector3 origin, direction;
|
|
|
|
};
|
2013-09-06 21:15:56 -07:00
|
|
|
|
2013-09-22 10:15:41 -07:00
|
|
|
std::ostream &operator<<(std::ostream &os, const Ray &r);
|
|
|
|
|
2013-09-06 21:15:56 -07:00
|
|
|
|
2013-09-09 22:47:19 -07:00
|
|
|
struct Color
|
|
|
|
{
|
|
|
|
Color();
|
2013-09-13 14:10:52 -07:00
|
|
|
Color(const float &r, const float &g, const float &b);
|
|
|
|
Color(const float &r, const float &g, const float &b, const float &a);
|
2013-09-06 21:15:56 -07:00
|
|
|
|
2013-09-12 15:51:08 -07:00
|
|
|
Color &operator*=(const float &rhs);
|
|
|
|
Color &operator/=(const float &rhs);
|
|
|
|
Color &operator+=(const float &rhs);
|
|
|
|
Color &operator-=(const float &rhs);
|
|
|
|
Color operator*(const float &rhs) const;
|
|
|
|
Color operator/(const float &rhs) const;
|
|
|
|
Color operator+(const float &rhs) const;
|
|
|
|
Color operator-(const float &rhs) const;
|
|
|
|
|
|
|
|
Color &operator=(const Color &rhs);
|
2013-09-10 16:25:12 -07:00
|
|
|
|
2013-09-13 18:23:25 -07:00
|
|
|
// These operators blend the two colors.
|
|
|
|
Color &operator*=(const Color &rhs);
|
|
|
|
Color &operator/=(const Color &rhs);
|
|
|
|
Color &operator+=(const Color &rhs);
|
|
|
|
Color &operator-=(const Color &rhs);
|
|
|
|
Color operator*(const Color &rhs) const;
|
|
|
|
Color operator/(const Color &rhs) const;
|
|
|
|
Color operator+(const Color &rhs) const;
|
|
|
|
Color operator-(const Color &rhs) const;
|
|
|
|
|
2013-09-09 22:47:19 -07:00
|
|
|
static const Color Black;
|
|
|
|
static const Color White;
|
|
|
|
static const Color Red;
|
|
|
|
static const Color Green;
|
|
|
|
static const Color Blue;
|
2013-09-07 22:12:35 -07:00
|
|
|
|
2013-09-09 22:47:19 -07:00
|
|
|
float red, green, blue, alpha;
|
|
|
|
};
|
2013-09-06 21:15:56 -07:00
|
|
|
|
2013-09-13 18:23:25 -07:00
|
|
|
const Color operator*(const float &lhs, const Color &rhs);
|
2013-09-22 10:15:41 -07:00
|
|
|
std::ostream &operator<<(std::ostream &os, const Color &c);
|
2013-09-13 18:23:25 -07:00
|
|
|
|
2013-09-05 22:54:45 -07:00
|
|
|
#endif
|