📄 tutori3d.h
字号:
#ifndef TUTORI3D_H
#define TUTORI3D_H
/*=================================================================================
FILE: tutori3d.h
DESCRIPTION: This application is intended to be an interactive tutorial of
the I3D, I3DModel, and I3DUtil APIs. It allows the user to
dynamically change the parameters to the API and view the resulting
changes on the display.
PUBLIC CLASSES: Not Applicable
Copyright (c) 2003 QUALCOMM Incorporated.
All Rights Reserved.
QUALCOMM Proprietary/GTDR
=================================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#if defined(BREW_STATIC_APP)
#include "comdef.h"
#endif
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions
#include "AEEMenu.h" // Menu interface definitions
#include "AEEGraphics.h" // 2D drawing capabilities
#include "AEEStdLib.h" // For helper functions
#include "AEE3D.h" // I3D interface definitions
#include "AEE3DUtil.h" // I3DUtil interface definitions
#include "AEE3DModel.h" // I3DModel interface defintions
#include "tutori3d_res.h" // Resource ID definitions
#include "tutori3d.bid" // Applet ClassID
/*---------------------------------------------------------------------------------
Struct Type Declarations
---------------------------------------------------------------------------------*/
// build options
//#define TUTOR_DEBUG
#define TUTOR_DEBUG1
/* App specific constants */
#define DEGREE 128 //about 11.5 degrees of 360
#define MODEL_SIZE 4096 // 2PI -- original size
#define PI_3D 2048 // PI defined as 2048 in I3D
#define CALLBACK_TIME 10 // milliseconds between frame renders
/* Window dimensions */
// 3D drawing area dimension
#define DRAWING_AREA_3D_UP_LEFT_X 0 // Upper Left x
#define DRAWING_AREA_3D_UP_LEFT_Y 0 // Upper Left y
#define DRAWING_AREA_3D_WIDTH pMe->di.cxScreen // Width
#define DRAWING_AREA_3D_HEIGHT 7*pMe->di.cyScreen/10 // Height
/* Colors */
#define MENU_BACK_CLR CLR_SYS_ITEM //MAKE_RGB(128, 128, 128) // menu backgroud color
#define MENU_TEXT_CLR CLR_BLACK // menu text color
#define ITEM_SELECT_COLOR MAKE_RGB(255, 0, 255) // selected menu item color
#define CLR_API_FRAME CLR_BLACK
#define CLR_API_TEXT CLR_WHITE
#define CLR_API_VAR_TEXT CLR_YELLOW
#define CLR_BLACK MAKE_RGB(0,0,0)
#define CLR_WHITE MAKE_RGB(255,255,255)
#define CLR_YELLOW MAKE_RGB(255,255,0)
#define CLR_RED MAKE_RGB(255,0,0)
#define CLR_BLUE MAKE_RGB(0,0,255)
#define CLR_GREEN MAKE_RGB(0,255,0)
/* enums */
// current state of program
typedef enum
{
STATE_NONE=0, // start-up state
STATE_MAIN, // in main menu
STATE_TRANSFORM, // in transformation window
STATE_TRANSFORM_ROTATE, // doing rotations
STATE_TRANSFORM_TRANSLATE, // doing translations
STATE_PROJECTION, // in projection window
STATE_PROJECTION_FOCAL, // adjusting focal length
STATE_PROJECTION_VIEWDEPTH, // adjusting view depth
STATE_PROJECTION_SCREENMAP, // adjusting screen mapping
STATE_PROJECTION_CLIPRECT, // adjusting clipping rectangle
STATE_LIGHTING, // in lighting window
STATE_LIGHTING_DIRECTION_COLOR, // adjusting direction and color lighting parameters
STATE_LIGHTING_MATERIAL, // adjusting material
STATE_TEXTURES_BLENDING, // in textures/blending mode
STATE_TEXTURES_BLENDING_RENDER, // adjusting render mode and texture properties
STATE_TEXTURES_BLENDING_ALPHA, // adjusting alpha value of object
STATE_TEXTURES_BLENDING_PERSPECTIVE //turn perspective on/off
} TutorI3D_State;
typedef enum
{
AXIS_X=0,
AXIS_Y=1,
AXIS_Z
} AxisType;
typedef enum
{
NEAR_PLANE=0,
FAR_PLANE
} Plane;
typedef enum
{
XSCALE=0,
YSCALE,
XSHIFT,
YSHIFT
} ScreenMapOption;
typedef enum
{
UPPER_LX=0, //upper left x
UPPER_LY, //upper left y
CLIP_WIDTH, //width of clipping rect
CLIP_HEIGHT //height of clipping rect
} ClipRectOption;
typedef enum
{
LIGHT_X=0,
LIGHT_Y,
LIGHT_Z,
LIGHT_RED,
LIGHT_GREEN,
LIGHT_BLUE,
LIGHT_ALPHA
} LightingDirColOption;
typedef enum
{
MATERIAL_RED=0,
MATERIAL_GREEN,
MATERIAL_BLUE,
MATERIAL_ALPHA,
MATERIAL_SHININESS,
MATERIAL_EMISSIVE
} MaterialOption;
typedef enum
{
TEXTURE_WRAP_S,
TEXTURE_WRAP_T
} TextureRenderOption;
typedef enum
{
MODEL_MAN,
MODEL_CUBE,
MODEL_SPHERE,
MODEL_SMOOTH_SPHERE,
MODEL_FIELD,
MODEL_LADYBUG
}DrawModel;
/* Data structures */
// VlistType and ObjType are structures used for creating 3D objects
typedef struct
{
int16 *Vlist;
uint32 VlistSize;
uint32 NumTriangles;
} VlistType;
typedef struct
{
AEE3DPrimitiveType *RMode;
AEE3DTLVertex *Model;
AEE3DPoint *Vertices;
AEE3DPoint16* Norm;
uint32 NumVertices;
VlistType *VlistArray;
uint16 NumVlist;
} ObjType;
// Application data structure. An
// instance of this structure is created when
// an instance of the application is created,
// and this instance is passed back to the
// application event handler along with
// the event.
// NOTE: global and static variables should
// NOT be used in the app, otherwise
// the app will not be position independent
// as BREW apps require.
// Instead, such variables should be
// defined in this structure. Since a
// pointer to this structure is passed
// back to the application with every event,
// you can simulate global and static
// variables using this structure.
typedef struct
{
AEEApplet a;
AEEDeviceInfo di;
IBitmap *m_pIBitmapDDB; //The Device Bitmap. Used for drawing to the
// screen.
// interfaces
I3D *m_p3D; //I3D instance
I3DUtil *m_p3DUtil; //I3DUtil instance.
I3DModel *pModelSmoothSphere; //Smooth sphere model
I3DModel *pModelField; //Field model
I3DModel *pLadyBug; //LadyBug model
IGraphics *m_pGraphics; //IGraphics interface
// menus
IMenuCtl *m_pMainMenu; // Instance for main menu
IMenuCtl *m_pSubMenu; // menu below the main menu (ie. transform menu,etc.)
// representative rectangles
AEERect mainMenuRect; // rectangle representing main menu window
AEERect menuTopRect; // rectangle where API function is written on screen
AEERect screen3DRect; // rectangle representing 3D draw window
AEERect screenAPI3DRect; // rectangle representing 3D draw window while API
// function is displayed at top of screen
AEERect menuBottomRect; // rectangle representing menu draw window
// at the bottom of the screen (for sub menus)
//fonts
IFont *font10; // AEECLSID_FONT_BASIC10, size 10
IFont *font11; // AEECLSID_FONT_BASIC11, size 11
IFont *font11b; // AEECLSID_FONT_BASIC11B, size 11 bold
IFont *oldFontNormal; // stores original AEE_FONT_NORMAL for restoration
IFont *oldFontBold; // stores original AEE_FONT_BOLD for restoration
// flags, states, and misc. variables
int charHeight; // height of character for AEE_FONT_NORMAL
boolean keyIsPressed; // is a key held down?
boolean showHelp; // display/hide help
boolean isSuspended; // is the app suspended?
TutorI3D_State state; //current state of TutorI3D program. This is a very
// important variable as it indicates how events
// should be handled by the main event handler
TutorI3D_State nextState; // the next state to go to (based on the current state,
// and user input.
boolean changeState; // Flag indicating wether we need to change states
// This is set to TRUE when going back to a previous menu,
// because we wait for the current frame to finish rendering
// before going back.
// When going forward in menus, this flag doesn't need
// to be used.
// these store the wParam and dwParam associated with the last
// EVT_KEY_PRESS event
uint16 lastKeyPresswParam;
uint32 lastKeyPressdwParam;
AEECallback cb; // callback data structure.
// 3D related variables
// cube model
ObjType* cubeModel;
//sphere model
ObjType* sphereModel;
//used for the axis model
ObjType* axisModel; // model of 3D axis
AEE3DPoint xarrow; // 3D point representing tip of x axis arrow model
AEE3DPoint yarrow; // 3D point representing tip of y axis arrow model
AEE3DPoint zarrow; // 3D point representing tip of z axis arrow model
AEE3DPoint axisTranslation; // translation vector of axis
AEE3DTransformMatrix axisMtx; // trans. mtx for the axis
AEE3DTransformMatrix initialAxisTransMtx; // initial trans. mtx for the axis
AEE3DTransformMatrix transformMtx; // transformation matrix to apply to the model
// before rendering
AEE3DTransformMatrix initalTransMtx; // the initial transform matrix for an object,
// when it's initialized
DrawModel drawModel; // the current model in use (being drawn)
// below are the tutorial specific static variables
// transform-->rotate static variables
AEE3DRotateType rotateAxis; // axis to rotate about
int xrot; // amount of x rotation
int yrot; // amount of y rotation
int zrot; // amount of z rotation
// transform-->translate static variables
AxisType translateAxis; // axis to translate along
AEE3DPoint translateVector; // direction of translation
// projection-->ViewDepth static variables
Plane viewDepthPlane; // current View Depth plane selected
// projection-->ScreenMapping static variables
ScreenMapOption screenMapOp; // current Screen Map option selected
// projection-->ClipRect static variables
ClipRectOption clipRectOp; // current Clip Rect option selected
// Lighting-->DirectionColor static variables
AEE3DLightType lightTypeOp; // current light type selection , diffuse or specular
LightingDirColOption lightDirColOp; // Direction,Colour option currently selected
// Lighting-->DiffuseMaterial static variables
MaterialOption lightMaterialOp; //current material option selected
// Texture_Blending-->Render static variables
TextureRenderOption textureOp; // current texture operation selected
boolean showTexture; // display current texture on screen?
int16 textureID; // res. ID of current texture
// Texture_Blending-->alpha static variables
boolean alphaEnabled; // is alpha blending enabled?
uint8 alphaValue; // current alpha value for model
// Texture_Blending-->perspective correction static variables
boolean perspectiveCorrEnabled; // is perspective correction enabled?
} TutorI3D;
/* Function pointer types*/
// draw menu function pointer type
typedef boolean (*PFN_DRAWMENUFUNC)(TutorI3D *pMe);
// event handler function pointer type
typedef boolean (*PFN_EVENTHANDLER)(TutorI3D * pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
// draw (model/scence) function pointer type
typedef void (*PFN_DRAWFUNC)(TutorI3D *pMe);
/*---------------------------------------------------------------------------------
Public functions
---------------------------------------------------------------------------------*/
int outputMultiLineStr(TutorI3D* pMe, AECHAR* wstr, int nChar, int x, int y,
int xStart, int maxWidth, int* widthPixels);
int outputColorText(TutorI3D* pMe, AECHAR* text, int8 indexColorChar, int8 nColorChar,
int xText, int yText, int maxWidth, RGBVAL color);
boolean TutorI3D_CloseMenu(IMenuCtl** menu);
void makeAEEClipRectFromRect(AEERect* srcRect, AEEClip* dstClip);
boolean isRenderState(TutorI3D_State state);
void TutorI3D_InitLadyBug(TutorI3D * pMe);
void TutorI3D_InitSmoothSphere(TutorI3D* pMe);
void TutorI3D_InitSphere(TutorI3D* pMe);
void TutorI3D_InitCube(TutorI3D* pMe);
void TutorI3D_InitField(TutorI3D* pMe);
void TutorI3D_InitAxis(TutorI3D* pMe);
void TutorI3D_SetupTutorialWindow(TutorI3D* pMe);
ObjType* TutorI3D_GetModel(TutorI3D* pMe, DrawModel model);
void TutorI3D_SetTopMenuTextValues(TutorI3D* pMe, int* xText, int* yText,
int* maxWidth);
void TutorI3D_SetBottomMenuTextValues(TutorI3D* pMe, int* xText, int* yText,
int* maxWidth);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -