출처 : http://iphonedevelopment.blogspot.kr/2008/12/glulookat.html
OpenGL에서 사용되던 카메라 시점을 설정해 주기 위한
glLookAt이 OpenGLES에서는 제공되지 않기 때문에 찾던 중 발견함.
역시... 해외 능력자들은 대단하다 ㅠㅠb
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.c
/*
* 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);
}
'Programmer의 텅빈 공간 > OpenGL/GLSL' 카테고리의 다른 글
OpenGLES에서 Matrix 기능 사용하기 (0) | 2015.01.20 |
---|---|
토파즈 필터 구현시 도움이 될만한 논문 (0) | 2014.07.11 |
Color Curves Shader (0) | 2014.06.13 |
Kuwahara Effect (0) | 2014.06.11 |
Edge Effect Shader (0) | 2014.06.11 |