erebus

diff liberebus/src/geomobj.cc @ 41:2e817711d0f6

console: proper input line windowing and clipping
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Jun 2014 12:28:56 +0300
parents 09028848f276
children ed18af9da8f7
line diff
     1.1 --- a/liberebus/src/geomobj.cc	Tue Jun 10 10:53:19 2014 +0300
     1.2 +++ b/liberebus/src/geomobj.cc	Tue Jun 10 12:28:56 2014 +0300
     1.3 @@ -1,6 +1,8 @@
     1.4  #include <math.h>
     1.5  #include <float.h>
     1.6 +#include <vmath/vmath.h>
     1.7  #include "geomobj.h"
     1.8 +#include "erebus_impl.h"
     1.9  
    1.10  static LambertRefl lambert;
    1.11  
    1.12 @@ -19,6 +21,11 @@
    1.13  	return false;
    1.14  }
    1.15  
    1.16 +Vector3 GeomObject::gen_surface_point() const
    1.17 +{
    1.18 +	return Vector3(0, 0, 0);
    1.19 +}
    1.20 +
    1.21  Vector3 GeomObject::calc_normal(const RayHit &hit) const
    1.22  {
    1.23  	// when you look at singularities, the singularities always look back at you :)
    1.24 @@ -64,6 +71,11 @@
    1.25  	return true;
    1.26  }
    1.27  
    1.28 +Vector3 Sphere::gen_surface_point() const
    1.29 +{
    1.30 +	return sphrand(1.0);
    1.31 +}
    1.32 +
    1.33  Vector3 Sphere::calc_normal(const RayHit &hit) const
    1.34  {
    1.35  	Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist;
    1.36 @@ -143,7 +155,27 @@
    1.37  		return true;
    1.38  	}
    1.39  	return false;
    1.40 +}
    1.41  
    1.42 +#define SIGN(x)	(x >= 0.0 ? 1.0 : -1.0)
    1.43 +
    1.44 +Vector3 Box::gen_surface_point() const
    1.45 +{
    1.46 +	Vector3 rnd{randf(-1, 1), randf(-1, 1), randf(-1, 1)};
    1.47 +	float absrnd[3];
    1.48 +
    1.49 +	absrnd[0] = fabs(rnd.x);
    1.50 +	absrnd[1] = fabs(rnd.y);
    1.51 +	absrnd[2] = fabs(rnd.z);
    1.52 +
    1.53 +	int major = 0;
    1.54 +	for(int i=1; i<3; i++) {
    1.55 +		if(absrnd[i] > absrnd[major]) {
    1.56 +			major = i;
    1.57 +		}
    1.58 +	}
    1.59 +	rnd[major] = SIGN(rnd[major]);
    1.60 +	return rnd;
    1.61  }
    1.62  
    1.63  #define BOX_EXT		0.499999
    1.64 @@ -176,6 +208,15 @@
    1.65  	return false;
    1.66  }
    1.67  
    1.68 +Vector3 Triangle::gen_surface_point() const
    1.69 +{
    1.70 +	float bu = randf();
    1.71 +	float bv = randf();
    1.72 +	float bw = 1.0 - (bu + bv);
    1.73 +
    1.74 +	return v[0] * bu + v[1] * bv + v[2] * bw;
    1.75 +}
    1.76 +
    1.77  // --- class Mesh ---
    1.78  
    1.79  bool Mesh::intersect(const Ray &ray, RayHit *hit) const
    1.80 @@ -200,3 +241,9 @@
    1.81  	}
    1.82  	return false;
    1.83  }
    1.84 +
    1.85 +Vector3 Mesh::gen_surface_point() const
    1.86 +{
    1.87 +	// this needs some precalculation...
    1.88 +	return Vector3(0, 0, 0);	// TODO
    1.89 +}