// YOUR CODE HERE
			// Given a vector n, form an orthogonal matrix with n as the last column, i.e.,
			// a coordinate system aligned such that n is its local z axis.
	static	__forceinline Mat3f	formBasis( const Vec3f& n ) 
	{
		Mat3f r;
		Vec3f q, b, t;

		// Get the minimum component of n
		int minIdx = 0;
		for (int i = 0; i < 3; ++i) {
			if ( abs(n[i]) < abs(n[minIdx]) ) minIdx = i;
		}

		// Replace the minimum component by 1.0f and take a cross-product to get a vector perpendicular to n
		q = n;
		q[minIdx] = 1.0f;

		t = (cross(q, n)).normalized();

		// Get the last perpendicular vector by taking n x t
		b = (cross(n, t)).normalized();

		// Construct the rotation matrix
		r.setCol(0, t);
		r.setCol(1, b);
		r.setCol(2, n);

		return r;
	}
Esempio n. 2
0
Mat3f formBasis(const Vec3f& n) {
	// YOUR CODE HERE (R3)
	Mat3f R;
	Vec3f Q = n;
	float min = 99;
	int ind = -1;
	for(int i = 0; i<3; ++i)
	if(abs(n[i]) < min)
	{
		min = abs(n[i]);
		ind = i;
	}
	Q[ind] = 1;
	Q.normalize();
	Vec3f T = cross(Q, n).normalized();
	Vec3f B = cross(n, T).normalized();
	R.setCol(0, T);
	R.setCol(1, B);
	R.setCol(2, n);
	float f = det(R);
	return R;
}