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

📄 projection.c

📁 用brew开发3D的例程
💻 C
📖 第 1 页 / 共 4 页
字号:
/*=================================================================================
FILE:       projection.c

SERVICES:   Functionality for projection tutorials. 
  
DESCRIPTION: This file contains all the initialization, event handlers and
			 other functions specific to the projection tutorials. 
                        
           
         
        Copyright (c) 1999-2003 QUALCOMM Incorporated.
               All Rights Reserved.
            QUALCOMM Proprietary/GTDR
=================================================================================*/

/* include files */
#include "projection.h"

/* local function prototypes */
static boolean TutorI3D_ProjectionFocalHandleEvent(TutorI3D* pMe, AEEEvent event, 
												   uint16 wParam, uint32 dwParam);

static boolean TutorI3D_ProjectionViewDepthHandleEvent(TutorI3D* pMe, AEEEvent event, 
												uint16 wParam, uint32 dwParam);

static boolean TutorI3D_ProjectionScreenMapHanldeEvent(TutorI3D* pMe, AEEEvent event, 
												uint16 wParam, uint32 dwParam);

static boolean TutorI3D_ProjectionClipRectHanldeEvent(TutorI3D* pMe, AEEEvent event, 
											   uint16 wParam, uint32 dwParam);

static boolean OnProjectionFocal(TutorI3D* pMe);
static boolean OnProjectionViewDepth(TutorI3D* pMe);
static boolean OnProjectionScreenMapping(TutorI3D* pMe);
static boolean OnProjectionClipRect(TutorI3D* pMe);


/*===========================================================================

  FUNCTION: TutorI3D_InitProjectionScreen
  
	DESCRIPTION
	  Initializes the projection screen. This function sets up the
	  rectangles, menus, variables, etc. needed for this screen.
	  
	  
	PROTOTYPE:
	  boolean TutorI3D_InitProjectionScreen(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_InitProjectionScreen(TutorI3D* pMe)
{
	AEEMenuColors menuColors;
	
	MEMSET(&menuColors, 0, sizeof(AEEMenuColors));
	
  
   // Set the clipping rectangle for 3D drawing functions
   // while in the sub states. 
   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 sub menus (bottom of screen)
   SETAEERECT (&pMe->menuBottomRect, pMe->screen3DRect.x, DRAWING_AREA_3D_HEIGHT, 
				pMe->di.cxScreen, 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 projection 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);

   // focal length
   IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
					IDS_FOCAL_LENGTH, IDS_FOCAL_LENGTH, NULL, (uint32) NULL);

   // view depth
   IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
					IDS_VIEW_DEPTH, IDS_VIEW_DEPTH, NULL, (uint32) NULL);
	
   // screen mapping
   IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
					IDS_SCREEN_MAPPING, IDS_SCREEN_MAPPING, NULL, (uint32) NULL);

   // clip rect
   IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
					IDS_CLIP_RECT, IDS_CLIP_RECT, 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);


    I3D_SetClipRect(pMe->m_p3D, &pMe->screen3DRect);
	
	return TRUE;

}

/*===========================================================================

  FUNCTION: TutorI3D_DrawProjectionMenu
  
	DESCRIPTION
	    Redraws the projection menu to the screen and sets it active.
		The rect for the menu is pMe->menuBottomRect
	  
	PROTOTYPE:
	  boolean TutorI3D_DrawProjectionMenu(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_DrawProjectionMenu(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_PROJECTION, 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: Projection menu title not displayed");
   }
     
	// allow commands 
	IMENUCTL_SetActive( pMe->m_pSubMenu, TRUE );

	return TRUE;

}


/*===========================================================================

FUNCTION 
	TutorI3D_ProjectionHandleEvent

DESCRIPTION
	This is the Event Handler for the projection screen. All events while in 
	the projection state or a substate of the projection state are processed
	by this event handler. 

PROTOTYPE:
	boolean TutorI3D_ProjectionHandleEvent(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_ProjectionHandleEvent(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_PROJECTION_FOCAL)
	{
		return TutorI3D_ProjectionFocalHandleEvent(pMe, event, wParam, dwParam);
	}
	
	else if(pMe->state == STATE_PROJECTION_VIEWDEPTH)
	{
		return TutorI3D_ProjectionViewDepthHandleEvent(pMe, event, wParam, dwParam);
	}
	
	else if(pMe->state == STATE_PROJECTION_SCREENMAP)
	{
		return TutorI3D_ProjectionScreenMapHanldeEvent(pMe, event, wParam, dwParam);		

	}
	else if(pMe->state == STATE_PROJECTION_CLIPRECT)
	{
		return TutorI3D_ProjectionClipRectHanldeEvent(pMe, event, wParam, dwParam);
	}
	
	else if (pMe->state == STATE_PROJECTION)
	{
		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_FOCAL_LENGTH:
				IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
				pMe->state = STATE_PROJECTION_FOCAL;
				OnProjectionFocal(pMe);
				break;
			
			case IDS_VIEW_DEPTH:
				IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
				pMe->state = STATE_PROJECTION_VIEWDEPTH;
				OnProjectionViewDepth(pMe);
				break;

			case IDS_SCREEN_MAPPING:
				IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
				pMe->state = STATE_PROJECTION_SCREENMAP;
				OnProjectionScreenMapping(pMe);
				break;

			case IDS_CLIP_RECT:
				IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
				pMe->state = STATE_PROJECTION_CLIPRECT;
				OnProjectionClipRect(pMe);
				break;

			default:
				return FALSE;

			}
		return TRUE;

		default:
			return FALSE;


		}

	}

	else
		return FALSE;

}


/*===========================================================================

FUNCTION 
	TutorI3D_ProjectionFocalHandleEvent

DESCRIPTION
	This is the Event Handler for the focal length tutorial. All events while in 
	the projection focal state are processed by this event handler. 

PROTOTYPE:
	static boolean TutorI3D_ProjectionFocalHandleEvent(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_ProjectionFocalHandleEvent(TutorI3D* pMe, AEEEvent event, 
												   uint16 wParam, uint32 dwParam)
{

	uint16 focalLength;

	switch(event)
	{
	
	case EVT_KEY_RELEASE:
		pMe->keyIsPressed = FALSE;
		return TRUE;

	case EVT_KEY_PRESS:
		pMe->lastKeyPresswParam = wParam;
		pMe->lastKeyPressdwParam = dwParam;
		pMe->keyIsPressed = TRUE;
							
		switch(wParam)
		{
	
		// increase focal length
		case AVK_UP:
			I3D_GetFocalLength(pMe->m_p3D, &focalLength);
			
			if(focalLength + 10 < 32768)	// check upper limit
				I3D_SetFocalLength(pMe->m_p3D, focalLength+=10);
			break;

		// decrease focal length
		case AVK_DOWN:
			I3D_GetFocalLength(pMe->m_p3D, &focalLength);
			
			if(focalLength - 10 > 0)		// check lower limit
				I3D_SetFocalLength(pMe->m_p3D, focalLength-=10);				
			break;
	
	
		default:
			return FALSE;
		}
		
		return TRUE;

	case EVT_KEY:
			
		switch(wParam)
		{
			
			// 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_PROJECTION;
				pMe->changeState = TRUE;
				break;
			default:
				return FALSE;
		}

⌨️ 快捷键说明

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