erebus
diff liberebus/src/geomobj.cc @ 46:c4d48a21bc4a
in the middle of the vmath->gph-math port
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 24 Feb 2016 00:26:50 +0200 |
parents | bab25c0ce337 |
children |
line diff
1.1 --- a/liberebus/src/geomobj.cc Tue Dec 29 12:19:53 2015 +0200 1.2 +++ b/liberebus/src/geomobj.cc Wed Feb 24 00:26:50 2016 +0200 1.3 @@ -21,25 +21,25 @@ 1.4 return false; 1.5 } 1.6 1.7 -Vector3 GeomObject::gen_surface_point() const 1.8 +Vec3 GeomObject::gen_surface_point() const 1.9 { 1.10 - return Vector3(0, 0, 0); 1.11 + return Vec3(0, 0, 0); 1.12 } 1.13 1.14 -Vector3 GeomObject::calc_normal(const RayHit &hit) const 1.15 +Vec3 GeomObject::calc_normal(const RayHit &hit) const 1.16 { 1.17 // when you look at singularities, the singularities always look back at you :) 1.18 return -(hit.local_ray.dir).normalized(); 1.19 } 1.20 1.21 -Vector3 GeomObject::calc_tangent(const RayHit &hit) const 1.22 +Vec3 GeomObject::calc_tangent(const RayHit &hit) const 1.23 { 1.24 - return Vector3(1, 0, 0); // whatever... 1.25 + return Vec3(1, 0, 0); // whatever... 1.26 } 1.27 1.28 -Vector2 GeomObject::calc_texcoords(const RayHit &hit) const 1.29 +Vec2 GeomObject::calc_texcoords(const RayHit &hit) const 1.30 { 1.31 - return Vector2(); 1.32 + return Vec2(); 1.33 } 1.34 1.35 // --- class Sphere --- 1.36 @@ -71,42 +71,42 @@ 1.37 return true; 1.38 } 1.39 1.40 -Vector3 Sphere::gen_surface_point() const 1.41 +Vec3 Sphere::gen_surface_point() const 1.42 { 1.43 return sphrand(1.0); 1.44 } 1.45 1.46 -Vector3 Sphere::calc_normal(const RayHit &hit) const 1.47 +Vec3 Sphere::calc_normal(const RayHit &hit) const 1.48 { 1.49 - Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; 1.50 + Vec3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; 1.51 return pt.normalized(); 1.52 } 1.53 1.54 -static inline Vector3 sphvec(float u, float v) 1.55 +static inline Vec3 sphvec(float u, float v) 1.56 { 1.57 float theta = u * M_PI * 2.0; 1.58 float phi = v * M_PI; 1.59 1.60 - return Vector3(sin(theta) * sin(phi), cos(phi), cos(theta) * sin(phi)); 1.61 + return Vec3(sin(theta) * sin(phi), cos(phi), cos(theta) * sin(phi)); 1.62 } 1.63 1.64 -Vector3 Sphere::calc_tangent(const RayHit &hit) const 1.65 +Vec3 Sphere::calc_tangent(const RayHit &hit) const 1.66 { 1.67 - Vector2 uv = calc_texcoords(hit); 1.68 - Vector3 pnext = sphvec(uv.x + 0.05, 0.5); 1.69 - Vector3 pprev = sphvec(uv.y - 0.05, 0.5); 1.70 + Vec2 uv = calc_texcoords(hit); 1.71 + Vec3 pnext = sphvec(uv.x + 0.05, 0.5); 1.72 + Vec3 pprev = sphvec(uv.y - 0.05, 0.5); 1.73 return (pnext - pprev).normalized(); 1.74 } 1.75 1.76 -Vector2 Sphere::calc_texcoords(const RayHit &hit) const 1.77 +Vec2 Sphere::calc_texcoords(const RayHit &hit) const 1.78 { 1.79 - Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; 1.80 + Vec3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; 1.81 pt.normalize(); 1.82 1.83 float theta = atan2(pt.z, pt.x); 1.84 float phi = acos(pt.y); 1.85 1.86 - return Vector2(theta / M_PI + 0.5, phi / M_PI); 1.87 + return Vec2(theta / M_PI + 0.5, phi / M_PI); 1.88 } 1.89 1.90 1.91 @@ -114,8 +114,8 @@ 1.92 1.93 bool Box::intersect(const Ray &ray, RayHit *hit) const 1.94 { 1.95 - Vector3 param[2] = {Vector3{-0.5, -0.5, -0.5}, Vector3{0.5, 0.5, 0.5}}; 1.96 - Vector3 inv_dir{1.0f / ray.dir.x, 1.0f / ray.dir.y, 1.0f / ray.dir.z}; 1.97 + Vec3 param[2] = {Vec3{-0.5, -0.5, -0.5}, Vec3{0.5, 0.5, 0.5}}; 1.98 + Vec3 inv_dir{1.0f / ray.dir.x, 1.0f / ray.dir.y, 1.0f / ray.dir.z}; 1.99 int sign[3] = {inv_dir.x < 0, inv_dir.y < 0, inv_dir.z < 0}; 1.100 1.101 float tmin = (param[sign[0]].x - ray.origin.x) * inv_dir.x; 1.102 @@ -159,9 +159,9 @@ 1.103 1.104 #define SIGN(x) (x >= 0.0 ? 1.0 : -1.0) 1.105 1.106 -Vector3 Box::gen_surface_point() const 1.107 +Vec3 Box::gen_surface_point() const 1.108 { 1.109 - Vector3 rnd{randf(-1, 1), randf(-1, 1), randf(-1, 1)}; 1.110 + Vec3 rnd{randf(-1, 1), randf(-1, 1), randf(-1, 1)}; 1.111 float absrnd[3]; 1.112 1.113 absrnd[0] = fabs(rnd.x); 1.114 @@ -179,26 +179,26 @@ 1.115 } 1.116 1.117 #define BOX_EXT 0.499999 1.118 -Vector3 Box::calc_normal(const RayHit &hit) const 1.119 +Vec3 Box::calc_normal(const RayHit &hit) const 1.120 { 1.121 - Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; 1.122 - if(pt.x > BOX_EXT) return Vector3(1, 0, 0); 1.123 - if(pt.x < -BOX_EXT) return Vector3(-1, 0, 0); 1.124 - if(pt.y > BOX_EXT) return Vector3(0, 1, 0); 1.125 - if(pt.y < -BOX_EXT) return Vector3(0, -1, 0); 1.126 - if(pt.z > BOX_EXT) return Vector3(0, 0, 1); 1.127 - if(pt.z < -BOX_EXT) return Vector3(0, 0, -1); 1.128 - return Vector3(0, 0, 0); // shouldn't happen unless numerical precision is fucked 1.129 + Vec3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; 1.130 + if(pt.x > BOX_EXT) return Vec3(1, 0, 0); 1.131 + if(pt.x < -BOX_EXT) return Vec3(-1, 0, 0); 1.132 + if(pt.y > BOX_EXT) return Vec3(0, 1, 0); 1.133 + if(pt.y < -BOX_EXT) return Vec3(0, -1, 0); 1.134 + if(pt.z > BOX_EXT) return Vec3(0, 0, 1); 1.135 + if(pt.z < -BOX_EXT) return Vec3(0, 0, -1); 1.136 + return Vec3(0, 0, 0); // shouldn't happen unless numerical precision is fucked 1.137 } 1.138 1.139 -Vector3 Box::calc_tangent(const RayHit &hit) const 1.140 +Vec3 Box::calc_tangent(const RayHit &hit) const 1.141 { 1.142 - return Vector3(1, 0, 0); // TODO 1.143 + return Vec3(1, 0, 0); // TODO 1.144 } 1.145 1.146 -Vector2 Box::calc_texcoords(const RayHit &hit) const 1.147 +Vec2 Box::calc_texcoords(const RayHit &hit) const 1.148 { 1.149 - return Vector2(0, 0); // TODO 1.150 + return Vec2(0, 0); // TODO 1.151 } 1.152 1.153 // --- class Triangle --- 1.154 @@ -208,7 +208,7 @@ 1.155 return false; 1.156 } 1.157 1.158 -Vector3 Triangle::gen_surface_point() const 1.159 +Vec3 Triangle::gen_surface_point() const 1.160 { 1.161 // TODO: this is probably not uniform, fix at some point 1.162 float bu = randf(); 1.163 @@ -243,8 +243,8 @@ 1.164 return false; 1.165 } 1.166 1.167 -Vector3 Mesh::gen_surface_point() const 1.168 +Vec3 Mesh::gen_surface_point() const 1.169 { 1.170 // this needs some precalculation... 1.171 - return Vector3(0, 0, 0); // TODO 1.172 + return Vec3(0, 0, 0); // TODO 1.173 }