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

📄 transform.c

📁 用brew开发3D的例程
💻 C
📖 第 1 页 / 共 2 页
字号:

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_TransformTranslateHandleEvent(TutorI3D* pMe, AEEEvent event, 
												uint16 wParam, uint32 dwParam)
{

		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 translation along appropriate axis
			case AVK_UP:
				
				if(pMe->translateAxis == AXIS_X)
				{
					pMe->translateVector.x += TRANSLATE_UNIT << 16;
					pMe->axisTranslation.x += TRANSLATE_UNIT << 16;
				}
				else if (pMe->translateAxis == AXIS_Y)
				{
					pMe->translateVector.y += TRANSLATE_UNIT << 16;
					pMe->axisTranslation.y += TRANSLATE_UNIT << 16;
				}
				else if (pMe->translateAxis == AXIS_Z)
				{
					pMe->translateVector.z += TRANSLATE_UNIT << 16;
					pMe->axisTranslation.z += TRANSLATE_UNIT << 16;
				}

				I3DUtil_SetTranslationMatrix(pMe->m_p3DUtil,&pMe->translateVector,&pMe->transformMtx);
				I3DUtil_SetTranslationMatrix(pMe->m_p3DUtil,&pMe->axisTranslation,&pMe->axisMtx);
				break;

			// decrease translation
			case AVK_DOWN:

				if(pMe->translateAxis == AXIS_X)
				{
					pMe->translateVector.x -= TRANSLATE_UNIT << 16;
					pMe->axisTranslation.x -= TRANSLATE_UNIT << 16;
				}
				else if (pMe->translateAxis == AXIS_Y)
				{
					pMe->translateVector.y -= TRANSLATE_UNIT << 16;
					pMe->axisTranslation.y -= TRANSLATE_UNIT << 16;
				}
				else if (pMe->translateAxis == AXIS_Z)
				{
					pMe->translateVector.z -= TRANSLATE_UNIT << 16;
					pMe->axisTranslation.z -= TRANSLATE_UNIT << 16;
				}

				I3DUtil_SetTranslationMatrix(pMe->m_p3DUtil,&pMe->translateVector,&pMe->transformMtx);
				I3DUtil_SetTranslationMatrix(pMe->m_p3DUtil,&pMe->axisTranslation,&pMe->axisMtx);
				break;

			default:
				return FALSE;
			}
			return TRUE;

		
		case EVT_KEY:
				
			switch(wParam)
			{
			
			case AVK_1:
				pMe->translateAxis = AXIS_X;
				break;
			
			case AVK_2:
				pMe->translateAxis = AXIS_Y;
				break;
			
			case AVK_3:
				pMe->translateAxis = AXIS_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 OnTransformRotate

DESCRIPTION
	 This function is called when the Rotate menu item is selected. 
	 Anything to do when first entering this tutorial should be done here, 
	 ie. tutorial specific initializations. 

PROTOTYPE:
	static boolean OnTransformRotate(TutorI3D* pMe)

PARAMETERS:
	pMe [In] : Pointer to TutorI3D sturcture
	
DEPENDENCIES
  none

RETURN VALUE
  TRUE: If succeded
  FALSE: If there was an error

SIDE EFFECTS
  none
===========================================================================*/
static boolean OnTransformRotate(TutorI3D* pMe)
{
	return TRUE;
}

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

FUNCTION OnTransformTranslate

DESCRIPTION
	 This function is called when the Translate menu item is selected. 
	 Anything to do when first entering this tutorial should be done here, 
	 ie. tutorial specific initializations. 

PROTOTYPE:
	static boolean OnTransformTranslate(TutorI3D* pMe)

PARAMETERS:
	pMe [In] : Pointer to TutorI3D sturcture
	
DEPENDENCIES
  none

RETURN VALUE
  TRUE: If succeded
  FALSE: If there was an error

SIDE EFFECTS
  none
===========================================================================*/
static boolean OnTransformTranslate(TutorI3D* pMe)
{
	return TRUE;
}

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

  FUNCTION: TransformRotateManipulateBuf
  
	DESCRIPTION
	   This function adds text and 2D graphics to the frame buffer after
	   3D frame render is complete for the rotation tutorial.
	  
	PROTOTYPE:
	  void TransformRotateManipulateBuf(TutorI3D* pMe)
		
	PARAMETERS:
	  pMe: [in]: Pointer to TutorI3D sturcture
	  		  
	DEPENDENCIES
	  none
				  
	RETURN VALUE
	  none
					
	SIDE EFFECTS
	  none
===========================================================================*/
void TransformRotateManipulateBuf(TutorI3D* pMe)
{

	AECHAR szBuf[50];
	char chBuf[50];
	RGBVAL rgb=0;
	RGBVAL rgb1=0;
	int textWidth;
	int ang;
	int nLine=0;	// # of lines used to output text
	int maxWidth;
	int xText,yText;
	
	if(!pMe)
		return;

	TutorI3D_SetTopMenuTextValues(pMe, &xText, &yText, &maxWidth);

	TutorI3D_SetupTutorialWindow(pMe);
					
	rgb = IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, CLR_API_TEXT);
	

	SPRINTF(chBuf, "I3DUtil_GetRotateMatrix(m,ang,axis)" );
	STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
	outputColorText(pMe, szBuf, 26, 8, xText, yText, 
					maxWidth, CLR_API_VAR_TEXT);

	IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, MENU_TEXT_CLR );

	// Now draw the tutorial information in the bottom menu. 
	// First set the initial output point for the text and maxWidth. 
	TutorI3D_SetBottomMenuTextValues(pMe,&xText,&yText,&maxWidth);

	
	if(pMe->rotateAxis == AEE3D_ROTATE_X)
	{
		rgb1 = IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, ITEM_SELECT_COLOR);
	}
	
	ang = (180 * pMe->xrot) / 2048;

	SPRINTF(chBuf, "x angle:  %d = %d deg", pMe->xrot, ang );
	STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
	nLine += outputMultiLineStr(pMe, szBuf, -1, xText, yText, -1, maxWidth,
					&textWidth );

	

	if(pMe->rotateAxis == AEE3D_ROTATE_X)
	{
		IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb1);
	}
	else if(pMe->rotateAxis == AEE3D_ROTATE_Y)
	{
		rgb1 = IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, ITEM_SELECT_COLOR);
	}
	
	ang = (180 * pMe->yrot) / 2048;
	
	SPRINTF(chBuf, "y angle:  %d = %d deg", pMe->yrot, ang );
	STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
	nLine += outputMultiLineStr(pMe, szBuf, -1, xText, yText + nLine*pMe->charHeight, 
					   -1, maxWidth, &textWidth );
	
	if(pMe->rotateAxis == AEE3D_ROTATE_Y)
	{
		IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb1);
	}
	else if(pMe->rotateAxis == AEE3D_ROTATE_Z)
	{
		rgb1 = IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, ITEM_SELECT_COLOR);
	}

	ang = (180 * pMe->zrot) / 2048;

	SPRINTF(chBuf, "z angle:  %d = %d deg", pMe->zrot, ang );
	STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
	nLine += outputMultiLineStr(pMe, szBuf, -1, xText, yText + nLine*pMe->charHeight, 
					   -1, maxWidth, &textWidth );
	
	if(pMe->rotateAxis == AEE3D_ROTATE_Z)
	{
		IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb1);
	}

	IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, CLR_BLACK);

	STR_TO_WSTR("(Note: Pi = 2048)", szBuf, sizeof(szBuf));
	IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, szBuf,
					  -1, 0, pMe->menuBottomRect.y + pMe->menuBottomRect.dy -
					  2*pMe->charHeight, NULL, IDF_ALIGN_RIGHT | IDF_TEXT_TRANSPARENT);


	STR_TO_WSTR("Press '#' for Help", szBuf, sizeof(szBuf));
	IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, szBuf,
					  -1, 0, 0, NULL, IDF_ALIGN_CENTER | IDF_ALIGN_BOTTOM | 
					  IDF_TEXT_TRANSPARENT);

	
	if(pMe->showHelp)
	{
		IDISPLAY_EraseRect(pMe->a.m_pIDisplay, &pMe->screenAPI3DRect);

		nLine = 0;
		xText = pMe->menuTopRect.x + 1;
		yText = pMe->menuTopRect.y + pMe->menuTopRect.dy + 5;


	
		STR_TO_WSTR("Up: +", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText+nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

		STR_TO_WSTR("Down: -", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText+nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

		STR_TO_WSTR("1: x axis", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText + nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);
		
		STR_TO_WSTR("2: y axis", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText + nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

		STR_TO_WSTR("3: z axis", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText + nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

		STR_TO_WSTR("#: show/hide help", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText + nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

	}

	IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb);
	
}


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

  FUNCTION: TransformTranslateManipulateBuf
  
	DESCRIPTION
	   This function adds text and 2D graphics to the frame buffer after
	   3D frame render is complete for the translation tutorial.
	  
	PROTOTYPE:
	  void TransformTranslateManipulateBuf(TutorI3D* pMe)
		
	PARAMETERS:
	  pMe: [in]: Pointer to TutorI3D sturcture
	  		  
	DEPENDENCIES
	  none
				  
	RETURN VALUE
	  none
					
	SIDE EFFECTS
	  none
===========================================================================*/
void TransformTranslateManipulateBuf(TutorI3D* pMe)
{

	AECHAR szBuf[50];
	char chBuf[50];
	RGBVAL rgb=0; 
	RGBVAL rgb1=0;
	int textWidth;
	int nLine=0;	// # of lines used to output text
	
	int maxWidth;
	int xText;
	int yText;
	

	if(!pMe)
		return;
	
	TutorI3D_SetTopMenuTextValues(pMe, &xText, &yText, &maxWidth);

	TutorI3D_SetupTutorialWindow(pMe);

	rgb = IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, CLR_API_TEXT);
	
	
	SPRINTF(chBuf, "I3DUtil_SetTranslationMatrix(vect,m)" );
	STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
	
	outputColorText(pMe, szBuf, 29, 4, xText, yText, 
					maxWidth, CLR_API_VAR_TEXT);

	IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, MENU_TEXT_CLR );

	// Now draw the tutorial information in the bottom menu. 
	// First set the initial output point for the text and maxWidth. 
	TutorI3D_SetBottomMenuTextValues(pMe,&xText,&yText,&maxWidth);
	
	if(pMe->translateAxis == AXIS_X)
	{
		rgb1 = IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, ITEM_SELECT_COLOR);
	}

	SPRINTF(chBuf, "vect.x = %d << 16", pMe->translateVector.x >> 16);
	STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
	nLine += outputMultiLineStr(pMe, szBuf, -1, xText, yText, -1, maxWidth,
					&textWidth );

	if(pMe->translateAxis == AXIS_X)
	{
		IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb1);
	}
	else if(pMe->translateAxis == AXIS_Y)
	{
		rgb1 = IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, ITEM_SELECT_COLOR);
	}
	
	SPRINTF(chBuf, "vect.y = %d << 16", pMe->translateVector.y >> 16);
	STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
	nLine += outputMultiLineStr(pMe, szBuf, -1, xText, yText + nLine*pMe->charHeight, 
					   -1, maxWidth, &textWidth );
	
	if(pMe->translateAxis == AXIS_Y)
	{
		IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb1);
	}
	else if(pMe->translateAxis == AXIS_Z)
	{
		rgb1 = IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, ITEM_SELECT_COLOR);
	}


	SPRINTF(chBuf, "vect.z = %d << 16", pMe->translateVector.z >> 16);
	STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
	nLine += outputMultiLineStr(pMe, szBuf, -1, xText, yText + nLine*pMe->charHeight, 
					   -1, maxWidth, &textWidth );
	
	if(pMe->translateAxis == AXIS_Z)
	{
		IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb1);
	}

	IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, CLR_BLACK);
	

	STR_TO_WSTR("Press '#' for Help", szBuf, sizeof(szBuf));
	IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, szBuf,
					  -1, 0, 0, NULL, IDF_ALIGN_CENTER | IDF_ALIGN_BOTTOM | 
					  IDF_TEXT_TRANSPARENT);

	if(pMe->showHelp)
	{

		IDISPLAY_EraseRect(pMe->a.m_pIDisplay, &pMe->screenAPI3DRect);


		nLine = 0;
		xText = pMe->menuTopRect.x + 1;
		yText = pMe->menuTopRect.y + pMe->menuTopRect.dy + 5;

			
		STR_TO_WSTR("Up: +", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText+nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

		STR_TO_WSTR("Down: -", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText+nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

		STR_TO_WSTR("1: x axis", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText + nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);
		
		STR_TO_WSTR("2: y axis", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText + nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

		STR_TO_WSTR("3: z axis", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText + nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

		STR_TO_WSTR("#: show/hide help", szBuf, sizeof(szBuf));
		nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
						yText + nLine*pMe->charHeight, 
						-1, pMe->di.cxScreen -5, &textWidth);

	}

	IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb);
}

⌨️ 快捷键说明

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