?? our_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_1,
MATERIAL_point_1P,
MATERIAL_point_3T,
MATERIAL_Triangle_1,
MATERIAL_Triangle_T,
//MATERIAL_obj,
MATERIAL_wire,
MATERIAL_bmp,
};
#define MATERIAL_MASK (0x0f)
#define MATERIAL_oneside (0<<5)
#define MATERIAL_towside (1<<5)
#define MATERIAL_cmp_n (0<<6)
#define MATERIAL_cmp_z (1<<6)
#define MATERIAL_pre_z (1<<30)
enum
{
OBJ_R_XYZ,
OBJ_R_XYZ_ADD,
};
//================================================================================================
#define OUR_RGB32_2_16(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_RGB_MASK500 (0xf800) //
#define OUR_RGB_MASK060 (0x7E0) //
#define OUR_RGB_MASK005 (0x1f) //
#define OUR_RGB_MASK5000 (0x1f0000)//
#define OUR_RGB_MASK8000 (0xff000000)
#define OUR_RGB_MASK0500 (0x00f80000)
#define OUR_RGB_MASK0060 (0x0000fc00)
#define OUR_RGB_MASK0005 (0x000000f8)
#define OUR_RGB32_A(a,r,g,b) (b + ((g ) << 8) + ((r) << 16)+ ((a) <<24))
#define OUR_RGB32(r,g,b) (b + ((g ) << 8) + ((r) << 16))
#define OUR_RGB16_A(a,r,g,b) (((b & 0xf8 )>>3) + ((g & 0xfc) << 3) + ((r & 0xf8) << 8))
#define OUR_RGB16(r,g,b) (((b & 0xf8 )>>3) + ((g & 0xfc) << 3) + ((r & 0xf8) << 8))
#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)
//---------------------------------------------------
//12+12+12+4=40B
typedef struct OUR_3D_TRAG_TYP
{
// UINT state_attr; // state information
/* union
{
UCHAR c[4];
CLR clor;
}CC;
union
{
UCHAR c[4];
CLR clor;
}CC_work;
*/
FIX_POINT3D NOR_P;
UINT p1,p2,p3; // the indices into the vertex list
UINT uv1,uv2,uv3; // the UV axi
UINT bmp_index; // the UV axi
} OUR_3D_TRAG, *OUR_3D_TRAG_PTR;
//---------------------------------------------------
typedef struct OUR_3D_POINT_TYP
{
FIXP16 x,y,z;
UINT state_attr; // state information
CLR color; // color of polygon
} OUR_3D_POINT, *OUR_3D_POINT_PTR;
//---------------------------------------------------//48+12+36 =96
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
UINT width; //half of the screem width
UINT hight; //half of the screem hight
UINT focus; //the focus of the camera
FIX_MATRIX_3X3 mrot; //the
} OUR_3D_CAM,*OUR_3D_CAM_PTR;
//---------------------------------------------------//45*4=180
typedef struct
{
UINT state_attr; // state information
int x_rot,y_rot,z_rot; //rotation
UINT 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
UINT material; //
FIX_POINT3D pos; //
FIXP16 scale_x; //the obj can scale
FIXP16 scale_x_i; //the obj can scale
FIXP16 scale_y; //the obj can scale
FIXP16 scale_y_i; //the obj can scale
FIXP16 scale_z; //the obj can scale
FIXP16 scale_z_i; //the obj can scale
UINT point_num; //how many points the obj have
UINT 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; //
CLR* clor_work; //
OUR_BMP_INFO** bmp_info;
UINT* uv; //for the fu
UINT* pPoints_changed;//
UINT* pTriangle_changed;//
UINT pTriangle_num_changed;//
}OUR_3D_OBJ,*OUR_3D_OBJ_PTR;
//---------------------------------------------------//36
typedef struct OUR_3D_LIT
{
struct OUR_3D_LIT* lit_next; //point to the next light
UINT 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];
//UINT 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, // 1300t
FIXP16 y,
FIXP16 z,
OUR_3D_OBJ_PTR obj,
int obj_r_style);// output
//--------------------------------------------------------------------
int OUR_OBJ_INIT16( OUR_3D_OBJ_PTR obj,
FIX_POINT3D_PTR pos,
FIXP16 scale,
CLR clor,
FIX_POINT3D_PTR pPoint,
UINT point_num,
OUR_3D_TRAG_PTR pTriagle,
UINT triagle_num,
UINT* pPoints_changed,
UINT* pTriangle_changed
);
int OUR_OBJ_INIT32( OUR_3D_OBJ_PTR obj,
UINT material,
FIX_POINT3D_PTR pos,
FIXP16 scale,
UINT point_num,
UINT 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,
UINT* pPoints_changed,
UINT* pTriangle_changed
);
int OUR_OBJ_SET_SCALE_X( OUR_3D_OBJ_PTR obj, FIXP16 scale);
int OUR_OBJ_SET_SCALE_Y( OUR_3D_OBJ_PTR obj, FIXP16 scale);
int OUR_OBJ_SET_SCALE_Z( OUR_3D_OBJ_PTR obj, FIXP16 scale);
int OUR_LIT_INIT16(OUR_3D_LIT_PTR lit,FIX_POINT3D_PTR pos_dir,CLR clr,UINT sta);
int OUR_LIT_INIT32(OUR_3D_LIT_PTR lit,FIX_POINT3D_PTR pos_dir,CLR clr,UINT sta);
int OUR_LIT_INSERT(OUR_3D_LIT_PTR *_lit_list,OUR_3D_LIT_PTR lit);
//--------------------------------------------------------------------
void OUR_3Dengin_start(void);
void OUR_3Dengin_SET_LCD_B(int w,int h);
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 int OUR_D_screem_w;
extern int OUR_D_screem_h;
//================================================================================================
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -