📄 transform.c
字号:
/*=================================================================================
FILE: transform.c
SERVICES: Functionality for transformation tutorials.
DESCRIPTION: This file contains all the initialization, event handlers and
other functions specific to the transformation tutorials.
Copyright (c) 1999-2003 QUALCOMM Incorporated.
All Rights Reserved.
QUALCOMM Proprietary/GTDR
=================================================================================*/
/* include files */
#include "transform.h"
/* local function prototypes */
static boolean TutorI3D_TransformRotateHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam);
static boolean TutorI3D_TransformTranslateHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam);
static boolean OnTransformRotate(TutorI3D* pMe);
static boolean OnTransformTranslate(TutorI3D* pMe);
/*===========================================================================
FUNCTION: TutorI3D_InitTransformScreen
DESCRIPTION
Initializes the transform screen. This function sets up the
rectangles, menus, variables, etc. needed for this screen.
PROTOTYPE:
boolean TutorI3D_InitTransformScreen(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture
DEPENDENCIES
none
RETURN VALUE
TRUE: if initialization was successful
FALSE: if failed
SIDE EFFECTS
none
===========================================================================*/
boolean TutorI3D_InitTransformScreen(TutorI3D* pMe)
{
AEEMenuColors menuColors;
MEMSET(&menuColors, 0, sizeof(AEEMenuColors));
// Set the clipping rectangle for 3D drawing functions
SETAEERECT (&pMe->screen3DRect, DRAWING_AREA_3D_UP_LEFT_X,
DRAWING_AREA_3D_UP_LEFT_Y,
DRAWING_AREA_3D_WIDTH,
DRAWING_AREA_3D_HEIGHT);
// Set the rectangle for the menu at the bottom of the screen.
// start the menu where the 3D draw area ends.
SETAEERECT (&pMe->menuBottomRect, DRAWING_AREA_3D_UP_LEFT_X,
DRAWING_AREA_3D_HEIGHT,
DRAWING_AREA_3D_WIDTH,
pMe->di.cyScreen - DRAWING_AREA_3D_HEIGHT);
// Rectangle where the API function is written at top of the screen
SETAEERECT(&pMe->menuTopRect, pMe->screen3DRect.x, pMe->screen3DRect.y,
pMe->screen3DRect.dx, pMe->charHeight + 3);
// The 3D draw area defined by screen3DRect minus the API name rectangle
// at the top of the screen (menuTopRect).
SETAEERECT(&pMe->screenAPI3DRect, pMe->screen3DRect.x,
pMe->menuTopRect.y + pMe->menuTopRect.dy,
pMe->screen3DRect.dx,
pMe->menuBottomRect.y - (pMe->menuTopRect.y + pMe->menuTopRect.dy ));
// create transform menu instance
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_SOFTKEYCTL,
(void **)&pMe->m_pSubMenu) != SUCCESS)
{
return FALSE;
}
IMENUCTL_SetActive( pMe->m_pSubMenu, FALSE );
IMENUCTL_Reset(pMe->m_pSubMenu);
IMENUCTL_DeleteAll(pMe->m_pSubMenu);
IMENUCTL_SetRect (pMe->m_pSubMenu, &pMe->menuBottomRect);
// Rotate
IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
IDS_ROTATE, IDS_ROTATE, NULL, (uint32) NULL);
// Translate
IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
IDS_TRANSLATE, IDS_TRANSLATE, NULL, (uint32) NULL);
// yellow on black for selected items
menuColors.cSelBack = CLR_BLACK;
menuColors.cSelText = CLR_YELLOW;
menuColors.wMask = MC_SEL_BACK | MC_SEL_TEXT;
IMENUCTL_SetColors(pMe->m_pSubMenu, &menuColors);
// 3D Drawing should only be in the specified rect
I3D_SetClipRect(pMe->m_p3D, &pMe->screen3DRect);
pMe->xrot = 0;
pMe->yrot = 0;
pMe->zrot = 0;
pMe->translateVector.x = 0;
pMe->translateVector.y = 0;
pMe->translateVector.z = 0;
return TRUE;
}
/*===========================================================================
FUNCTION: TutorI3D_DrawTransformMenu
DESCRIPTION
Redraws the transform menu to the screen and sets it active.
The rect for the menu is pMe->menuBottomRect
PROTOTYPE:
boolean TutorI3D_DrawTransformMenu(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture
DEPENDENCIES
none
RETURN VALUE
TRUE: if menu was redrawn
FALSE: if there was an error
SIDE EFFECTS
none
===========================================================================*/
boolean TutorI3D_DrawTransformMenu(TutorI3D* pMe)
{
AECHAR szBuf[30];
// Fill back menu background with same color as unselected menu item background
IDISPLAY_FillRect(pMe->a.m_pIDisplay, &pMe->menuBottomRect, CLR_SYS_ITEM);
if(!IMENUCTL_Redraw(pMe->m_pSubMenu))
{
return FALSE;
}
// Seperate from draw area with a line
IDISPLAY_DrawHLine(pMe->a.m_pIDisplay, pMe->menuBottomRect.x, pMe->menuBottomRect.y,
pMe->menuBottomRect.dx);
// Draw title
if(ISHELL_LoadResString(pMe->a.m_pIShell, TUTORI3D_RES_FILE, IDS_TRANSFORMATIONS, szBuf,
sizeof(szBuf)) == 0)
{
return FALSE;
}
if(IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, szBuf,
-1, (pMe->menuBottomRect.x + pMe->menuBottomRect.dx)/2,
pMe->menuBottomRect.y + 3, NULL,
IDF_ALIGN_CENTER | IDF_TEXT_TRANSPARENT) != SUCCESS)
{
DBGPRINTF("Error: Transform menu title not displayed");
}
// allow commands
IMENUCTL_SetActive( pMe->m_pSubMenu, TRUE );
return TRUE;
}
/*===========================================================================
FUNCTION TutorI3D_TransformHandleEvent
DESCRIPTION
This is the Event Handler for the transform screen. All events while in
the transform state or a substate of the transform state are processed
by this event handler.
PROTOTYPE:
boolean TutorI3D_TransformHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam)
PARAMETERS:
pMe [In] : Pointer to TutorI3D sturcture
ecode [In]: Specifies the Event sent to the event handler
wParam, dwParam [In]: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the event handler has processed the event
FALSE: If the event handler did not process the event
SIDE EFFECTS
none
===========================================================================*/
boolean TutorI3D_TransformHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam)
{
/* Send event to appropriate sub event handler or handle event here, depending
on the current state. */
if(pMe->state == STATE_TRANSFORM_ROTATE)
{
return TutorI3D_TransformRotateHandleEvent(pMe, event, wParam, dwParam);
}
else if(pMe->state == STATE_TRANSFORM_TRANSLATE)
{
return TutorI3D_TransformTranslateHandleEvent(pMe, event, wParam, dwParam);
}
else if (pMe->state == STATE_TRANSFORM)
{
switch(event)
{
case EVT_KEY:
switch(wParam)
{
case AVK_CLR:
/* The User has requested to go back to the main menu.
First: Close the current menu (Free associated memory)
Second: set the next state we're going to.
Third: set the changeState flag here to indicate
we're going back a state. Once the current 3D frame
has finished rendering (ie. when we receive the
AEE3D_EVENT_FRAME_UPDATE_DISPLAY), we actually
change states.
The reason we do this is because we don't want to
change states immediately when the user
requests to go back a state. This is because we're going
to be drawing to the frame buffer (menus, etc.) when going
back a state. So what we do is, we wait for the current 3D
frame to finish rendering first, then switch states when we know
it's ok to draw to the frame buffer.
When going forward states, the menus, text, etc. are drawn either
before the rendering for the frame begins
(ie. before I3D_StartFrame() is called) or after it has completed.
(ie. in the respective ManipulateBuf functions).
*/
TutorI3D_CloseMenu(&pMe->m_pSubMenu);
pMe->nextState = STATE_MAIN;
pMe->changeState = TRUE;
break;
default:
return IMENUCTL_HandleEvent(pMe->m_pSubMenu, EVT_KEY,
wParam, dwParam);
}
return TRUE;
case EVT_COMMAND:
switch(wParam)
{
case IDS_ROTATE:
// about to go forward one state, so deactivate the current menu,
// change the current state
IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
pMe->state = STATE_TRANSFORM_ROTATE;
OnTransformRotate(pMe);
break;
case IDS_TRANSLATE:
// about to change states, so deactivate the current menu
IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
pMe->state = STATE_TRANSFORM_TRANSLATE;
OnTransformTranslate(pMe);
break;
default:
return FALSE;
}
return TRUE;
default:
return FALSE;
}
}
else
return FALSE;
}
/*===========================================================================
FUNCTION TutorI3D_TransformRotateHandleEvent
DESCRIPTION
This is the Event Handler for the rotate tutorial. All events while in
the transform rotate state are processed by this event handler.
PROTOTYPE:
static boolean TutorI3D_TransformRotateHandleEvent(TutorI3D* pMe,
AEEEvent event,
uint16 wParam,
uint32 dwParam)
PARAMETERS:
pMe [In] : Pointer to TutorI3D sturcture
ecode [In]: Specifies the Event sent to the event handler
wParam, dwParam [In]: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the event handler has processed the event
FALSE: If the event handler did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean TutorI3D_TransformRotateHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam)
{
AEE3DTransformMatrix m1;
switch(event)
{
case EVT_KEY_RELEASE:
pMe->keyIsPressed = FALSE;
return TRUE;
case EVT_KEY_PRESS:
{
// NOTE: On target, EVT_KEY_PRESS is sent only once
// per key press, even if the key is held down. When the
// key is released, EVT_KEY_RELEASE is sent. Here we set a flag,
// to indicate a key is pressed, and we unset it once the
// key is released.
pMe->lastKeyPresswParam = wParam;
pMe->lastKeyPressdwParam = dwParam;
pMe->keyIsPressed = TRUE;
if(wParam == AVK_UP || wParam == AVK_DOWN)
{
boolean doRotation = TRUE;
int rotateUnit = (wParam == AVK_UP ? ROTATE_UNIT : -ROTATE_UNIT);
if(pMe->rotateAxis == AEE3D_ROTATE_X)
{
pMe->xrot+=rotateUnit;
if(pMe->xrot > 4096)
{
pMe->xrot = 4096;
doRotation = FALSE;
}
else if(pMe->xrot < -4096)
{
pMe->xrot = -4096;
doRotation = FALSE;
}
}
else if (pMe->rotateAxis == AEE3D_ROTATE_Y)
{
pMe->yrot+=rotateUnit;
if(pMe->yrot > 4096)
{
pMe->yrot = 4096;
doRotation = FALSE;
}
else if(pMe->yrot < -4096)
{
pMe->yrot = -4096;
doRotation = FALSE;
}
}
else if (pMe->rotateAxis == AEE3D_ROTATE_Z)
{
pMe->zrot+=rotateUnit;
if(pMe->zrot > 4096)
{
pMe->zrot = 4096;
doRotation = FALSE;
}
else if(pMe->zrot < -4096)
{
pMe->zrot = -4096;
doRotation = FALSE;
}
}
if(doRotation)
{
I3DUtil_GetRotateMatrix(pMe->m_p3DUtil, rotateUnit, &m1, pMe->rotateAxis);
I3DUtil_MatrixMultiply(pMe->m_p3DUtil, &pMe->transformMtx, &m1);
I3DUtil_MatrixMultiply(pMe->m_p3DUtil, &pMe->axisMtx, &m1);
}
return TRUE;
}
else
return FALSE; // key wasn't AVK_UP or AVK_DOWN
} // end case EVT_KEY_PRESS
case EVT_KEY:
switch(wParam)
{
// pick rotation axis: x
case AVK_1:
pMe->rotateAxis = AEE3D_ROTATE_X;
break;
// pick rotation axis: y
case AVK_2:
pMe->rotateAxis = AEE3D_ROTATE_Y;
break;
// pick rotation axis : z
case AVK_3:
pMe->rotateAxis = AEE3D_ROTATE_Z;
break;
// Show/Hide Commands
case AVK_POUND:
if(pMe->showHelp == FALSE)
pMe->showHelp = TRUE;
else if(pMe->showHelp == TRUE)
pMe->showHelp = FALSE;
break;
case AVK_CLR:
/*
User request to return to previous state. Set the next state,
and a flag, and wait until the current frame finishes rendering
before switching states. For information on why we do this,
read the comment in the parent event handler for the AVK_CLR event.
*/
pMe->nextState = STATE_TRANSFORM;
pMe->changeState = TRUE;
break;
default:
return FALSE;
}
return TRUE;
case EVT_COMMAND:
return TRUE;
default:
return FALSE;
}
}
/*===========================================================================
FUNCTION TutorI3D_TransformTranslateHandleEvent
DESCRIPTION
This is the Event Handler for the translate tutorial. All events while in
the transform translate state are processed by this event handler.
PROTOTYPE:
static boolean TutorI3D_TransformTranslateHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam)
PARAMETERS:
pMe [In] : Pointer to TutorI3D sturcture
ecode [In]: Specifies the Event sent to the event handler
wParam, dwParam [In]: Event specific data.
DEPENDENCIES
none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -