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

📄 our_3d.h

📁 MTK上3D特效的一些开源代码
💻 H
字号:
/**************************************************************************
Copyright (C) jianbo miao Corporation.  All Rights Released.
this is a 3d engin named our_3d_engin.
our_3d_engin feature:
1:there is no float.
2:it do the 3d things all by softwear.
3:base on 1 and 2 , it can execution on arm which have no 3d hardwear accelerate.

if you have any  suggestion or question,pls contact with me
mail:miaojb@126.com
msn:miaojianbo@hotmail.com
qq:30209027

2008/01/01
***************************************************************************/


#ifndef OUR_3D
#define OUR_3D

//================================================================================================
//================================================================================================

#include "our_cpu.h"
#include "our_math.h"
#include "our_bmp.h"

#define SCALE_1 (10)
//--------------------OBJ state----------------------
#define OBJ_CHANGED 1

//--------------------LIT state----------------------
#define LIT_point               1
#define LIT_parallel            2
#define LIT_condition		3
//--------------------material ----------------------
enum
{
    MATERIAL_point,
    MATERIAL_Triangle,
    MATERIAL_obj,
    MATERIAL_wire,
    MATERIAL_bmp,
};

#define MATERIAL_oneside		(0<<5)
#define MATERIAL_towside   	(1<<5)

#define MATERIAL_cmp_n       	(0<<6)
#define MATERIAL_cmp_z       	(1<<6)
//================================================================================================

#define OUR_RGB32_2_16(clr) 	{clr=(((clr & 0xff )>>3) + ((clr& 0xfc00) >> 5) + ((clr & 0xf80000) >>8));}


//RGB Masks for 5.6.5 mode
//DDPF_RGB  16 R: 0x0000F800  
//             G: 0x000007E0  
//             B: 0x0000001F  

//RGB Masks for 5.5.5 mode
//DDPF_RGB  16 R: 0x00007C00  
//             G: 0x000003E0  
//             B: 0x0000001F  
#define OUR_RGB16BIT565(r,g,b) 	(((b & 0xf8 )>>3) + ((g & 0xfc) << 3) + ((r & 0xf8) << 8))


//LIGHT Masks for 171717 mode
//DDPF_RGB  16 G: 0x007E0000 
//             R: 0x0000f800  
//             B: 0x0000001F  
#define OUR_LIGHT_CLR565(r,g,b)	(((b & 0xf8)>>3) + ((g & 0xfc) << 19) + ((r & 0xf8) << 8))
#define OUR_LIGHT_MASK565		(0x1f  + 0x7E00000+ 0xf800)	//bgr

#define OUR_LIGHT_MASK500		(0xf800)	//
#define OUR_LIGHT_MASK060		(0x7E0)	//
#define OUR_LIGHT_MASK005		(0x1f)	//
#define OUR_LIGHT_MASK5000		(0x1f0000)//

#define OUR_RGB32(a,r,g,b) 	        (b  + ((g ) << 8) + ((r) << 16)+ ((a) <<24))
#define OUR_RGB_MASK8000             (0xff000000)
#define OUR_RGB_MASK0800             (0x00ff0000)
#define OUR_RGB_MASK0080             (0x0000ff00)
#define OUR_RGB_MASK0008             (0x000000ff)
#define OUR_RGB_MASK0088             (0x00000fff)
#define OUR_RGB_MASK8800             (0x0fff0000)


#define OUR_UV_MASK8800               	(0xffff0000)
#define OUR_UV_MASK0088            	(0x0000ffff)

#define OUR_RGB_MASK7000          	(0xfe000000)
#define OUR_RGB_MASK0700             (0x00fe0000)
#define OUR_RGB_MASK0070             (0x0000fe00)
#define OUR_RGB_MASK0007             (0x000000fe)
#define OUR_RGB_MASK7070             (0xfe00fe00)
#define OUR_RGB_MASK0707             (0x00fe00fe)
#define OUR_RGB_MASK7777             (0xfefefefe)
//---------------------------------------------------
typedef struct OUR_3D_TRAG_TYP
{
	uint32 state_attr;			// state information
	union
        {
		UCHAR              c[4];
		CLR			 clor;
        }CC;
	union
        {
		UCHAR              c[4];
		CLR			 clor;
        }CC_work;

	FIX_POINT3D NOR_P;
	uint32 p1,p2,p3;			// the indices into the vertex list
	uint32 uv1,uv2,uv3;		// the UV axi

} OUR_3D_TRAG, *OUR_3D_TRAG_PTR;

