gluLookAt.h
/*
* gluLookAt.h
*
* This is a modified version of the function of the same name from
* the Mesa3D project ( http://mesa3d.org/ ), which is licensed
* under the MIT license, which allows use, modification, and
* redistribution
*
* In order to work under OpenGL ES, all instances of GLdouble
* had to be changed to GLfloat, and all "d" function calls had
* to be changed to the "f" versions.
*
* Original developer's comments have been left in place.
*
* Out of respect for the original authors, this is licensed under
* the Mesa (MIT) license. Original license follows:
*
* -----------------------------------------------------------------------
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz);
gluLookAt.m
/*
* gluLookAt.c
*/
void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz)
{
GLfloat m ;
GLfloat x , y , z ;
GLfloat mag;
/* Make rotation matrix */
/* Z vector */
z = eyex - centerx;
z = eyey - centery;
z = eyez - centerz;
mag = sqrt(z * z + z * z + z * z );
if { /* mpichler, 19950515 */
z /= mag;
z /= mag;
z /= mag;
}
/* Y vector */
y = upx;
y = upy;
y = upz;
/* X vector = Y cross Z */
x = y * z - y * z ;
x = -y * z + y * z ;
x = y * z - y * z ;
/* Recompute Y = Z cross X */
y = z * x - z * x ;
y = -z * x + z * x ;
y = z * x - z * x ;
/* mpichler, 19950515 */
/* cross product gives area of parallelogram, which is < 1.0 for
* non-perpendicular unit-length vectors; so normalize x, y here
*/
mag = sqrt(x * x + x * x + x * x );
if {
x /= mag;
x /= mag;
x /= mag;
}
mag = sqrt(y * y + y * y + y * y );
if {
y /= mag;
y /= mag;
y /= mag;
}
M(0, 0) = x ;
M(0, 1) = x ;
M(0, 2) = x ;
M(0, 3) = 0.0;
M(1, 0) = y ;
M(1, 1) = y ;
M(1, 2) = y ;
M(1, 3) = 0.0;
M(2, 0) = z ;
M(2, 1) = z ;
M(2, 2) = z ;
M(2, 3) = 0.0;
M(3, 0) = 0.0;
M(3, 1) = 0.0;
M(3, 2) = 0.0;
M(3, 3) = 1.0;
glMultMatrixf(m);
/* Translate Eye to Origin */
glTranslatef(-eyex, -eyey, -eyez);
}
No comments:
Post a Comment