# HG changeset patch # User John Tsiombikas # Date 1456266410 -7200 # Node ID c4d48a21bc4a41521d5710bf52e8b945ca6309cf # Parent bab25c0ce3379cae1286ea05c4574070fcbcda32 in the middle of the vmath->gph-math port diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/brdf.cc --- a/liberebus/src/brdf.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/brdf.cc Wed Feb 24 00:26:50 2016 +0200 @@ -5,32 +5,32 @@ #include "erebus_impl.h" // --- class SurfaceGeometry --- -SurfaceGeometry::SurfaceGeometry(const Vector3 &norm, VecLength st) - : SurfaceGeometry(norm, Vector2(0, 0), st) +SurfaceGeometry::SurfaceGeometry(const Vec3 &norm, VecLength st) + : SurfaceGeometry(norm, Vec2(0, 0), st) { } -SurfaceGeometry::SurfaceGeometry(const Vector3 &norm, const Vector2 &uvarg, VecLength st) +SurfaceGeometry::SurfaceGeometry(const Vec3 &norm, const Vec2 &uvarg, VecLength st) : normal(norm), uv(uvarg) { if(st == unknown) { normal.normalize(); } - tangent = Vector3(1.0f, 0.0f, 0.0f); + tangent = Vec3(1.0f, 0.0f, 0.0f); if(1.0 - fabs(dot_product(normal, tangent)) < 1e-4f) { - tangent = Vector3(0.0f, 0.0f, 1.0f); + tangent = Vec3(0.0f, 0.0f, 1.0f); } - Vector3 bitan = cross_product(normal, tangent); + Vec3 bitan = cross_product(normal, tangent); tangent = cross_product(bitan, normal); } -SurfaceGeometry::SurfaceGeometry(const Vector3 &norm, const Vector3 &tang, VecLength st) - : SurfaceGeometry(norm, tang, Vector2(0, 0), st) +SurfaceGeometry::SurfaceGeometry(const Vec3 &norm, const Vec3 &tang, VecLength st) + : SurfaceGeometry(norm, tang, Vec2(0, 0), st) { } -SurfaceGeometry::SurfaceGeometry(const Vector3 &norm, const Vector3 &tang, const Vector2 &uvarg, VecLength st) +SurfaceGeometry::SurfaceGeometry(const Vec3 &norm, const Vec3 &tang, const Vec2 &uvarg, VecLength st) : normal(norm), tangent(tang), uv(uvarg) { if(st == unknown) { @@ -39,26 +39,26 @@ } } -Vector3 SurfaceGeometry::spherical_to_world(float theta, float phi) const +Vec3 SurfaceGeometry::spherical_to_world(float theta, float phi) const { float x = cos(theta) * sin(phi); float y = sin(theta) * sin(phi); float z = cos(phi); - return sample_to_world(Vector3(x, y, z)); + return sample_to_world(Vec3(x, y, z)); } -Vector3 SurfaceGeometry::sample_to_world(const Vector3 &v) const +Vec3 SurfaceGeometry::sample_to_world(const Vec3 &v) const { - Matrix3x3 xform; + Mat3x3 xform; xform.set_column_vector(tangent, 0); xform.set_column_vector(cross_product(normal, tangent), 1); xform.set_column_vector(normal, 2); return v.transformed(xform); } -Vector3 SurfaceGeometry::world_to_sample(const Vector3 &v) const +Vec3 SurfaceGeometry::world_to_sample(const Vec3 &v) const { - Matrix3x3 xform; + Mat3x3 xform; xform.set_row_vector(tangent, 0); xform.set_row_vector(cross_product(normal, tangent), 1); xform.set_row_vector(normal, 2); @@ -76,7 +76,7 @@ this->mtl = mtl; } -float Reflectance::sample(const SurfaceGeometry &geom, const Vector3 &outdir, Vector3 *indir) const +float Reflectance::sample(const SurfaceGeometry &geom, const Vec3 &outdir, Vec3 *indir) const { *indir = sample_dir(geom, outdir); return eval(geom, outdir, *indir); @@ -94,7 +94,7 @@ valid_checked = false; } -int CompositeRefl::pick_brdf(const SurfaceGeometry &geom, const Vector3 &outdir) const +int CompositeRefl::pick_brdf(const SurfaceGeometry &geom, const Vec3 &outdir) const { if(sub_brdf.empty()) { return -1; @@ -158,7 +158,7 @@ "warning: don't call CompositeRefl's sample_dir and eval separately\n" " it'll pick different brdfs each time! use sample instead\n"; -Vector3 CompositeRefl::sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const +Vec3 CompositeRefl::sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const { if(!warned_composite_usage) { fputs(composite_usage_warnstr, stderr); @@ -168,13 +168,13 @@ return sub_brdf[bidx].brdf->sample_dir(geom, outdir); } -float CompositeRefl::sample(const SurfaceGeometry &geom, const Vector3 &outdir, Vector3 *indir) const +float CompositeRefl::sample(const SurfaceGeometry &geom, const Vec3 &outdir, Vec3 *indir) const { int bidx = pick_brdf(geom, outdir); return sub_brdf[bidx].brdf->sample(geom, outdir, indir); } -float CompositeRefl::eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const +float CompositeRefl::eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const { if(!warned_composite_usage) { fputs(composite_usage_warnstr, stderr); @@ -185,38 +185,38 @@ } // --- class LambertRefl --- -Vector3 LambertRefl::sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const +Vec3 LambertRefl::sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const { // TODO: write a better uniform disk sampling that doesn't rely in rejection - Vector3 dir; + Vec3 dir; do { - dir = Vector3(randf(-1, 1), randf(-1, 1), 0); + dir = Vec3(randf(-1, 1), randf(-1, 1), 0); } while(dir.length_sq() > 1.0); dir.z = sqrt(1.0 - (dir.x * dir.x + dir.y * dir.y)); return geom.sample_to_world(dir); } -float LambertRefl::eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const +float LambertRefl::eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const { return dot_product(geom.normal, outdir); } // --- class MirrorRefl --- -Vector3 MirrorRefl::sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const +Vec3 MirrorRefl::sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const { return outdir.reflection(geom.normal); } -float MirrorRefl::eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const +float MirrorRefl::eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const { return 1.0f; } // --- class PhongRefl --- -Vector3 PhongRefl::sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const +Vec3 PhongRefl::sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const { - Vector3 refl = outdir.reflection(geom.normal).normalized(); + Vec3 refl = outdir.reflection(geom.normal).normalized(); SurfaceGeometry refl_geom(refl, SurfaceGeometry::unit); float shininess = mtl ? mtl->get_attrib_value("shininess", geom.uv.x, geom.uv.y) : 42.0; @@ -227,11 +227,11 @@ return refl_geom.spherical_to_world(theta, phi); } -float PhongRefl::eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const +float PhongRefl::eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const { float shininess = mtl ? mtl->get_attrib_value("shininess", geom.uv.x, geom.uv.y) : 42.0; - Vector3 refl = outdir.reflection(geom.normal); + Vec3 refl = outdir.reflection(geom.normal); float dot = std::max(dot_product(indir, refl), 0.0f); return pow(dot, shininess); } diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/brdf.h --- a/liberebus/src/brdf.h Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/brdf.h Wed Feb 24 00:26:50 2016 +0200 @@ -8,26 +8,26 @@ class SurfaceGeometry { public: - Vector3 normal, tangent; - Vector2 uv; + Vec3 normal, tangent; + Vec2 uv; enum VecLength { unit, unknown }; - explicit SurfaceGeometry(const Vector3 &norm, VecLength st = unknown); - SurfaceGeometry(const Vector3 &norm, const Vector2 &uv, VecLength st = unknown); - SurfaceGeometry(const Vector3 &norm, const Vector3 &tang, VecLength st = unknown); - SurfaceGeometry(const Vector3 &norm, const Vector3 &tang, const Vector2 &uv, VecLength st = unknown); + explicit SurfaceGeometry(const Vec3 &norm, VecLength st = unknown); + SurfaceGeometry(const Vec3 &norm, const Vec2 &uv, VecLength st = unknown); + SurfaceGeometry(const Vec3 &norm, const Vec3 &tang, VecLength st = unknown); + SurfaceGeometry(const Vec3 &norm, const Vec3 &tang, const Vec2 &uv, VecLength st = unknown); /** create a cartesian direction vector in sample space (zenith = +Z) and * transform it to world space. * \param theta the horizontal angle (azimuth, in radians) around the Z axis [0, 2pi] * \param phi the vertical angle (elevation, in radians) away from the Z axis [0, pi] */ - Vector3 spherical_to_world(float theta, float phi) const; + Vec3 spherical_to_world(float theta, float phi) const; /// transforms a direction vector from sample space (centered around Z) to world space - Vector3 sample_to_world(const Vector3 &v) const; + Vec3 sample_to_world(const Vec3 &v) const; /// transforms a direction vector from world space to sample space (centered around Z) - Vector3 world_to_sample(const Vector3 &v) const; + Vec3 world_to_sample(const Vec3 &v) const; }; /// abstract bidirection reflectance distribution function base class @@ -44,14 +44,14 @@ const Material *get_material() const; /// given an outgoing light direction generate an incidence direction to sample the BRDF - virtual Vector3 sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const = 0; + virtual Vec3 sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const = 0; /// given an outgoing direction, generate an incidence direction, and evaluate its probability - virtual float sample(const SurfaceGeometry &geom, const Vector3 &outdir, Vector3 *indir) const; + virtual float sample(const SurfaceGeometry &geom, const Vec3 &outdir, Vec3 *indir) const; /// given an outgoing direction and an incidence direction, evaluate the probability of this path - virtual float eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const = 0; + virtual float eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const = 0; }; -typedef float (*CompReflWeightFunc)(const SurfaceGeometry &geom, const Vector3 &outdir); +typedef float (*CompReflWeightFunc)(const SurfaceGeometry &geom, const Vec3 &outdir); /// composite BRDF, with multiple weighted sub-reflectances. class CompositeRefl : public Reflectance { @@ -64,7 +64,7 @@ std::vector sub_brdf; mutable bool valid_checked; - int pick_brdf(const SurfaceGeometry &geom, const Vector3 &outdir) const; + int pick_brdf(const SurfaceGeometry &geom, const Vec3 &outdir) const; public: CompositeRefl(); @@ -75,30 +75,30 @@ bool check_valid() const; - Vector3 sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const override; - float sample(const SurfaceGeometry &geom, const Vector3 &outdir, Vector3 *indir) const override; - float eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const override; + Vec3 sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const override; + float sample(const SurfaceGeometry &geom, const Vec3 &outdir, Vec3 *indir) const override; + float eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const override; }; /// lambertian perfect diffuse reflectance class LambertRefl : public Reflectance { public: - Vector3 sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const override; - float eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const override; + Vec3 sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const override; + float eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const override; }; /// perfect specular reflectance class MirrorRefl : public Reflectance { public: - Vector3 sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const override; - float eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const override; + Vec3 sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const override; + float eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const override; }; /// glossy phong reflectance with lafortune sampling class PhongRefl : public Reflectance { public: - Vector3 sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const override; - float eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const override; + Vec3 sample_dir(const SurfaceGeometry &geom, const Vec3 &outdir) const override; + float eval(const SurfaceGeometry &geom, const Vec3 &outdir, const Vec3 &indir) const override; }; #endif // BRDF_H_ diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/bvol.cc --- a/liberebus/src/bvol.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/bvol.cc Wed Feb 24 00:26:50 2016 +0200 @@ -2,8 +2,8 @@ bool AABox::intersect(const Ray &ray) const { - Vector3 param[2] = {vmin, vmax}; - Vector3 inv_dir(1.0 / ray.dir.x, 1.0 / ray.dir.y, 1.0 / ray.dir.z); + Vec3 param[2] = {vmin, vmax}; + Vec3 inv_dir(1.0 / ray.dir.x, 1.0 / ray.dir.y, 1.0 / ray.dir.z); int sign[3] = {inv_dir.x < 0, inv_dir.y < 0, inv_dir.z < 0}; float tmin = (param[sign[0]].x - ray.origin.x) * inv_dir.x; diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/bvol.h --- a/liberebus/src/bvol.h Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/bvol.h Wed Feb 24 00:26:50 2016 +0200 @@ -5,10 +5,10 @@ class AABox { public: - Vector3 vmin, vmax; + Vec3 vmin, vmax; AABox() : vmin(-0.5, -0.5, -0.5), vmax(0.5, 0.5, 0.5) {} - AABox(const Vector3 &v0, const Vector3 &v1) : vmin(v0), vmax(v1) {} + AABox(const Vec3 &v0, const Vec3 &v1) : vmin(v0), vmax(v1) {} bool intersect(const Ray &ray) const; }; diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/camera.cc --- a/liberebus/src/camera.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/camera.cc Wed Feb 24 00:26:50 2016 +0200 @@ -12,7 +12,7 @@ cached_matrix_valid = false; } -Camera::Camera(const Vector3 &p) +Camera::Camera(const Vec3 &p) : pos(p) { vfov = DEFAULT_FOV; @@ -33,18 +33,18 @@ return vfov; } -void Camera::set_position(const Vector3 &pos) +void Camera::set_position(const Vec3 &pos) { this->pos = pos; cached_matrix_valid = false; // invalidate the cached matrix } -const Vector3 &Camera::get_position() const +const Vec3 &Camera::get_position() const { return pos; } -const Matrix4x4 &Camera::get_matrix() const +const Mat4x4 &Camera::get_matrix() const { if(!cached_matrix_valid) { calc_matrix(&cached_matrix); @@ -53,7 +53,7 @@ return cached_matrix; } -Vector2 Camera::calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const +Vec2 Camera::calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const { float ppos[2]; float aspect = (float)xsz / (float)ysz; @@ -65,12 +65,12 @@ ppos[1] = 1.0 - (float)y * pheight; calc_sample_pos_rec(sample, pwidth, pheight, ppos); - return Vector2(ppos[0], ppos[1]); + return Vec2(ppos[0], ppos[1]); } Ray Camera::get_primary_ray(int x, int y, int xsz, int ysz, int sample) const { - Vector2 ppos = calc_sample_pos(x, y, xsz, ysz, sample); + Vec2 ppos = calc_sample_pos(x, y, xsz, ysz, sample); Ray ray; ray.origin = pos; @@ -80,7 +80,7 @@ ray.dir.normalize(); // transform the ray direction with the camera matrix - Matrix4x4 mat = get_matrix(); + Mat4x4 mat = get_matrix(); mat.m[0][3] = mat.m[1][3] = mat.m[2][3] = mat.m[3][0] = mat.m[3][1] = mat.m[3][2] = 0.0; mat.m[3][3] = 1.0; @@ -90,35 +90,35 @@ TargetCamera::TargetCamera() {} -TargetCamera::TargetCamera(const Vector3 &pos, const Vector3 &targ) +TargetCamera::TargetCamera(const Vec3 &pos, const Vec3 &targ) : Camera(pos), target(targ) { } -void TargetCamera::set_target(const Vector3 &targ) +void TargetCamera::set_target(const Vec3 &targ) { target = targ; cached_matrix_valid = false; // invalidate the cached matrix } -const Vector3 &TargetCamera::get_target() const +const Vec3 &TargetCamera::get_target() const { return target; } -void TargetCamera::calc_matrix(Matrix4x4 *mat) const +void TargetCamera::calc_matrix(Mat4x4 *mat) const { - Vector3 up{0, 1, 0}; - Vector3 dir = (target - pos).normalized(); + Vec3 up{0, 1, 0}; + Vec3 dir = (target - pos).normalized(); if(1.0 - fabs(dot_product(dir, up)) < 1e-4) { - up = Vector3(0, 0, 1); + up = Vec3(0, 0, 1); } - Vector3 right = cross_product(up, dir).normalized(); + Vec3 right = cross_product(up, dir).normalized(); up = cross_product(dir, right); - *mat = Matrix4x4( + *mat = Mat4x4( right.x, up.x, dir.x, pos.x, right.y, up.y, dir.y, pos.y, right.z, up.z, dir.z, pos.z, @@ -127,11 +127,11 @@ void FlyCamera::input_move(float x, float y, float z) { - static const Vector3 vfwd(0, 0, 1), vright(1, 0, 0); + static const Vec3 vfwd(0, 0, 1), vright(1, 0, 0); - Vector3 k = vfwd.transformed(rot); - Vector3 i = vright.transformed(rot); - Vector3 j = cross_product(k, i); + Vec3 k = vfwd.transformed(rot); + Vec3 i = vright.transformed(rot); + Vec3 j = cross_product(k, i); pos += i * x + j * y + k * z; cached_matrix_valid = false; @@ -139,7 +139,7 @@ void FlyCamera::input_rotate(float x, float y, float z) { - Vector3 axis(x, y, z); + Vec3 axis(x, y, z); float axis_len = axis.length(); if(fabs(axis_len) < 1e-5) { return; @@ -150,14 +150,14 @@ cached_matrix_valid = false; } -void FlyCamera::calc_matrix(Matrix4x4 *mat) const +void FlyCamera::calc_matrix(Mat4x4 *mat) const { - Matrix4x4 tmat; + Mat4x4 tmat; tmat.set_translation(pos); - Matrix3x3 rmat = rot.get_rotation_matrix(); + Mat3x3 rmat = rot.get_rotation_matrix(); - *mat = tmat * Matrix4x4(rmat); + *mat = tmat * Mat4x4(rmat); } /* generates a sample position for sample number sidx, in the unit square diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/camera.h --- a/liberebus/src/camera.h Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/camera.h Wed Feb 24 00:26:50 2016 +0200 @@ -5,50 +5,50 @@ class Camera { protected: - Vector3 pos; + Vec3 pos; float vfov; // vertical field of view in radians - mutable Matrix4x4 cached_matrix; + mutable Mat4x4 cached_matrix; mutable bool cached_matrix_valid; - virtual void calc_matrix(Matrix4x4 *mat) const = 0; + virtual void calc_matrix(Mat4x4 *mat) const = 0; - Vector2 calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const; + Vec2 calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const; public: Camera(); - Camera(const Vector3 &pos); + Camera(const Vec3 &pos); virtual ~Camera(); virtual void set_fov(float vfov); virtual float get_fov() const; - virtual void set_position(const Vector3 &pos); - virtual const Vector3 &get_position() const; - virtual const Matrix4x4 &get_matrix() const; + virtual void set_position(const Vec3 &pos); + virtual const Vec3 &get_position() const; + virtual const Mat4x4 &get_matrix() const; virtual Ray get_primary_ray(int x, int y, int xsz, int ysz, int sample = 0) const; }; class TargetCamera : public Camera { protected: - Vector3 target; + Vec3 target; - void calc_matrix(Matrix4x4 *mat) const; + void calc_matrix(Mat4x4 *mat) const; public: TargetCamera(); - TargetCamera(const Vector3 &pos, const Vector3 &targ); + TargetCamera(const Vec3 &pos, const Vec3 &targ); - virtual void set_target(const Vector3 &targ); - virtual const Vector3 &get_target() const; + virtual void set_target(const Vec3 &targ); + virtual const Vec3 &get_target() const; }; class FlyCamera : public Camera { protected: - Quaternion rot; + Quat rot; - void calc_matrix(Matrix4x4 *mat) const; + void calc_matrix(Mat4x4 *mat) const; public: void input_move(float x, float y, float z); diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/color.h --- a/liberebus/src/color.h Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/color.h Wed Feb 24 00:26:50 2016 +0200 @@ -3,7 +3,7 @@ #include -typedef Vector4 Color; +typedef Vec4 Color; inline float color_luminance(const Color &c) { return c[0] * 0.2126 + c[1] * 0.7152 + c[2] * 0.0722; } diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/erebus.cc --- a/liberebus/src/erebus.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/erebus.cc Wed Feb 24 00:26:50 2016 +0200 @@ -119,13 +119,13 @@ case Option::Type::INT: { int ival = ctx->options[opt].ival; - ctx->options[opt].vval = Vector4(ival, ival, ival, ival); + ctx->options[opt].vval = Vec4(ival, ival, ival, ival); } break; case Option::Type::FLOAT: { float fval = ctx->options[opt].fval; - ctx->options[opt].vval = Vector4(fval, fval, fval, fval); + ctx->options[opt].vval = Vec4(fval, fval, fval, fval); } default: break; @@ -343,7 +343,7 @@ case '0': if(ctx->dbg_nodesel != -1) { SceneNode *node = ctx->scn->get_node(ctx->dbg_nodesel); - Vector3 s = node->get_scaling(); + Vec3 s = node->get_scaling(); switch(key) { case '=': node->set_scaling(s * 1.1); @@ -352,7 +352,7 @@ node->set_scaling(s * 0.9); break; case '0': - node->set_scaling(Vector3(1, 1, 1)); + node->set_scaling(Vec3(1, 1, 1)); break; } } @@ -388,7 +388,7 @@ if(dx || dy) { TargetCamera *cam = (TargetCamera*)ctx->scn->get_active_camera(); if(cam && ctx->bnstate[0]) { - Vector3 cpos = cam->get_position(); + Vec3 cpos = cam->get_position(); float mag = cpos.length(); float theta = atan2(cpos.z / mag, cpos.x / mag) - DEG_TO_RAD(dx * 0.5); diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/erebus_impl.h --- a/liberebus/src/erebus_impl.h Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/erebus_impl.h Wed Feb 24 00:26:50 2016 +0200 @@ -12,7 +12,7 @@ enum Type { INT, FLOAT, VEC } type; int ival; float fval; - Vector4 vval; + Vec4 vval; }; struct Block { diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/geomobj.cc --- a/liberebus/src/geomobj.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/geomobj.cc Wed Feb 24 00:26:50 2016 +0200 @@ -21,25 +21,25 @@ return false; } -Vector3 GeomObject::gen_surface_point() const +Vec3 GeomObject::gen_surface_point() const { - return Vector3(0, 0, 0); + return Vec3(0, 0, 0); } -Vector3 GeomObject::calc_normal(const RayHit &hit) const +Vec3 GeomObject::calc_normal(const RayHit &hit) const { // when you look at singularities, the singularities always look back at you :) return -(hit.local_ray.dir).normalized(); } -Vector3 GeomObject::calc_tangent(const RayHit &hit) const +Vec3 GeomObject::calc_tangent(const RayHit &hit) const { - return Vector3(1, 0, 0); // whatever... + return Vec3(1, 0, 0); // whatever... } -Vector2 GeomObject::calc_texcoords(const RayHit &hit) const +Vec2 GeomObject::calc_texcoords(const RayHit &hit) const { - return Vector2(); + return Vec2(); } // --- class Sphere --- @@ -71,42 +71,42 @@ return true; } -Vector3 Sphere::gen_surface_point() const +Vec3 Sphere::gen_surface_point() const { return sphrand(1.0); } -Vector3 Sphere::calc_normal(const RayHit &hit) const +Vec3 Sphere::calc_normal(const RayHit &hit) const { - Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; + Vec3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; return pt.normalized(); } -static inline Vector3 sphvec(float u, float v) +static inline Vec3 sphvec(float u, float v) { float theta = u * M_PI * 2.0; float phi = v * M_PI; - return Vector3(sin(theta) * sin(phi), cos(phi), cos(theta) * sin(phi)); + return Vec3(sin(theta) * sin(phi), cos(phi), cos(theta) * sin(phi)); } -Vector3 Sphere::calc_tangent(const RayHit &hit) const +Vec3 Sphere::calc_tangent(const RayHit &hit) const { - Vector2 uv = calc_texcoords(hit); - Vector3 pnext = sphvec(uv.x + 0.05, 0.5); - Vector3 pprev = sphvec(uv.y - 0.05, 0.5); + Vec2 uv = calc_texcoords(hit); + Vec3 pnext = sphvec(uv.x + 0.05, 0.5); + Vec3 pprev = sphvec(uv.y - 0.05, 0.5); return (pnext - pprev).normalized(); } -Vector2 Sphere::calc_texcoords(const RayHit &hit) const +Vec2 Sphere::calc_texcoords(const RayHit &hit) const { - Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; + Vec3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; pt.normalize(); float theta = atan2(pt.z, pt.x); float phi = acos(pt.y); - return Vector2(theta / M_PI + 0.5, phi / M_PI); + return Vec2(theta / M_PI + 0.5, phi / M_PI); } @@ -114,8 +114,8 @@ bool Box::intersect(const Ray &ray, RayHit *hit) const { - Vector3 param[2] = {Vector3{-0.5, -0.5, -0.5}, Vector3{0.5, 0.5, 0.5}}; - Vector3 inv_dir{1.0f / ray.dir.x, 1.0f / ray.dir.y, 1.0f / ray.dir.z}; + Vec3 param[2] = {Vec3{-0.5, -0.5, -0.5}, Vec3{0.5, 0.5, 0.5}}; + Vec3 inv_dir{1.0f / ray.dir.x, 1.0f / ray.dir.y, 1.0f / ray.dir.z}; int sign[3] = {inv_dir.x < 0, inv_dir.y < 0, inv_dir.z < 0}; float tmin = (param[sign[0]].x - ray.origin.x) * inv_dir.x; @@ -159,9 +159,9 @@ #define SIGN(x) (x >= 0.0 ? 1.0 : -1.0) -Vector3 Box::gen_surface_point() const +Vec3 Box::gen_surface_point() const { - Vector3 rnd{randf(-1, 1), randf(-1, 1), randf(-1, 1)}; + Vec3 rnd{randf(-1, 1), randf(-1, 1), randf(-1, 1)}; float absrnd[3]; absrnd[0] = fabs(rnd.x); @@ -179,26 +179,26 @@ } #define BOX_EXT 0.499999 -Vector3 Box::calc_normal(const RayHit &hit) const +Vec3 Box::calc_normal(const RayHit &hit) const { - Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; - if(pt.x > BOX_EXT) return Vector3(1, 0, 0); - if(pt.x < -BOX_EXT) return Vector3(-1, 0, 0); - if(pt.y > BOX_EXT) return Vector3(0, 1, 0); - if(pt.y < -BOX_EXT) return Vector3(0, -1, 0); - if(pt.z > BOX_EXT) return Vector3(0, 0, 1); - if(pt.z < -BOX_EXT) return Vector3(0, 0, -1); - return Vector3(0, 0, 0); // shouldn't happen unless numerical precision is fucked + Vec3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; + if(pt.x > BOX_EXT) return Vec3(1, 0, 0); + if(pt.x < -BOX_EXT) return Vec3(-1, 0, 0); + if(pt.y > BOX_EXT) return Vec3(0, 1, 0); + if(pt.y < -BOX_EXT) return Vec3(0, -1, 0); + if(pt.z > BOX_EXT) return Vec3(0, 0, 1); + if(pt.z < -BOX_EXT) return Vec3(0, 0, -1); + return Vec3(0, 0, 0); // shouldn't happen unless numerical precision is fucked } -Vector3 Box::calc_tangent(const RayHit &hit) const +Vec3 Box::calc_tangent(const RayHit &hit) const { - return Vector3(1, 0, 0); // TODO + return Vec3(1, 0, 0); // TODO } -Vector2 Box::calc_texcoords(const RayHit &hit) const +Vec2 Box::calc_texcoords(const RayHit &hit) const { - return Vector2(0, 0); // TODO + return Vec2(0, 0); // TODO } // --- class Triangle --- @@ -208,7 +208,7 @@ return false; } -Vector3 Triangle::gen_surface_point() const +Vec3 Triangle::gen_surface_point() const { // TODO: this is probably not uniform, fix at some point float bu = randf(); @@ -243,8 +243,8 @@ return false; } -Vector3 Mesh::gen_surface_point() const +Vec3 Mesh::gen_surface_point() const { // this needs some precalculation... - return Vector3(0, 0, 0); // TODO + return Vec3(0, 0, 0); // TODO } diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/geomobj.h --- a/liberebus/src/geomobj.h Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/geomobj.h Wed Feb 24 00:26:50 2016 +0200 @@ -17,45 +17,45 @@ bool intersect(const Ray &ray, RayHit *hit = 0) const override; - virtual Vector3 gen_surface_point() const; + virtual Vec3 gen_surface_point() const; - virtual Vector3 calc_normal(const RayHit &hit) const; - virtual Vector3 calc_tangent(const RayHit &hit) const; - virtual Vector2 calc_texcoords(const RayHit &hit) const; + virtual Vec3 calc_normal(const RayHit &hit) const; + virtual Vec3 calc_tangent(const RayHit &hit) const; + virtual Vec2 calc_texcoords(const RayHit &hit) const; }; class Sphere : public GeomObject { public: bool intersect(const Ray &ray, RayHit *hit = 0) const override; - Vector3 gen_surface_point() const override; + Vec3 gen_surface_point() const override; - Vector3 calc_normal(const RayHit &hit) const override; - Vector3 calc_tangent(const RayHit &hit) const override; - Vector2 calc_texcoords(const RayHit &hit) const override; + Vec3 calc_normal(const RayHit &hit) const override; + Vec3 calc_tangent(const RayHit &hit) const override; + Vec2 calc_texcoords(const RayHit &hit) const override; }; class Box : public GeomObject { public: bool intersect(const Ray &ray, RayHit *hit = 0) const override; - Vector3 gen_surface_point() const override; + Vec3 gen_surface_point() const override; - Vector3 calc_normal(const RayHit &hit) const override; - Vector3 calc_tangent(const RayHit &hit) const override; - Vector2 calc_texcoords(const RayHit &hit) const override; + Vec3 calc_normal(const RayHit &hit) const override; + Vec3 calc_tangent(const RayHit &hit) const override; + Vec2 calc_texcoords(const RayHit &hit) const override; }; class Triangle : public GeomObject { public: - Vector3 v[3]; - Vector3 normal; - Vector3 vnorm[3]; - Vector2 vtex[3]; + Vec3 v[3]; + Vec3 normal; + Vec3 vnorm[3]; + Vec2 vtex[3]; bool intersect(const Ray &ray, RayHit *hit = 0) const override; - Vector3 gen_surface_point() const override; + Vec3 gen_surface_point() const override; }; class Mesh : public GeomObject { @@ -71,7 +71,7 @@ bool intersect(const Ray &ray, RayHit *hit = 0) const override; - Vector3 gen_surface_point() const override; + Vec3 gen_surface_point() const override; }; #endif // GEOMOBJ_H_ diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/object.cc --- a/liberebus/src/object.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/object.cc Wed Feb 24 00:26:50 2016 +0200 @@ -10,25 +10,25 @@ obj = subobj = 0; } -Vector3 RayHit::calc_normal() const +Vec3 RayHit::calc_normal() const { assert(obj->get_type() == ObjType::geom); - Vector3 norm = ((const GeomObject*)obj)->calc_normal(*this); + Vec3 norm = ((const GeomObject*)obj)->calc_normal(*this); - const Matrix4x4 &xform = node->get_inv_matrix(); - return norm.transformed(Matrix3x3(xform).transposed()).normalized(); + const Mat4x4 &xform = node->get_inv_matrix(); + return norm.transformed(Mat3x3(xform).transposed()).normalized(); } -Vector3 RayHit::calc_tangent() const +Vec3 RayHit::calc_tangent() const { assert(obj->get_type() == ObjType::geom); - Vector3 tang = ((const GeomObject*)obj)->calc_tangent(*this); + Vec3 tang = ((const GeomObject*)obj)->calc_tangent(*this); - const Matrix4x4 &xform = node->get_matrix(); - return tang.transformed(Matrix3x3(xform).transposed()); + const Mat4x4 &xform = node->get_matrix(); + return tang.transformed(Mat3x3(xform).transposed()); } -Vector2 RayHit::calc_texcoords() const +Vec2 RayHit::calc_texcoords() const { assert(obj->get_type() == ObjType::geom); return ((const GeomObject*)obj)->calc_texcoords(*this); diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/object.h --- a/liberebus/src/object.h Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/object.h Wed Feb 24 00:26:50 2016 +0200 @@ -17,9 +17,9 @@ RayHit(); - Vector3 calc_normal() const; - Vector3 calc_tangent() const; - Vector2 calc_texcoords() const; + Vec3 calc_normal() const; + Vec3 calc_tangent() const; + Vec2 calc_texcoords() const; }; enum class ObjType { null, geom, camera }; diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/rt.cc --- a/liberebus/src/rt.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/rt.cc Wed Feb 24 00:26:50 2016 +0200 @@ -32,16 +32,16 @@ const Ray &ray = hit.world_ray; //bool entering = true; - Vector3 pos = ray.origin + ray.dir * hit.dist; + Vec3 pos = ray.origin + ray.dir * hit.dist; - Vector3 norm = hit.calc_normal(); + Vec3 norm = hit.calc_normal(); if(dot_product(ray.dir, norm) > 0.0) { //entering = false; norm = -norm; } - //return norm * 0.5 + Vector3(0.5, 0.5, 0.5); - Vector2 texcoords = hit.calc_texcoords(); + //return norm * 0.5 + Vec3(0.5, 0.5, 0.5); + Vec2 texcoords = hit.calc_texcoords(); Color color = mtl->get_attrib_color("diffuse", texcoords.x, texcoords.y); Color specular = mtl->get_attrib_color("specular", texcoords.x, texcoords.y); @@ -52,7 +52,7 @@ /* // calculate direct illumination - Vector3 vdir = -ray.dir.normalized(); + Vec3 vdir = -ray.dir.normalized(); std::list lights = scn->gen_light_list(); auto it = lights.cbegin(); while(it != lights.cend()) { @@ -65,11 +65,11 @@ continue; } - const Matrix4x4 &xform = light_node->get_matrix(); - const Matrix4x4 &inv_xform = light_node->get_inv_matrix(); - Vector3 spt = light->gen_surface_point().transformed(xform); + const Mat4x4 &xform = light_node->get_matrix(); + const Mat4x4 &inv_xform = light_node->get_inv_matrix(); + Vec3 spt = light->gen_surface_point().transformed(xform); - Vector3 ldir = spt - pos; + Vec3 ldir = spt - pos; if(dot_product(ldir, norm) < 0.0) { continue; } @@ -91,14 +91,14 @@ shadow_hit.node = inst.node; } - Vector2 tc = shadow_hit.calc_texcoords(); + Vec2 tc = shadow_hit.calc_texcoords(); Color lcol = light->mtl.get_attrib_color("emissive", tc.x, tc.y); ldir.normalize(); norm.normalize(); float ndotl = dot_product(ldir, norm); - Vector3 refl = ldir.reflection(norm); + Vec3 refl = ldir.reflection(norm); float vdotr = dot_product(vdir, refl); Color direct = ray.energy * lcol * (color * ndotl);// + specular * pow(vdotr, shininess)); @@ -107,7 +107,7 @@ } */ - Vector3 sample_dir; + Vec3 sample_dir; float prob = brdf->sample(SurfaceGeometry(norm), -ray.dir, &sample_dir); if(randf() <= prob) { Ray sample_ray; diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/scene.cc --- a/liberebus/src/scene.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/scene.cc Wed Feb 24 00:26:50 2016 +0200 @@ -313,7 +313,7 @@ fprintf(stderr, "-position must be followed by 3 numbers\n"); goto err; } - node->set_position(Vector3(vec[0], vec[1], vec[2])); + node->set_position(Vec3(vec[0], vec[1], vec[2])); i += 3; } else if(strcmp(argv[i], "-rotation") == 0) { @@ -322,16 +322,16 @@ fprintf(stderr, "-rotation must be followed by axis vector and angle\n"); goto err; } - node->set_rotation(Quaternion(Vector3(vec[0], vec[1], vec[2]), vec[3])); + node->set_rotation(Quat(Vec3(vec[0], vec[1], vec[2]), vec[3])); i += 4; } else if(strcmp(argv[i], "-scaling") == 0) { int nelem = parse_vec(argv + i + 1, vec); - Vector3 s; + Vec3 s; if(nelem == 1) { s.x = s.y = s.z = vec[0]; } else if(nelem == 3) { - s = Vector3(vec[0], vec[1], vec[2]); + s = Vec3(vec[0], vec[1], vec[2]); } else { fprintf(stderr, "-scaling must be followed by 1 or 3 numbers\n"); goto err; @@ -361,9 +361,9 @@ int nelem = parse_vec(argv + i + 1, vec); Color emissive; if(nelem == 1) { - emissive = Vector3(1, 1, 1); + emissive = Vec3(1, 1, 1); } else if(nelem == 3) { - emissive = Vector3(vec[0], vec[1], vec[2]); + emissive = Vec3(vec[0], vec[1], vec[2]); } else { fprintf(stderr, "-emissive must be followed by an intensity or a color\n"); goto err; @@ -402,7 +402,7 @@ fprintf(stderr, "-position must be followed by 3 numbers\n"); goto err; } - cam->set_position(Vector3(vec[0], vec[1], vec[2])); + cam->set_position(Vec3(vec[0], vec[1], vec[2])); i += 3; } else if(strcmp(argv[i], "-target") == 0) { @@ -411,7 +411,7 @@ fprintf(stderr, "-target must be followed by 3 numbers\n"); goto err; } - cam->set_target(Vector3(vec[0], vec[1], vec[2])); + cam->set_target(Vec3(vec[0], vec[1], vec[2])); i += 3; } else if(strcmp(argv[i], "-fov") == 0) { diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/snode.cc --- a/liberebus/src/snode.cc Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/snode.cc Wed Feb 24 00:26:50 2016 +0200 @@ -72,59 +72,59 @@ return obj[idx]; } -void SceneNode::set_position(const Vector3 &pos) +void SceneNode::set_position(const Vec3 &pos) { this->pos = pos; } -void SceneNode::set_rotation(const Quaternion &rot) +void SceneNode::set_rotation(const Quat &rot) { this->rot = rot; } -void SceneNode::set_scaling(const Vector3 &scale) +void SceneNode::set_scaling(const Vec3 &scale) { this->scale = scale; } -const Vector3 &SceneNode::get_node_position() const +const Vec3 &SceneNode::get_node_position() const { return pos; } -const Quaternion &SceneNode::get_node_rotation() const +const Quat &SceneNode::get_node_rotation() const { return rot; } -const Vector3 &SceneNode::get_node_scaling() const +const Vec3 &SceneNode::get_node_scaling() const { return scale; } -Vector3 SceneNode::get_position() const +Vec3 SceneNode::get_position() const { - return Vector3{0, 0, 0}.transformed(xform); + return Vec3{0, 0, 0}.transformed(xform); } -Quaternion SceneNode::get_rotation() const +Quat SceneNode::get_rotation() const { return rot; // TODO } -Vector3 SceneNode::get_scaling() const +Vec3 SceneNode::get_scaling() const { return scale; // TODO } -const Matrix4x4 &SceneNode::get_matrix() const +const Mat4x4 &SceneNode::get_matrix() const { return xform; } -const Matrix4x4 &SceneNode::get_inv_matrix() const +const Mat4x4 &SceneNode::get_inv_matrix() const { return inv_xform; } diff -r bab25c0ce337 -r c4d48a21bc4a liberebus/src/snode.h --- a/liberebus/src/snode.h Tue Dec 29 12:19:53 2015 +0200 +++ b/liberebus/src/snode.h Wed Feb 24 00:26:50 2016 +0200 @@ -7,17 +7,17 @@ class SceneNode { private: - Vector3 pos; - Quaternion rot; - Vector3 scale; + Vec3 pos; + Quat rot; + Vec3 scale; std::vector obj; SceneNode *parent; std::vector children; - Matrix4x4 xform; - Matrix4x4 inv_xform; + Mat4x4 xform; + Mat4x4 inv_xform; public: SceneNode(); @@ -35,20 +35,20 @@ int get_num_objects() const; Object *get_object(int idx) const; - void set_position(const Vector3 &pos); - void set_rotation(const Quaternion &rot); - void set_scaling(const Vector3 &scale); + void set_position(const Vec3 &pos); + void set_rotation(const Quat &rot); + void set_scaling(const Vec3 &scale); - const Vector3 &get_node_position() const; - const Quaternion &get_node_rotation() const; - const Vector3 &get_node_scaling() const; + const Vec3 &get_node_position() const; + const Quat &get_node_rotation() const; + const Vec3 &get_node_scaling() const; - Vector3 get_position() const; - Quaternion get_rotation() const; - Vector3 get_scaling() const; + Vec3 get_position() const; + Quat get_rotation() const; + Vec3 get_scaling() const; - const Matrix4x4 &get_matrix() const; - const Matrix4x4 &get_inv_matrix() const; + const Mat4x4 &get_matrix() const; + const Mat4x4 &get_inv_matrix() const; void update_node(long msec = 0); void update(long msec = 0);