//---------------------------------------------------
typedef struct OUR_3D_POINT_TYP
{
    FIXP16      	x,y,z;
    uint32          state_attr; 		// state information
    CLR 		color;			// color of polygon
} OUR_3D_POINT, *OUR_3D_POINT_PTR;
//---------------------------------------------------
typedef struct 
{
    FIX_POINT3D     	pos;			//the postion of camera in the word
    FIX_POINT3D     	pos_obj;		//the postion of camera in the obj word
    FIX_POINT3D     	target;		//the camera point to the the target
    FIX_POINT3D     	up;			//the direction of the head of camera
    uint32                  width;		//half of the screem width
    uint32                  hight;  		//half of the screem hight
    uint32                  focus;  		//the focus of the camera
    FIX_MATRIX_3X3 mrot;		//the 
} OUR_3D_CAM,*OUR_3D_CAM_PTR;
//---------------------------------------------------
typedef struct 
{
	char 			state_attr;		// state information
	sint32		x_rot,y_rot,z_rot;	//rotation
	uint32		max_radius;		//the max radius
	FIX_MATRIX_3X3 	mrot;		//the obj word to the word
	FIX_MATRIX_3X3 	mrot_i;		//use for camera and lights
	FIXP16 			scale_i;		//the obj can scale
    
	uint32		material;			//
	FIX_POINT3D 	pos;				//
	FIXP16 		scale;			//the obj can scale
	uint32		point_num;		//how many points the obj have
	uint32		triangle_num;		//how many triagles the obj have
	FIX_POINT3D_PTR 	pPoints;		//
	FIX_POINT3D_PTR 	pPoint_nor;	//
	FIX_POINT3D_PTR 	pPoints_work;//
	OUR_3D_TRAG_PTR 	pTriangle;	//
        union
        {
		UCHAR              c[4];
		CLR			 clor;
        }CC;
	CLR*			clor_work;	//
	OUR_BMP_INFO*     bmp_info;
	uint32*			pPoints_changed;//
	uint32*			pTriangle_changed;//
	
}OUR_3D_OBJ,*OUR_3D_OBJ_PTR;


//---------------------------------------------------
typedef struct OUR_3D_LIT
{
	struct OUR_3D_LIT* 	lit_next;	//point to the next light
	uint32 		state_attr;		// state information
	FIX_POINT3D 	pos_dir;			//the position of the point light, or the direct of the pellar light
	FIX_POINT3D 	pos_dir_obj;		//the position of the light in the obj word 
	CLR			clor[2];
	//uint32	max_radius;		//for point light,maybe not use in this vis
} OUR_3D_LIT,*OUR_3D_LIT_PTR;



//----------------------------------------------------------------------
void OUR_Build_XYZ_Rotation_MATRIX3X3(	FIXP16 theta_x, // euler angles
							                          		FIXP16 theta_y, 
							                              		FIXP16 theta_z,
							                              		FIX_MATRIX_3X3_PTR mrot) ;// output
//time:							       
//----------------------------------------------------------------------
void OUR_POINT_CHANGE_OBJ(OUR_3D_OBJ_PTR obj,OUR_3D_CAM_PTR cam);//

//----------------------------------------------------------------------
void OUR_INIT_Triangle_Normal(	OUR_3D_OBJ_PTR obj );
//----------------------------------------------------------------------
void OUR_INIT_Point_Normal(	OUR_3D_OBJ_PTR obj );
//----------------------------------------------------------------------

void OUR_BACHFACE_OBJ_LIT16(	OUR_3D_OBJ_PTR	obj,//100*n t  需要优化
											OUR_3D_CAM_PTR	cam,
											OUR_3D_LIT_PTR 	lit);
//---------------------------------------------------------------------
void OUR_BACHFACE_OBJ_LIT32(	OUR_3D_OBJ_PTR	obj,//100*n t  需要优化
											OUR_3D_CAM_PTR	cam,
											OUR_3D_LIT_PTR 	lit);
void OUR_Build_CAM_Rotation_MATRIX3X3(OUR_3D_CAM_PTR cam);
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void OUR_XYZ_Rotation_OBJ(	FIXP16 x, // euler angles
							FIXP16 y, 
							FIXP16 z,
							OUR_3D_OBJ_PTR obj); // output 

//--------------------------------------------------------------------
int OUR_OBJ_INIT16(	OUR_3D_OBJ_PTR 	obj,		
					FIX_POINT3D_PTR	pos,
					FIXP16			scale,					
					CLR 				clor,
					FIX_POINT3D_PTR	pPoint,	
					uint32 			point_num,
					OUR_3D_TRAG_PTR	pTriagle,	
					uint32 			triagle_num,
					uint32*				pPoints_changed,
					uint32*				pTriangle_changed
					);
int OUR_OBJ_INIT32(	OUR_3D_OBJ_PTR 	obj,	
				   uint32			material,
				   FIX_POINT3D_PTR	pos,
				   FIXP16			scale,		
				   uint32 			point_num,	
				   uint32 			triagle_num,			
				   FIX_POINT3D_PTR	pPoint,
				   FIX_POINT3D_PTR	pPoint_nor,
				   FIX_POINT3D_PTR	pPoint_work,
				   OUR_3D_TRAG_PTR	pTriagle,				
				   CLR 				clor,		
				   CLR* 				clor_work,
				   OUR_BMP_INFO*     	bmp_info,
				   uint32*				pPoints_changed,
				   uint32*				pTriangle_changed
				   );
int OUR_LIT_INIT16(OUR_3D_LIT_PTR lit,FIX_POINT3D_PTR pos_dir,CLR clr,uint32 sta);
int OUR_LIT_INIT32(OUR_3D_LIT_PTR lit,FIX_POINT3D_PTR pos_dir,CLR clr,uint32 sta);
int OUR_LIT_INSERT(OUR_3D_LIT_PTR *_lit_list,OUR_3D_LIT_PTR lit);
//--------------------------------------------------------------------
void OUR_3Dengin_start(void);
void OUR_new_frame_start(void);
//--------------------------------------------------------------------

extern UINT OUR_D_FrameTH;
extern UINT OUR_D_point_changed_num;
extern UINT OUR_D_triangle_drawed_num;
extern UINT OUR_D_screem_w;
extern UINT OUR_D_screem_h;

//================================================================================================
#endif

⌨️ 快捷键说明

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