Blame view

legacy/rtsCubeSampler.cpp 1.77 KB
f1402849   dmayerich   renewed commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  #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;

  }