⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xxglu.c

📁 此程序需要Brew sdk2.1版本以上,是关于OpenGL的手机编程.
💻 C
字号:
/*=================================================================================
FILE:			xxglu.c
  
DESCRIPTION:	This file is provide as a standard sample Brew source file. 
				Please refer to this OpenGL(R)ES brew sample application as a 
				reference on how to use the standard OpenGL-ES and EGL APIs.
                          
ABSTRACT:		Fixed point math functions.

AUTHOR:			QUALCOMM
                        
				Copyright (c) 2004 QUALCOMM Incorporated.
					   All Rights Reserved.
					QUALCOMM Proprietary/GTDR
=================================================================================*/

/*-------------------------------------------------------------------------------*
 *                      I N C L U D E   F I L E S                                *
 *-------------------------------------------------------------------------------*/
#include <AEEStdlib.h>
#include "xxglu.h"

/*-------------------------------------------------------------------------------*
 *                            M A C R O S                                        *
 *-------------------------------------------------------------------------------*/
typedef __int64 int64;
typedef unsigned __int64 uint64;

#define memcpy MEMCPY

#define Q_FACTOR	16

#define X		v[0]
#define Y		v[1]
#define Z		v[2]
#define W		v[3]

/*-------------------------------------------------------------------------------*
 *                          B E G I N   P R O G R A M                            *
 *-------------------------------------------------------------------------------*/

/*===========================================================================
FUNCTION: xxgluCopyMatrixFx
  
DESCRIPTION:
	This funtion copy one matrix to another 
   
PROTOTYPE:
	void xxgluCopyMatrixFx( int32 from[4][4], int32 to[4][4] )
      
PARAMETERS:
	from[4][4]	: copy from this matrix
	to[4][4]	: copy to this matrix
            
DEPENDENCIES
	none
              
RETURN VALUE
	none
                
===========================================================================*/
void xxgluCopyMatrixFx( int32 from[4][4], int32 to[4][4] )
{
	memcpy(to, from, sizeof(int32[4][4]));
}


/*===========================================================================
FUNCTION: xxgluCrossFx
  
DESCRIPTION:
	this function performs a vector cross product
   
PROTOTYPE:
	void xxgluCrossFx( int32 *n, int32 *a, int32 *b )
      
PARAMETERS:
	n : pointer to int32, result of the vector cross product
	a, b : pointer to int32, input of the vector cross product
            
DEPENDENCIES
	none
              
RETURN VALUE
	none
                
===========================================================================*/
void xxgluCrossFx( int32 *n, int32 *a, int32 *b )
{
	n[0] = (int32)((((int64)a[1]*b[2]) - ((int64)a[2]*b[1]))>>Q_FACTOR); 
	n[1] = (int32)((((int64)a[2]*b[0]) - ((int64)a[0]*b[2]))>>Q_FACTOR); 
	n[2] = (int32)((((int64)a[0]*b[1]) - ((int64)a[1]*b[0]))>>Q_FACTOR); 
}


/*===========================================================================
FUNCTION: xxgluDotFx
  
DESCRIPTION:
	this function perform a vector dot product
   
PROTOTYPE:
	int32 xxgluDotFx( int32 v1[3], int32 v2[3] )
      
PARAMETERS:
	v1[3], v2[3] : dot product input vector
            
DEPENDENCIES
	none
              
RETURN VALUE
	return Q16 vector dot product of input parameter v1[3] and v2[3]
                
===========================================================================*/
int32 xxgluDotFx( int32 v1[3], int32 v2[3] )
{
	return (int32)(((int64)((int64)v1[0]*v2[0]) + ((int64)v1[1]*v2[1]) + ((int64)v1[2]*v2[2]))>>Q_FACTOR);
}


/*===========================================================================
FUNCTION: xxgluSqrtFx
  
DESCRIPTION:
	this function perform square root  
   
PROTOTYPE:
	int32 xxgluSqrtFx(int32 val)
      
PARAMETERS:
	val : input value for the square root function
            
DEPENDENCIES
	none
              
RETURN VALUE
	return Q16 square root of input parameter val
                
===========================================================================*/
int32
#define step(shift)											\
    if((0x40000000l >> shift) + sqrtVal <= val)				\
    {														\
        val -= (0x40000000l >> shift) + sqrtVal;			\
        sqrtVal = (sqrtVal >> 1) | (0x40000000l >> shift);  \
    }														\
    else													\
    {														\
        sqrtVal = sqrtVal >> 1;                             \
    }

