rtsCubeSampler.cpp 1.77 KB
#include "rtsCubeSampler.h"

vector<vector3D> rtsCubeSampler::Evaluate()
{
	/*This function evaluates the cube with the given parameters and returns
	a vector of sample normalized sample vectors.*/

	//find a valid up vector
	vector3D u(0.0, 1.0, 0.0);
	//calculate the side vector
	vector3D s = u.cross(m_main_vector);
	//orthogonalize the up vector
	u = m_main_vector.cross(s);
	//normalize all three vectors
	m_main_vector.normalize();
	u.normalize();
	s.normalize();

	//create a vector representing each side of the cube
	vector3D sides[6];
	sides[0] = m_main_vector;
	sides[1] = (m_main_vector)*(-1);
	sides[2] = u;
	sides[3] = u*(-1);
	sides[4] = s;
	sides[5] = s*(-1);

	//calculate the step size along the basis vectors for a side
	double step = 1.0/((double)m_squared_samples_per_side);

	//evaluate the cube, storing the result in an STL vector
	vector<vector3D> result;
	for(int k=0; k<6; k++)
		for(int i=0; i<m_squared_samples_per_side; i++)
			for(int j=0; j<m_squared_samples_per_side; j++)
			{
				//find the indices for the vectors representing the edges of the current side
				unsigned int u_vector_index = (k+2)%6;
				unsigned int v_vector_index = (k+4)%6;
				//get two basis vectors for the side
				vector3D u = sides[u_vector_index];
				vector3D v = sides[v_vector_index];

				//calculate a vector
				vector3D adjustment = (u*2*(i*step+0.5*step) - u) + (v*2*(j*step + 0.5*step) - v);
				vector3D final_vector = sides[k] + adjustment;
				final_vector.normalize();
				//test the angle and eliminate the vector if it is too large
				double cosine_angle = final_vector*m_main_vector;
				if(cosine_angle >= cos(TORADIANS(max_angle)))
					result.push_back(final_vector);
			}

	//return the vector of results
	return result;
}