//
// ___FILENAME___
// ___PACKAGENAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright (c) ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved.
//
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_EMBEDDED
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#else
#import <OpenGL/OpenGL.h>
#endif
#import "ConstantsAndMacros.h"
@class OpenGLWaveFrontMaterial;
#pragma mark -
#pragma mark Color3D
#pragma mark -
typedef struct {
GLfloat red;
GLfloat green;
GLfloat blue;
GLfloat alpha;
} Color3D;
static inline Color3D Color3DMake(CGFloat inRed, CGFloat inGreen, CGFloat inBlue, CGFloat inAlpha)
{
Color3D ret;
ret.red = inRed;
ret.green = inGreen;
ret.blue = inBlue;
ret.alpha = inAlpha;
return ret;
}
static inline void Color3DSet(Color3D *color, CGFloat inRed, CGFloat inGreen, CGFloat inBlue, CGFloat inAlpha)
{
color->red = inRed;
color->green = inGreen;
color->blue = inBlue;
color->alpha = inAlpha;
}
static inline Color3D Color3DInterpolate(Color3D color1, Color3D color2, GLfloat percent)
{
Color3D ret;
ret.red = color1.red + ((color2.red - color1.red) * percent);
ret.blue = color1.blue + ((color2.blue - color1.blue) * percent);
ret.green = color1.green + ((color2.green - color1.green) * percent);
ret.alpha = color1.alpha + ((color2.alpha - color1.alpha) * percent);
if (ret.red > 1.0)
ret.red -= 1.0;
if (ret.green > 1.0)
ret.green -= 1.0;
if (ret.blue > 1.0)
ret.blue -= 1.0;
if (ret.alpha > 1.0)
ret.alpha = 1.0;
if (ret.red < 0.0)
ret.red += 1.0;
if (ret.green < 0.0)
ret.green += 1.0;
if (ret.blue < 0.0)
ret.blue += 1.0;
if (ret.alpha < 0.0)
ret.alpha += 1.0;
return ret;
}
#pragma mark -
#pragma mark Vertex3D
#pragma mark -
typedef struct {
GLfloat x;
GLfloat y;
GLfloat z;
} Vertex3D;
static inline Vertex3D Vertex3DMake(CGFloat inX, CGFloat inY, CGFloat inZ)
{
Vertex3D ret;
ret.x = inX;
ret.y = inY;
ret.z = inZ;
return ret;
}
static inline void Vertex3DSet(Vertex3D *vertex, CGFloat inX, CGFloat inY, CGFloat inZ)
{
vertex->x = inX;
vertex->y = inY;
vertex->z = inZ;
}
#pragma mark -
#pragma mark Vector3D
#pragma mark -
typedef Vertex3D Vector3D;
#define Vector3DMake(x,y,z) (Vector3D)Vertex3DMake(x, y, z)
#define Vector3DSet(vector,x,y,z) Vertex3DSet(vector, x, y, z)
static inline GLfloat Vector3DMagnitude(Vector3D vector)
{
return sqrtf((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}
static inline void Vector3DNormalize(Vector3D *vector)
{
GLfloat vecMag = Vector3DMagnitude(*vector);
if ( vecMag == 0.0 )
{
vector->x = 1.0;
vector->y = 0.0;
vector->z = 0.0;
return;
}
vector->x /= vecMag;
vector->y /= vecMag;
vector->z /= vecMag;
}
static inline GLfloat Vector3DDotProduct(Vector3D vector1, Vector3D vector2)
{
return vector1.x*vector2.x + vector1.y*vector2.y + vector1.z*vector2.z;
}
static inline Vector3D Vector3DCrossProduct(Vector3D vector1, Vector3D vector2)
{
Vector3D ret;
ret.x = (vector1.y * vector2.z) - (vector1.z * vector2.y);
ret.y = (vector1.z * vector2.x) - (vector1.x * vector2.z);
ret.z = (vector1.x * vector2.y) - (vector1.y * vector2.x);
return ret;
}
static inline Vector3D Vector3DMakeWithStartAndEndPoints(Vertex3D start, Vertex3D end)
{
Vector3D ret;
ret.x = end.x - start.x;
ret.y = end.y - start.y;
ret.z = end.z - start.z;
Vector3DNormalize(&ret);
return ret;
}
static inline Vector3D Vector3DAdd(Vector3D vector1, Vector3D vector2)
{
Vector3D ret;
ret.x = vector1.x + vector2.x;
ret.y = vector1.y + vector2.y;
ret.z = vector1.z + vector2.z;
return ret;
}
static inline void Vector3DFlip (Vector3D *vector)
{
vector->x = -vector->x;
vector->y = -vector->y;
vector->z = -vector->z;
}
static inline void Vector3DRotateToDirection (GLfloat pitch, GLfloat azimuth, Vector3D *vector)
{
vector->x = -sin(DEGREES_TO_RADIANS(azimuth)) * cos(DEGREES_TO_RADIANS(pitch));
vector->y = sin(DEGREES_TO_RADIANS(pitch));
vector->z = cos(DEGREES_TO_RADIANS(pitch)) * cos(DEGREES_TO_RADIANS(azimuth));
}
#pragma mark -
#pragma mark Rotation3D
#pragma mark -
// A Rotation3D is just a Vertex3D used to store three angles (pitch, yaw, roll) instead of cartesian coordinates.
// For simplicity, we just reuse the Vertex3D, even though the member names should probably be either xRot, yRot,
// and zRot, or else pitch, yaw, roll.
typedef Vertex3D Rotation3D;
#define Rotation3DMake(x,y,z) (Rotation3D)Vertex3DMake(x, y, z)
#pragma mark -
#pragma mark Face3D
#pragma mark -
// Face3D is used to hold three integers which will be integer index values to another array
typedef struct {
GLushort v1;
GLushort v2;
GLushort v3;
} Face3D;
static inline Face3D Face3DMake(int v1, int v2, int v3)
{
Face3D ret;
ret.v1 = v1;
ret.v2 = v2;
ret.v3 = v3;
return ret;
}
#pragma mark -
#pragma mark Triangle3D
#pragma mark -
typedef struct {
Vertex3D v1;
Vertex3D v2;
Vertex3D v3;
} Triangle3D;
static inline Triangle3D Triangle3DMake(Vertex3D inV1, Vertex3D inV2, Vertex3D inV3)
{
Triangle3D ret;
ret.v1 = inV1;
ret.v2 = inV2;
ret.v3 = inV3;
return ret;
}
static inline Vector3D Triangle3DCalculateSurfaceNormal(Triangle3D triangle)
{
Vector3D u = Vector3DMakeWithStartAndEndPoints(triangle.v2, triangle.v1);
Vector3D v = Vector3DMakeWithStartAndEndPoints(triangle.v3, triangle.v1);
Vector3D ret;
ret.x = (u.y * v.z) - (u.z * v.y);
ret.y = (u.z * v.x) - (u.x * v.z);
ret.z = (u.x * v.y) - (u.y * v.x);
return ret;
}
#pragma mark -
#pragma mark Interleaving
#pragma mark -
typedef struct {
GLfloat s;
GLfloat t;
} TextureCoord3D;
typedef struct {
Vertex3D vertex;
Vector3D normal;
} VertexData3D;
typedef struct {
Vertex3D vertex;
Vector3D normal;
TextureCoord3D texCoord;
} TexturedVertexData3D;
typedef struct {
Vertex3D vertex;
Vector3D normal;
Color3D color;
} ColoredVertexData3D;
#pragma mark -
#pragma mark Matrices
#pragma mark -
typedef GLfloat Matrix3D[16];
// OpenGL ES hardware accelerates Vector * Matrix but not Matrix * Matrix
/*
These defines, the fast sine function, and the vectorized version of the
matrix multiply function below are based on the Matrix4Mul method from
the vfp-math-library. Thi code has been modified, and are subject to
the original license terms and ownership as follow:
VFP math library for the iPhone / iPod touch
Copyright (c) 2007-2008 Wolfgang Engel and Matthias Grundmann
http://code.google.com/p/vfpmathlibrary/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising
from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
static inline float fastAbs(float x) { return (x < 0) ? -x : x; }
static inline GLfloat fastSinf(GLfloat x)
{
// fast sin function; maximum error is 0.001
const float P = 0.225;
x = x * M_1_PI;
int k = (int) round(x);
x = x - k;
float y = (4 - 4 * fastAbs(x)) * x;
y = P * (y * fastAbs(y) - y) + y;
return (k&1) ? -y : y;
}
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
#define VFP_CLOBBER_S0_S31 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", \
"s9", "s10", "s11", "s12", "s13", "s14", "s15", "s16", \
"s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", \
"s25", "s26", "s27", "s28", "s
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Empty OpenGL ES Application.xctemplate.zip (12个子文件)
Empty OpenGL ES Application.xctemplate
TemplateInfo.plist 4KB
.DS_Store 6KB
Classes
GLViewController.m 2KB
GLView.h 920B
GLViewController.h 291B
GLView.m 4KB
OpenGLCommon.h 23KB
OpenGLTexture3D.m 3KB
.DS_Store 6KB
ConstantsAndMacros.h 941B
OpenGLTexture3D.h 569B
TemplateIcon.icns 31KB
共 12 条
- 1
资源评论
- midsummer__2015-06-29写的真的很好,受教了
热血枫叶
- 粉丝: 388
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 5uonly.apk
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- 基于JSP毕业设计-基于WEB操作系统课程教学网站的设计与实现(源代码+论文).zip
- 基于LM324和LM386的音响放大器Multisim仿真+PCB电路原理图
- Python机器学习与数据挖掘环境配置与库验证
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功