출처 : 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.
*
*/

#import <Foundation/Foundation.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>

void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz);




gluLookAt.c

/*
* gluLookAt.c
*/


#include "gluLookAt.h"

void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz)
{
GLfloat m[16];
GLfloat x[3], y[3], z[3];
GLfloat mag;

/* Make rotation matrix */

/* Z vector */
z[0] = eyex - centerx;
z[1] = eyey - centery;
z[2] = eyez - centerz;
mag = sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
if (mag) { /* mpichler, 19950515 */
z[0] /= mag;
z[1] /= mag;
z[2] /= mag;
}

/* Y vector */
y[0] = upx;
y[1] = upy;
y[2] = upz;

/* X vector = Y cross Z */
x[0] = y[1] * z[2] - y[2] * z[1];
x[1] = -y[0] * z[2] + y[2] * z[0];
x[2] = y[0] * z[1] - y[1] * z[0];

/* Recompute Y = Z cross X */
y[0] = z[1] * x[2] - z[2] * x[1];
y[1] = -z[0] * x[2] + z[2] * x[0];
y[2] = z[0] * x[1] - z[1] * x[0];

/* 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[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
if (mag) {
x[0] /= mag;
x[1] /= mag;
x[2] /= mag;
}

mag = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
if (mag) {
y[0] /= mag;
y[1] /= mag;
y[2] /= mag;
}

#define M(row,col) m[col*4+row]
M(0, 0) = x[0];
M(0, 1) = x[1];
M(0, 2) = x[2];
M(0, 3) = 0.0;
M(1, 0) = y[0];
M(1, 1) = y[1];
M(1, 2) = y[2];
M(1, 3) = 0.0;
M(2, 0) = z[0];
M(2, 1) = z[1];
M(2, 2) = z[2];
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;
#undef M
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


자료구조와 알고리즘을 공부하기 좋은 사이트 !


http://visualgo.net/


확실히 시각화 해서 보니까 최고인듯 b




사용법에 대한 영상은 


http://www.youtube.com/watch?v=k0GHDQ0pqXY





어제 경기를 보는데 맘이 아파서 끝까지 다 못봄 ㅠㅠ


으.. 역시 T1은 아직 무리인가................. 헠헠





공부 좀 하려고 예전에 스크랩 해준 페이지를 둘러보다가


갑자기 보게 된............ 재걸이 영상 :D


손이 오글오글 거리는데 그래도 계속 쳐다보게 되는건...


아마..... 와치 재걸이가 잘생겨서 이겠지 ... *



내 마음에 강타 좀 써줘요 헠헠




'Game은 나의 활력소 > 나진' 카테고리의 다른 글

온게임넷 라이브 tv  (0) 2015.09.07
롤챔스는...  (0) 2015.03.12
저번주의 롤챔스 프리시즌 !  (0) 2014.12.10
롤드컵 16강 대진  (0) 2014.09.12
조재걸 - 박정석 감독님 화보  (0) 2014.09.10

+ Recent posts