Subversion Repositories gelsvn

Rev

Rev 125 | Rev 570 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 125 Rev 569
Line 29... Line 29...
29
				(*this)[1] = rlen * sin(theta) * sin(phi);
29
				(*this)[1] = rlen * sin(theta) * sin(phi);
30
				(*this)[2] = rlen * cos(theta);
30
				(*this)[2] = rlen * cos(theta);
31
		}
31
		}
32
 
32
 
33
		template<class T, class V>
33
		template<class T, class V>
34
		void orthogonal(const ArithVec3Float<T,V>& _a, 
34
		void orthogonal(const ArithVec3Float<T,V>& n, 
35
										ArithVec3Float<T,V>& b, 
35
										ArithVec3Float<T,V>& b1, 
36
										ArithVec3Float<T,V>& c)
36
										ArithVec3Float<T,V>& b2)
37
		{
37
		{
38
				V a = normalize(_a);
-
 
39
				T max_sqval=sqr(a[0]);
-
 
40
				unsigned int mi=0;
-
 
41
				for(unsigned int i=1;i<3;i++)
-
 
42
				{
-
 
43
						T sqval = sqr(a[i]);
-
 
44
						if(max_sqval<sqval)
-
 
45
						{
-
 
46
								max_sqval = sqval;
-
 
47
								mi = i;
-
 
48
						}
-
 
49
				}
-
 
50
				b[mi] = 0;
-
 
51
				b[(mi+1)%3] = 1;
-
 
52
				b[(mi+2)%3] = 0;
-
 
53
 
-
 
54
				b = normalize(b-a*dot(b,a));
-
 
55
				c = normalize(cross(a,b));
38
			onb(normalize(n), b1, b2);
56
 
-
 
57
				if(dot(cross(b,c), a) < 0) swap(b,c);
-
 
58
		}
39
		}
59
 
40
 
-
 
41
    template<class T, class V>
-
 
42
    void onb(const ArithVec3Float<T,V>& n, 
-
 
43
             ArithVec3Float<T,V>& b1, 
-
 
44
             ArithVec3Float<T,V>& b2)
-
 
45
    {
-
 
46
      if(n[2] < -0.9999999f) // Handle the singularity
-
 
47
      {
-
 
48
        b1 = V( 0.0f, -1.0f, 0.0f);
-
 
49
        b2 = V(-1.0f,  0.0f, 0.0f);
-
 
50
        return;
-
 
51
      }
-
 
52
      const T a = 1.0f/(1.0f + n[2]);
-
 
53
      const T b = -n[0]*n[1]*a;
-
 
54
      b1 = V(1.0f - n[0]*n[0]*a, b, -n[0]);
-
 
55
      b2 = V(b, 1.0f - n[1]*n[1]*a, -n[1]);
-
 
56
    }
60
 
57
 
61
		template class ArithVec3Float<float, Vec3f>;
58
		template class ArithVec3Float<float, Vec3f>;
62
		template void orthogonal<float,Vec3f>(const ArithVec3Float<float,Vec3f>& a, 
59
		template void orthogonal<float,Vec3f>(const ArithVec3Float<float,Vec3f>& a, 
63
																					ArithVec3Float<float,Vec3f>& b, 
60
																					ArithVec3Float<float,Vec3f>& b, 
64
																					ArithVec3Float<float,Vec3f>& c);
61
																					ArithVec3Float<float,Vec3f>& c);
-
 
62
    template void onb<float,Vec3f>(const ArithVec3Float<float,Vec3f>& n, 
-
 
63
                                   ArithVec3Float<float,Vec3f>& b1, 
-
 
64
                                   ArithVec3Float<float,Vec3f>& b2);
65
 
65
 
66
		template class ArithVec3Float<double, Vec3d>;
66
		template class ArithVec3Float<double, Vec3d>;
67
		template void orthogonal<double,Vec3d>(const ArithVec3Float<double,Vec3d>& a,
67
		template void orthogonal<double,Vec3d>(const ArithVec3Float<double,Vec3d>& a,
68
																					 ArithVec3Float<double,Vec3d>& b, 
68
																					 ArithVec3Float<double,Vec3d>& b, 
69
																					 ArithVec3Float<double,Vec3d>& c);
69
																					 ArithVec3Float<double,Vec3d>& c);
70
 
-
 
-
 
70
    template void onb<double,Vec3d>(const ArithVec3Float<double,Vec3d>& n, 
-
 
71
                                    ArithVec3Float<double,Vec3d>& b1, 
-
 
72
                                    ArithVec3Float<double,Vec3d>& b2);
71
}
73
}