|
From: <pat...@us...> - 2012-08-03 22:12:47
|
Revision: 1278
http://ggt.svn.sourceforge.net/ggt/?rev=1278&view=rev
Author: patrickh
Date: 2012-08-03 22:12:41 +0000 (Fri, 03 Aug 2012)
Log Message:
-----------
>From the submission, this adds the following:
* a new setLookAt() function in Generate.h (implements gluLookAt())
* a new binary operator^() for Vec3 cross product in VecOps.h
Submitted by: Paul Martz
Modified Paths:
--------------
trunk/gmtl/Generate.h
trunk/gmtl/VecOps.h
Modified: trunk/gmtl/Generate.h
===================================================================
--- trunk/gmtl/Generate.h 2011-04-23 22:05:31 UTC (rev 1277)
+++ trunk/gmtl/Generate.h 2012-08-03 22:12:41 UTC (rev 1278)
@@ -715,7 +715,46 @@
return setFrustum( result, -right, top, right, -top, nr, fr );
}
+ /** Configure a matrix from view parameters.
+ *
+ * Functionally equivalent to gluLookAt(), this function configures
+ * @c result as a view matrix with the viewer positioned at @c eye,
+ * looking towards @c center, with the specified @c up orientation.
+ * Results are undefined if (center-eye) == 0 or (center-eye) is
+ * coincident with +/-up. @c result can be used to transform point
+ * data from world to OpenGL eye coordinates. @c result.mData can
+ * be passed to an OpenGL GLSL shader as uniform mat4 data.
+ *
+ * @pre (center-eye) has non-zero length
+ * @pre (center-eye) not coincident with +/-up
+ *
+ * @param result the matrix to be configured as a view matrix.
+ * @param eye the position of the viewer.
+ * @param center a target location to look at. The view direction is
+ * computed as @c center - @c eye.
+ * @param up the viewer's up orientation.
+ * @return a reference to @c result for convenience.
+ */
+ template <typename T>
+ inline Matrix<T, 4,4>& setLookAt( Matrix<T, 4,4>& result,
+ const Point<T, 3>& eye, const Point<T, 3>& center, const Vec<T, 3>& up )
+ {
+ Vec<T, 3> f( center-eye ); normalize( f );
+ Vec<T, 3> s( f ^ up ); normalize( s );
+ Vec<T, 3> u( s ^ f ); normalize( u );
+ Matrix<T, 4,4> orient;
+ zero( orient );
+ orient(0,0) = s[0]; orient(1,0) = u[0]; orient(2,0) = -f[0];
+ orient(0,1) = s[1]; orient(1,1) = u[1]; orient(2,1) = -f[1];
+ orient(0,2) = s[2]; orient(1,2) = u[2]; orient(2,2) = -f[2];
+ orient(3,3) = T(1.);
+
+ result = orient * makeTrans< Matrix<T, 4,4> >( -eye );
+ result.mState = Matrix<T, 4,4>::AFFINE;
+ return( result );
+ }
+
/*
template< typename DATA_TYPE, unsigned ROWS, unsigned COLS, unsigned SIZE, typename REP >
inline Matrix<DATA_TYPE, ROWS, COLS>& setTrans( Matrix<DATA_TYPE, ROWS, COLS>& result,
Modified: trunk/gmtl/VecOps.h
===================================================================
--- trunk/gmtl/VecOps.h 2011-04-23 22:05:31 UTC (rev 1277)
+++ trunk/gmtl/VecOps.h 2012-08-03 22:12:41 UTC (rev 1278)
@@ -467,6 +467,42 @@
}
/**
+ * Compute the cross product between v1 and v2 and return the result
+ * implemented as a binary ^ operator. Use this to initialize a new
+ * Vec with the cross product of two Vecs, for example, or to increase
+ * code readability in implementations of algebraic formulae. Note
+ * this operation applies only to 3-dimensional vectors.
+ *
+ * Example:
+ * @code
+ * Vec3f b(1.,0.,0.), c(0.,1.,0.);
+ * Vec3f a( b ^ c );
+ * @endcode
+ * This is equivalent to:
+ * @code
+ * Vec3f b(1.,0.,0.), c(0.,1.,0.);
+ * Vec3f a;
+ * cross( a, b, c );
+ * @endcode
+ *
+ * @pre v1 and v2 are 3-D vectors
+ *
+ * @param v1 the first vector
+ * @param v2 the second vector
+ *
+ * @return the cross product ( v1 ^ v2 ) as a new Vec.
+ */
+template<class DATA_TYPE>
+inline Vec<DATA_TYPE, 3> operator^( const Vec<DATA_TYPE, 3>& v1,
+ const Vec<DATA_TYPE, 3>& v2 )
+{
+ Vec<DATA_TYPE, 3> result;
+ cross( result, v1, v2 );
+ return( result );
+}
+
+
+/**
* Reflect a vector about a normal.
*
* This method reflects the given vector around the normal vector given. It is similar to if the normal vector was
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|