xxgluSqrtFx(int32 val)
{
// Note: This fast square root function only works with an even Q_FACTOR
    int32 sqrtVal = 0;
    
    step(0);
    step(2);
    step(4);
    step(6);
    step(8);
    step(10);
    step(12);
    step(14);
    step(16);
    step(18);
    step(20);
    step(22);
    step(24);
    step(26);
    step(28);
    step(30);
    
    if(sqrtVal < val)
    {
        ++sqrtVal;
    }
    
    sqrtVal <<= (Q_FACTOR)/2;
    return(sqrtVal);
}

/*===========================================================================
FUNCTION: my2gl_Norm
  
DESCRIPTION:
	this function nomalize a vector  
   
PROTOTYPE:
	int my2gl_Norm(int32 a[3])
      
PARAMETERS:
	a : pointer to a vector
            
DEPENDENCIES
	none
              
RETURN VALUE
	return the normalized vector of parameter a
                
===========================================================================*/
int my2gl_Norm(int32 a[3])
{
	int32 n, oon;
	n = (int32)(((int64)a[0]*a[0]+(int64)a[1]*a[1]+(int64)a[2]*a[2])>>Q_FACTOR);
	n = xxgluSqrtFx(n);
	
	if (n==0) return 0;

	oon = (int32)(((int64)1<<(Q_FACTOR<<1)) / n);
	a[0] = (int32)(((int64)a[0] * oon)>>Q_FACTOR);
	a[1] = (int32)(((int64)a[1] * oon)>>Q_FACTOR);
	a[2] = (int32)(((int64)a[2] * oon)>>Q_FACTOR);

	return n;

}

/*===========================================================================
FUNCTION: xxgluUnitFx
  
DESCRIPTION:
	this function calucate the unit vector
   
PROTOTYPE:
	int32 xxgluUnitFx( int32 vin[3], int32 vout[3] )
      
PARAMETERS:
	vin[3]	: input vector
	vout[3]	: output vector
            
DEPENDENCIES
	none
              
RETURN VALUE
	return Q16 unit vector of parameter vin[3]
                
===========================================================================*/
int32 xxgluUnitFx( int32 vin[3], int32 vout[3] )
{
	memcpy(vout, vin, (sizeof(int32)*3));
	return(my2gl_Norm(vout));
}

/*===========================================================================
FUNCTION: xxgluLookAtMatrixFx
  
DESCRIPTION:
	this function perform gluLookAt function
   
PROTOTYPE:
	void xxgluLookAtMatrixFx(int32 *m, int32 ex, int32 ey, int32 ez, int32 atx, int32 aty, int32 atz, int32 ux, int32 uy, int32 uz)
      
PARAMETERS:
	m				: pointer to the viewing matrix
	ex, ey, ez		: eye position in x, y and z
	atx, aty, atz	: look at poisition in x, y and z
	ux, uy, uz		: up vector in x, y and z

DEPENDENCIES
	none
              
RETURN VALUE
	none
                
===========================================================================*/
void xxgluLookAtMatrixFx(int32 *m, int32 ex, int32 ey, int32 ez, int32 atx, int32 aty, int32 atz, int32 ux, int32 uy, int32 uz)
{
	int32 vEye[3];
	int32 vDir[3];
	int32 vUp[3];
	int32 vRight[3];

	//get viewing vector
	vDir[0] = atx - ex;
	vDir[1] = aty - ey;
	vDir[2] = atz - ez;
	xxgluUnitFx(vDir, vDir);

	//get right vector
	vUp[0] = ux;
	vUp[1] = uy;
	vUp[2] = uz;
	xxgluCrossFx(vRight,vDir,vUp);
	xxgluUnitFx(vRight, vRight);

	//get up vector
	xxgluCrossFx(vUp,vRight,vDir);
	xxgluUnitFx(vUp, vUp);

	//other 3 components
	vEye[0] = ex;
	vEye[1] = ey;
	vEye[2] = ez;
	
	*(m+0)  = vRight[0]; 
    *(m+4)  = vRight[1];
	*(m+8)  = vRight[2];
	*(m+12) = -xxgluDotFx(vRight,vEye);
	*(m+1)  = vUp[0]; 
	*(m+5)  = vUp[1];
	*(m+9)  = vUp[2];
	*(m+13) = -xxgluDotFx(vUp,vEye);
	*(m+2)  = -vDir[0]; 
	*(m+6)  = -vDir[1];
	*(m+10) = -vDir[2];
	*(m+14) = xxgluDotFx(vDir,vEye);
	*(m+3)  = 0; 
	*(m+7)  = 0;
	*(m+11) = 0;
	*(m+15) = 1 << Q_FACTOR;
}

#undef X 
#undef Y 
#undef Z 
#undef W   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -