📄 lighting.c
字号:
/* Only display color specular info if in a mode that requires it*/
if(lightMode == AEE3D_LIGHT_MODE_DIFFUSED_COLOR_SPECULAR ||
lightMode == AEE3D_LIGHT_MODE_COLOR_DIFFUSED_COLOR_SPECULAR)
{
if(pMe->lightTypeOp == AEE3D_LIGHT_SPECULAR)
{
if(pMe->lightDirColOp == LIGHT_RED)
colCharStart = 17;
else if(pMe->lightDirColOp == LIGHT_GREEN)
colCharStart = 21;
else if(pMe->lightDirColOp == LIGHT_BLUE)
colCharStart = 25;
else if(pMe->lightDirColOp == LIGHT_ALPHA)
colCharStart = 29;
else
colCharStart = -1;
}
else
colCharStart = -1;
SPRINTF(chBuf, "light.colorSpec=(%.3d,%.3d,%.3d,%.3d)",
lightSpecular.color.r, lightSpecular.color.g,
lightSpecular.color.b, lightSpecular.color.a);
STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
nLine = outputColorText(pMe, szBuf, colCharStart, 3, xText, yText,
maxWidth, ITEM_SELECT_COLOR);
yText += nLine*pMe->charHeight;
if(pMe->lightTypeOp == AEE3D_LIGHT_SPECULAR)
{
if(pMe->lightDirColOp == LIGHT_X)
colCharStart = 15;
else if(pMe->lightDirColOp == LIGHT_Y)
colCharStart = 22;
else if(pMe->lightDirColOp == LIGHT_Z)
colCharStart = 29;
else
colCharStart = -1;
}
else
colCharStart = -1;
if(lightMode != AEE3D_LIGHT_MODE_DIFFUSED_COLOR_SPECULAR)
{
SPRINTF(chBuf, "light.dirSpec=(%+.5d,%+.5d,%+.5d)", lightSpecular.direction.x,
lightSpecular.direction.y, lightSpecular.direction.z);
STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
nLine = outputColorText(pMe, szBuf, colCharStart, 6, xText, yText,
maxWidth, ITEM_SELECT_COLOR);
yText = nLine*pMe->charHeight;
}
}
if(pMe->lightTypeOp == AEE3D_LIGHT_SPECULAR)
{
IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb1);
}
//place the help key information in a different location on screen.
// doesn't fit in the bottom of screen in this mode because of too much text
STR_TO_WSTR("Press '#' for Help", szBuf, sizeof(szBuf));
if(lightMode == AEE3D_LIGHT_MODE_COLOR_DIFFUSED_COLOR_SPECULAR)
{
IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, szBuf,
-1, 0, pMe->menuTopRect.y+pMe->menuTopRect.dy +5,
NULL, IDF_ALIGN_CENTER | IDF_TEXT_TRANSPARENT);
}
else
{
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/Down: inc./dec.", szBuf, sizeof(szBuf));
nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
yText+nLine*pMe->charHeight,
-1, pMe->di.cxScreen -5, &textWidth);
STR_TO_WSTR("1/2/3: (x,y,z) select", szBuf, sizeof(szBuf));
nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
yText + nLine*pMe->charHeight,
-1, pMe->di.cxScreen -5, &textWidth);
STR_TO_WSTR("4/5/6/7: (red,green,blue,alpha)", szBuf, sizeof(szBuf));
nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
yText + nLine*pMe->charHeight,
-1, pMe->di.cxScreen -5, &textWidth);
STR_TO_WSTR("8: toggle diffuse/specular", szBuf, sizeof(szBuf));
nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
yText + nLine*pMe->charHeight,
-1, pMe->di.cxScreen -5, &textWidth);
STR_TO_WSTR("9: toggle lighting mode", 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_SetFont(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, oldFont);
pMe->charHeight = oldFontHeight;
IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb);
}
/*===========================================================================
FUNCTION: LightingMaterialManipulateBuf
DESCRIPTION
This function adds text and 2D graphics to the frame buffer after
3D frame render is complete for the material tutorial.
PROTOTYPE:
void LightingMaterialManipulateBuf(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture
DEPENDENCIES
none
RETURN VALUE
none
SIDE EFFECTS
none
===========================================================================*/
void LightingMaterialManipulateBuf(TutorI3D* pMe)
{
AECHAR szBuf[80];
char chBuf[80];
int8 colCharStart=-1; // index of first color character on the line
AEE3DMaterial material;
IFont* oldFont;
int oldFontHeight;
RGBVAL rgb=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, "I3D_SetMaterial(mat)" );
STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
outputColorText(pMe, szBuf, 16, 3, xText, yText,
maxWidth, CLR_API_VAR_TEXT);
// 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);
I3D_GetMaterial(pMe->m_p3D, &material);
IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, MENU_TEXT_CLR );
oldFont = IDISPLAY_SetFont(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, pMe->font10);
oldFontHeight = pMe->charHeight;
pMe->charHeight = IDISPLAY_GetFontMetrics(pMe->a.m_pIDisplay, AEE_FONT_NORMAL,
NULL, NULL);
SPRINTF(chBuf, "mat.color = (%.3d,%.3d,%.3d,%.3d)", material.color.r, material.color.g,
material.color.b, material.color.a);
STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
if(pMe->lightMaterialOp == MATERIAL_RED)
colCharStart = 13;
else if(pMe->lightMaterialOp == MATERIAL_GREEN)
colCharStart = 17;
else if(pMe->lightMaterialOp == MATERIAL_BLUE)
colCharStart = 21;
else if(pMe->lightMaterialOp == MATERIAL_ALPHA)
colCharStart = 25;
else
colCharStart = -1;
nLine = outputColorText(pMe, szBuf, colCharStart, 3, xText, yText,
maxWidth, ITEM_SELECT_COLOR);
yText += nLine*pMe->charHeight;
SPRINTF(chBuf, "mat.shininess = %.3d", material.shininess);
STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
if(pMe->lightMaterialOp == MATERIAL_SHININESS)
colCharStart = 16;
else
colCharStart = -1;
nLine = outputColorText(pMe, szBuf, colCharStart, 3, xText, yText,
maxWidth, ITEM_SELECT_COLOR);
yText += nLine*pMe->charHeight;
SPRINTF(chBuf, "mat.emissive = %.3d", material.emissive);
STR_TO_WSTR (chBuf, szBuf, sizeof(szBuf));
if(pMe->lightMaterialOp == MATERIAL_EMISSIVE)
colCharStart = 15;
else
colCharStart = -1;
nLine = outputColorText(pMe, szBuf, colCharStart, 3, xText, yText,
maxWidth, ITEM_SELECT_COLOR);
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/Down: inc./dec.", szBuf, sizeof(szBuf));
nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
yText+nLine*pMe->charHeight,
-1, pMe->di.cxScreen -5, &textWidth);
STR_TO_WSTR("1/2/3/4: (red,green,blue,alpha) select", szBuf, sizeof(szBuf));
nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
yText + nLine*pMe->charHeight,
-1, pMe->di.cxScreen -5, &textWidth);
STR_TO_WSTR("5: shininess", szBuf, sizeof(szBuf));
nLine += outputMultiLineStr(pMe, szBuf, -1, xText,
yText + nLine*pMe->charHeight,
-1, pMe->di.cxScreen -5, &textWidth);
STR_TO_WSTR("6: emissive", 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_SetFont(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, oldFont);
pMe->charHeight = oldFontHeight;
IDISPLAY_SetColor(pMe->a.m_pIDisplay, CLR_USER_TEXT, rgb);
}
/*===========================================================================
FUNCTION: isColorLightingMode
DESCRIPTION
This function can be used to tell if a given combination of
lighting mode and light type support color light
PROTOTYPE:
static boolean isColorLightingMode(AEE3DLightingMode mode, AEE3DLightType type)
PARAMETERS:
mode: [in]: Lighting mode to check
type: [in]: Light type to check
DEPENDENCIES
none
RETURN VALUE
TRUE: if the combination of mode and type support color light
FALSE: otherwise
SIDE EFFECTS
none
===========================================================================*/
static boolean isColorLightingMode(AEE3DLightingMode mode, AEE3DLightType type)
{
switch(mode)
{
case AEE3D_LIGHT_MODE_DIFFUSED:
{
return FALSE;
}
case AEE3D_LIGHT_MODE_COLOR_DIFFUSED:
{
if(type == AEE3D_LIGHT_DIFFUSED)
return TRUE;
}
break;
case AEE3D_LIGHT_MODE_DIFFUSED_COLOR_SPECULAR:
{
if(type == AEE3D_LIGHT_SPECULAR)
return TRUE;
}
break;
case AEE3D_LIGHT_MODE_COLOR_DIFFUSED_COLOR_SPECULAR:
{
return TRUE;
}
default:
break;
}
return FALSE;
}
/*===========================================================================
FUNCTION: isLightingColorOption
DESCRIPTION
This function is used to tell if lightDirColOp is one
of the color options.
PROTOTYPE:
static boolean isLightingColorOption(LightingDirColOption lightDirColOp)
PARAMETERS:
lightDirColOp: [in]: Option we're checking
DEPENDENCIES
none
RETURN VALUE
TRUE: if lightDirColOp is a color option
FALSE: otherwise
SIDE EFFECTS
none
===========================================================================*/
static boolean isLightingColorOption(LightingDirColOption lightDirColOp)
{
switch(lightDirColOp)
{
case LIGHT_RED:
case LIGHT_GREEN:
case LIGHT_BLUE:
case LIGHT_ALPHA:
return TRUE;
default:
break;
}
return FALSE;
}
/*===========================================================================
FUNCTION: isLightingDirectionOption
DESCRIPTION
This function is used to tell if lightDirColOp is one
of the direction options.
PROTOTYPE:
static boolean isLightingDirectionOption(LightingDirColOption lightDirColOp)
PARAMETERS:
lightDirColOp: [in]: Option we're checking
DEPENDENCIES
none
RETURN VALUE
TRUE: if lightDirColOp is a direction option
FALSE: otherwise
SIDE EFFECTS
none
===========================================================================*/
static boolean isLightingDirectionOption(LightingDirColOption lightDirColOp)
{
switch(lightDirColOp)
{
case LIGHT_X:
case LIGHT_Y:
case LIGHT_Z:
return TRUE;
default:
break;
}
return FALSE;
}
/*===========================================================================
FUNCTION: isDirectionLightingMode
DESCRIPTION
This function can be used to tell if a given combination of
lighting mode and light type support a direction vector.
Note: all combinations do except in AEE3D_LIGHT_MODE_DIFFUSED_COLOR_SPECULAR
mode with light type being AEE3D_LIGHT_SPECULAR.
PROTOTYPE:
static boolean isDirectionLightingMode(AEE3DLightingMode mode, AEE3DLightType type)
PARAMETERS:
mode: [in]: Lighting mode to check
type: [in]: Light type to check
DEPENDENCIES
none
RETURN VALUE
TRUE: if the combination of mode and type support a direction vector
FALSE: otherwise
SIDE EFFECTS
none
===========================================================================*/
static boolean isDirectionLightingMode(AEE3DLightingMode mode, AEE3DLightType type)
{
switch(mode)
{
// In AEE3D_LIGHT_MODE_DIFFUSED_COLOR_SPECULAR mode,
// diffuse and specular lighting share direction.
// Use the diffuse lighting direction by default,
// and ignore the specular direction by returning FALSE here.
case AEE3D_LIGHT_MODE_DIFFUSED_COLOR_SPECULAR:
{
if(type == AEE3D_LIGHT_SPECULAR)
return FALSE;
}
default:
break;
}
// all other combinations support a direction vector.
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -