/*
Copyright (c) 2008, Luke Benstead.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file mat4.c
*/
#include <memory.h>
#include <assert.h>
#include <stdlib.h>
#include "kazmath/utility.h"
#include "kazmath/vec3.h"
#include "kazmath/mat4.h"
#include "kazmath/mat3.h"
#include "kazmath/quaternion.h"
#include "kazmath/plane.h"
#include "kazmath/neon_matrix_impl.h"
/**
* Fills a kmMat4 structure with the values from a 16
* element array of floats
* @Params pOut - A pointer to the destination matrix
* pMat - A 16 element array of floats
* @Return Returns pOut so that the call can be nested
*/
kmMat4* const kmMat4Fill(kmMat4* pOut, const kmScalar* pMat)
{
memcpy(pOut->mat, pMat, sizeof(kmScalar) * 16);
return pOut;
}
/**
* Sets pOut to an identity matrix returns pOut
* @Params pOut - A pointer to the matrix to set to identity
* @Return Returns pOut so that the call can be nested
*/
kmMat4* const kmMat4Identity(kmMat4* pOut)
{
memset(pOut->mat, 0, sizeof(float) * 16);
pOut->mat[0] = pOut->mat[5] = pOut->mat[10] = pOut->mat[15] = 1.0f;
return pOut;
}
float get(const kmMat4 * pIn, int row, int col)
{
return pIn->mat[row + 4*col];
}
void set(kmMat4 * pIn, int row, int col, float value)
{
pIn->mat[row + 4*col] = value;
}
void swap(kmMat4 * pIn, int r1, int c1, int r2, int c2)
{
float tmp = get(pIn,r1,c1);
set(pIn,r1,c1,get(pIn,r2,c2));
set(pIn,r2,c2, tmp);
}
//Returns an upper and a lower triangular matrix which are L and R in the Gauss algorithm
int gaussj(kmMat4 *a, kmMat4 *b)
{
int i, icol = 0, irow = 0, j, k, l, ll, n = 4, m = 4;
float big, dum, pivinv;
int indxc[n];
int indxr[n];
int ipiv[n];
for (j = 0; j < n; j++) {
ipiv[j] = 0;
}
for (i = 0; i < n; i++) {
big = 0.0f;
for (j = 0; j < n; j++) {
if (ipiv[j] != 1) {
for (k = 0; k < n; k++) {
if (ipiv[k] == 0) {
if (abs(get(a,j, k)) >= big) {
big = abs(get(a,j, k));
irow = j;
icol = k;
}
}
}
}
}
++(ipiv[icol]);
if (irow != icol) {
for (l = 0; l < n; l++) {
swap(a,irow, l, icol, l);
}
for (l = 0; l < m; l++) {
swap(b,irow, l, icol, l);
}
}
indxr[i] = irow;
indxc[i] = icol;
if (get(a,icol, icol) == 0.0) {
return KM_FALSE;
}
pivinv = 1.0f / get(a,icol, icol);
set(a,icol, icol, 1.0f);
for (l = 0; l < n; l++) {
set(a,icol, l, get(a,icol, l) * pivinv);
}
for (l = 0; l < m; l++) {
set(b,icol, l, get(b,icol, l) * pivinv);
}
for (ll = 0; ll < n; ll++) {
if (ll != icol) {
dum = get(a,ll, icol);
set(a,ll, icol, 0.0f);
for (l = 0; l < n; l++) {
set(a,ll, l, get(a,ll, l) - get(a,icol, l) * dum);
}
for (l = 0; l < m; l++) {
set(b,ll, l, get(a,ll, l) - get(b,icol, l) * dum);
}
}
}
}
// This is the end of the main loop over columns of the reduction. It only remains to unscram-
// ble the solution in view of the column interchanges. We do this by interchanging pairs of
// columns in the reverse order that the permutation was built up.
for (l = n - 1; l >= 0; l--) {
if (indxr[l] != indxc[l]) {
for (k = 0; k < n; k++) {
swap(a,k, indxr[l], k, indxc[l]);
}
}
}
return KM_TRUE;
}
/**
* Calculates the inverse of pM and stores the result in
* pOut.
* @Return Returns NULL if there is no inverse, else pOut
*/
kmMat4* const kmMat4Inverse(kmMat4* pOut, const kmMat4* pM)
{
kmMat4 inv;
kmMat4Assign(&inv, pM);
kmMat4 tmp;
kmMat4Identity(&tmp);
if(gaussj(&inv, &tmp) == KM_FALSE) {
return NULL;
}
kmMat4Assign(pOut, &inv);
return pOut;
}
/**
* Returns KM_TRUE if pIn is an identity matrix
* KM_FALSE otherwise
*/
const int kmMat4IsIdentity(const kmMat4* pIn)
{
static const float identity [] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
return (memcmp(identity, pIn->mat, sizeof(float) * 16) == 0);
}
/**
* Sets pOut to the transpose of pIn, returns pOut
*/
kmMat4* const kmMat4Transpose(kmMat4* pOut, const kmMat4* pIn)
{
int x, z;
for (z = 0; z < 4; ++z) {
for (x = 0; x < 4; ++x) {
pOut->mat[(z * 4) + x] = pIn->mat[(x * 4) + z];
}
}
return pOut;
}
/**
* Multiplies pM1 with pM2, stores the result in pOut, returns pOut
*/
kmMat4* const kmMat4Multiply(kmMat4* pOut, const kmMat4* pM1, const kmMat4* pM2)
{
#if defined(__ARM_NEON__)
float mat[16];
// Invert column-order with row-order
NEON_Matrix4Mul( &pM2->mat[0], &pM1->mat[0], &mat[0] );
#else
float mat[16];
const float *m1 = pM1->mat, *m2 = pM2->mat;
mat[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3];
mat[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3];
mat[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3];
mat[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3];
mat[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7];
mat[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7];
mat[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7];
mat[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7];
mat[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11];
mat[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11];
mat[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11];
mat[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11];
mat[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15];
mat[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15];
mat[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15];
mat[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15];
#endif
memcpy(pOut->mat, mat, sizeof(float)*16);
return pOut;
}
/**
* Assigns the value of pIn to pOut
*/
kmMat4* const kmMat4Assign(kmMat4* pOut, const kmMat4* pIn)
{
assert(pOut != pIn && "You have tried to self-assi
没有合适的资源?快使用搜索试试~ 我知道了~
IOS应用源码之仿微信“飞机大战”ios游戏源码 .rar
共412个文件
h:151个
m:108个
png:78个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 47 浏览量
2022-07-09
10:38:59
上传
评论
收藏 3.96MB RAR 举报
温馨提示
IOS应用源码之仿微信“飞机大战”ios游戏源码 .rar
资源推荐
资源详情
资源评论
收起资源包目录
IOS应用源码之仿微信“飞机大战”ios游戏源码 .rar (412个子文件)
mat4.c 21KB
quaternion.c 14KB
mat3.c 10KB
vec3.c 7KB
matrix.c 5KB
ray2.c 5KB
vec4.c 5KB
plane.c 5KB
vec2.c 3KB
neon_matrix_impl.c 3KB
mat4stack.c 3KB
base64.c 2KB
aabb.c 2KB
utility.c 2KB
ccUtils.c 367B
Hero.ccb 17KB
Enemy1.ccb 6KB
Loading.ccb 6KB
GameScene.ccb 6KB
Level.ccb 5KB
Bullet.ccb 4KB
Hero.ccbi 522B
Level.ccbi 310B
Enemy1.ccbi 307B
GameScene.ccbi 287B
Loading.ccbi 266B
Bullet.ccbi 200B
Airplane.ccbproj 639B
Airplane.ccbresourcelog 2KB
ChangeLog 25KB
Thumbs.db 114KB
Thumbs.db 8KB
Thumbs.db 6KB
Thumbs.db 5KB
.gitignore 374B
uthash.h 58KB
utlist.h 53KB
ccDeprecated.h 22KB
CCNode.h 21KB
CCActionInterval.h 15KB
CCMenuItem.h 15KB
CCFileUtils.h 15KB
CCParticleSystem.h 15KB
CocosDenshion.h 14KB
ccMacros.h 13KB
CCTexture2D.h 12KB
CCDirector.h 11KB
CCSprite.h 10KB
CCEventDispatcher.h 10KB
CCLayer.h 10KB
CCScheduler.h 10KB
ccConfig.h 10KB
ccTypes.h 10KB
CCTransition.h 10KB
CDAudioManager.h 9KB
CDXMacOSXSupport.h 9KB
ccCArray.h 9KB
CGPointExtension.h 8KB
CCActionEase.h 8KB
CCGLView.h 8KB
CCLabelBMFont.h 8KB
CCLabelTTF.h 8KB
CCActionTiledGrid.h 7KB
CCGLProgram.h 7KB
CCTMXXMLParser.h 7KB
CCActionGrid3D.h 7KB
CCTextureAtlas.h 7KB
CCTMXLayer.h 7KB
CCSpriteBatchNode.h 6KB
CCRenderTexture.h 6KB
CCActionInstant.h 6KB
CCAction.h 6KB
CCProtocols.h 6KB
CCAnimation.h 6KB
CCDrawingPrimitives.h 6KB
CCTMXTiledMap.h 5KB
CCActionCatmullRom.h 5KB
CCActionGrid.h 5KB
CCTextureCache.h 5KB
ccGLStateCache.h 5KB
CCTexturePVR.h 5KB
cocos2d.h 5KB
CCSpriteFrame.h 5KB
OpenGL_Internal.h 5KB
CCParticleBatchNode.h 4KB
CCSpriteFrameCache.h 4KB
quaternion.h 4KB
CCTouchDispatcher.h 4KB
CCArray.h 4KB
CCConfiguration.h 4KB
CCActionManager.h 4KB
mat4.h 4KB
CCBReader.h 4KB
CCGrid.h 4KB
SimpleAudioEngine.h 4KB
CCDirectorIOS.h 4KB
CCProgressTimer.h 3KB
CCDirectorMac.h 3KB
CCAtlasNode.h 3KB
CCTouchHandler.h 3KB
共 412 条
- 1
- 2
- 3
- 4
- 5
资源评论
reg183
- 粉丝: 1811
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab实现电力系统仿真计算软件包,包括潮流计算,最优潮流计算等.rar
- 基于matlab实现电力系统各种故障波形仿真,单相接地故障,两相间短路,两相接地短路,三相短路等.rar
- 基于matlab实现电动汽车动力性,爬坡性,续驶里程等性能仿真.rar
- Python动态烟花代码.pdf
- 基于matlab实现串口发送接收数据 可配置端口,波特率等 发送可选择ASCII方式或HEX方式
- matlab基于BP神经网络手写字母识别(单一).zip代码9
- 基于matlab实现编写的串口调试工具,数据接收部分采用中断方式,保证了实时的数据显示
- 基于matlab实现39节点电力系统合闸角调控过程中的机组和负荷的灵敏度计算.rar
- HBase数据库性能调优
- 原生微信小程序源码 - -首字母排序选择
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功