mirror of https://github.com/axmolengine/axmol.git
issue #11: add glu.cpp, glu.h and OpenGL_Internal.h
This commit is contained in:
parent
0e6a96423c
commit
cb433f5988
|
@ -0,0 +1,46 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
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 THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __SUPPORT_OPGL_SUPPORT_OPGL_INTERNAL_H__
|
||||||
|
#define __SUPPORT_OPGL_SUPPORT_OPGL_INTERNAL_H__
|
||||||
|
|
||||||
|
/* Generic error reporting */
|
||||||
|
#define REPORT_ERROR(__FORMAT__, ...) printf("%s: %s\n", __FUNCTION__, __VA_ARGS__)
|
||||||
|
|
||||||
|
/* EAGL and GL functions calling wrappers that log on error */
|
||||||
|
#define CALL_EAGL_FUNCTION(__FUNC__, ...) ({ EAGLError __error = __FUNC__( __VA_ARGS__ ); if(__error != kEAGLErrorSuccess) printf("%s() called from %s returned error %i\n", #__FUNC__, __FUNCTION__, __error); (__error ? false : true); })
|
||||||
|
//#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); (__error ? NO : YES); })
|
||||||
|
#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); })
|
||||||
|
|
||||||
|
/* Optional delegate methods support */
|
||||||
|
#ifndef __DELEGATE_IVAR__
|
||||||
|
#define __DELEGATE_IVAR__ _delegate
|
||||||
|
#endif
|
||||||
|
#ifndef __DELEGATE_METHODS_IVAR__
|
||||||
|
#define __DELEGATE_METHODS_IVAR__ _delegateMethods
|
||||||
|
#endif
|
||||||
|
#define TEST_DELEGATE_METHOD_BIT(__BIT__) (self->__DELEGATE_METHODS_IVAR__ & (1 << __BIT__))
|
||||||
|
#define SET_DELEGATE_METHOD_BIT(__BIT__, __NAME__) { if([self->__DELEGATE_IVAR__ respondsToSelector:@selector(__NAME__)]) self->__DELEGATE_METHODS_IVAR__ |= (1 << __BIT__); else self->__DELEGATE_METHODS_IVAR__ &= ~(1 << __BIT__); }
|
||||||
|
|
||||||
|
#endif // __SUPPORT_OPGL_SUPPORT_OPGL_INTERNAL_H__
|
|
@ -0,0 +1,129 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
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 THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "glu.h"
|
||||||
|
#include "OpenGL_Internal.h"
|
||||||
|
|
||||||
|
#include <GLES/gl.h>
|
||||||
|
|
||||||
|
#define _USE_MATH_DEFINES
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
|
||||||
|
{
|
||||||
|
GLfloat xmin, xmax, ymin, ymax;
|
||||||
|
|
||||||
|
ymax = zNear * (GLfloat)tanf(fovy * (float)M_PI / 360);
|
||||||
|
ymin = -ymax;
|
||||||
|
xmin = ymin * aspect;
|
||||||
|
xmax = ymax * aspect;
|
||||||
|
|
||||||
|
glFrustumf(xmin, xmax,
|
||||||
|
ymin, ymax,
|
||||||
|
zNear, zFar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gluLookAt(float fEyeX, float fEyeY, float fEyeZ,
|
||||||
|
float fCenterX, float fCenterY, float fCenterZ,
|
||||||
|
float fUpX, float fUpY, float fUpZ)
|
||||||
|
{
|
||||||
|
GLfloat m[16];
|
||||||
|
GLfloat x[3], y[3], z[3];
|
||||||
|
GLfloat mag;
|
||||||
|
|
||||||
|
/* Make rotation matrix */
|
||||||
|
|
||||||
|
/* Z vector */
|
||||||
|
z[0] = fEyeX - fCenterX;
|
||||||
|
z[1] = fEyeY - fCenterY;
|
||||||
|
z[2] = fEyeZ - fCenterZ;
|
||||||
|
mag = (float)sqrtf(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
|
||||||
|
if (mag) {
|
||||||
|
z[0] /= mag;
|
||||||
|
z[1] /= mag;
|
||||||
|
z[2] /= mag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Y vector */
|
||||||
|
y[0] = fUpX;
|
||||||
|
y[1] = fUpY;
|
||||||
|
y[2] = fUpZ;
|
||||||
|
|
||||||
|
/* 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];
|
||||||
|
|
||||||
|
/* cross product gives area of parallelogram, which is < 1.0 for
|
||||||
|
* non-perpendicular unit-length vectors; so normalize x, y here
|
||||||
|
*/
|
||||||
|
|
||||||
|
mag = (float)sqrtf(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
|
||||||
|
if (mag) {
|
||||||
|
x[0] /= mag;
|
||||||
|
x[1] /= mag;
|
||||||
|
x[2] /= mag;
|
||||||
|
}
|
||||||
|
|
||||||
|
mag = (float)sqrtf(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.0f;
|
||||||
|
M(1, 0) = y[0];
|
||||||
|
M(1, 1) = y[1];
|
||||||
|
M(1, 2) = y[2];
|
||||||
|
M(1, 3) = 0.0f;
|
||||||
|
M(2, 0) = z[0];
|
||||||
|
M(2, 1) = z[1];
|
||||||
|
M(2, 2) = z[2];
|
||||||
|
M(2, 3) = 0.0f;
|
||||||
|
M(3, 0) = 0.0f;
|
||||||
|
M(3, 1) = 0.0f;
|
||||||
|
M(3, 2) = 0.0f;
|
||||||
|
M(3, 3) = 1.0f;
|
||||||
|
#undef M
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
GLfloat fixedM[16];
|
||||||
|
for (a = 0; a < 16; ++a)
|
||||||
|
fixedM[a] = m[a];
|
||||||
|
glMultMatrixf(fixedM);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Translate Eye to Origin */
|
||||||
|
glTranslatef(-fEyeX, -fEyeY, -fEyeZ);
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
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 THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __SUPPORT_OPGL_SUPPORT_GLU_H__
|
||||||
|
#define __SUPPORT_OPGL_SUPPORT_GLU_H__
|
||||||
|
|
||||||
|
#include <GLES/gl.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
@file
|
||||||
|
cocos2d OpenGL GLU implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** OpenGL gluLookAt implementation */
|
||||||
|
void gluLookAt(float fEyeX, float fEyeY, float fEyeZ, float fLookAtX, float fLookAtY, float fLookAtZ, float fUpX, float fUpY, float fUpZ);
|
||||||
|
/** OpenGL gluPerspective implementation */
|
||||||
|
void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar);
|
||||||
|
|
||||||
|
#endif // __SUPPORT_OPGL_SUPPORT_GLU_H__
|
Loading…
Reference in New Issue