📄 tutori3d.c
字号:
SIDE EFFECTS
none
===========================================================================*/
static void TutorI3D_DrawSmoothSphere(TutorI3D* pMe)
{
if(!pMe) return;
// Clear the 3D drawing region
IDISPLAY_EraseRect(pMe->a.m_pIDisplay, &pMe->screen3DRect);
//Clear the Z buffer before every frame is drawn. Otherwise,
// the scence may not be drawn properly.
I3D_ResetZBuf(pMe->m_p3D);
TutorI3D_DrawBackground(pMe, IDB_BACKGROUND_BRICK);
// Apply the given transformation matrix for every segment of the model.
if(I3DModel_SetSegmentMVT(pMe->pModelSmoothSphere, &pMe->transformMtx, -1) != SUCCESS)
{
DBGPRINTF("Error: model-view transform not set");
}
// Draw the model
if(I3DModel_Draw(pMe->pModelSmoothSphere,pMe->m_p3D) != SUCCESS)
{
DBGPRINTF("Error: can't draw model");
}
// Start rendering the frame.
if(I3D_StartFrame(pMe->m_p3D) != SUCCESS)
{
DBGPRINTF("Error: StartFrame() failed");
}
}
/*===========================================================================
FUNCTION: TutorI3D_InitLadyBug
DESCRIPTION
Initialization function for drawing the ladybug model.
This function should be called before calling the draw function
for this model.
PROTOTYPE:
void TutorI3D_InitLadyBug(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture;
DEPENDENCIES
none
RETURN VALUE
none
SIDE EFFECTS
none
===========================================================================*/
void TutorI3D_InitLadyBug(TutorI3D* pMe)
{
AEE3DTransformMatrix m1;
if(!pMe) return;
pMe->drawModel = MODEL_LADYBUG;
if(I3DUtil_SetIdentityMatrix(pMe->m_p3DUtil,&pMe->transformMtx) != SUCCESS)
{
DBGPRINTF("Error: can't set identity");
}
// starting position for the man model
pMe->translateVector.x = 0;
pMe->translateVector.y = -40<<16;
pMe->translateVector.z = 600<<16;
if(I3DUtil_SetTranslationMatrix(pMe->m_p3DUtil,&pMe->translateVector,
&pMe->transformMtx) != SUCCESS)
{
DBGPRINTF("Error: can't set translation");
}
/* // increase the size of the model by 2
pMe->transformMtx.m00 >>= 1;
pMe->transformMtx.m11 >>= 1;
pMe->transformMtx.m22 >>= 1;
*/
// don't apply any initial transformations for transform tutorial.
// ie. load model as is, and let user transform.
if(pMe->state != STATE_TRANSFORM)
{
// otherwise, apply some transformations
if(I3DUtil_GetRotateMatrix(pMe->m_p3DUtil,PI_3D, &m1, AEE3D_ROTATE_X) != SUCCESS)
{
DBGPRINTF("Error: rotation matrix");
}
if(I3DUtil_MatrixMultiply(pMe->m_p3DUtil, &pMe->transformMtx, &m1) != SUCCESS)
{
DBGPRINTF("Error: matrix multiply");
}
}
if( !TutorI3D_EnableModelShading(pMe->pLadyBug, TRUE) )
{
DBGPRINTF("Error: setting shading mode");
}
// keep a copy of the initial transform matrix
MEMCPY(&pMe->initalTransMtx, &pMe->transformMtx, sizeof(AEE3DTransformMatrix));
}
/*===========================================================================
FUNCTION: TutorI3D_DrawLadyBug
DESCRIPTION
Draw function for the ladybug. This function should only be called
after the initialization function has been callled for this model.
This function will start the rendering process and draw one frame.
I3D sends an AEE3D_EVENT_FRAME_COMPLETED event to the registered
I3D event notifier when the frame is finished rendering.
PROTOTYPE:
static void TutorI3D_DrawLadyBug(TutorI3D * pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture;
DEPENDENCIES
TutorI3D_InitLadyBug() needs to be called before this function
RETURN VALUE
none
SIDE EFFECTS
none
===========================================================================*/
static void TutorI3D_DrawLadyBug(TutorI3D * pMe)
{
if(!pMe) return;
// Clear the 3D drawing region
IDISPLAY_EraseRect(pMe->a.m_pIDisplay, &pMe->screen3DRect);
I3D_ResetZBuf(pMe->m_p3D);
// Apply the given transformation matrix for the entire model.
if(I3DModel_SetSegmentMVT(pMe->pLadyBug, &pMe->transformMtx, -1) != SUCCESS)
{
DBGPRINTF("Error: model-view transform not set");
}
if(I3DModel_Draw(pMe->pLadyBug,pMe->m_p3D) != SUCCESS)
{
DBGPRINTF("Error: can't draw model");
}
// draw axis model
if(pMe->state == STATE_TRANSFORM_ROTATE ||
pMe->state == STATE_TRANSFORM_TRANSLATE)
{
TutorI3D_DrawAxis(pMe);
}
if(I3D_StartFrame(pMe->m_p3D) != SUCCESS)
{
DBGPRINTF("Error: StartFrame() failed");
}
}
/*===========================================================================
FUNCTION: TutorI3D_InitField
DESCRIPTION
Initialization function for drawing the field model.
This function should be called before calling the draw function
for this model.
PROTOTYPE:
void TutorI3D_InitField(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture;
DEPENDENCIES
none
RETURN VALUE
none
SIDE EFFECTS
none
===========================================================================*/
void TutorI3D_InitField(TutorI3D* pMe)
{
AEE3DTransformMatrix m;
if(!pMe) return;
pMe->drawModel = MODEL_FIELD;
if(I3DUtil_SetIdentityMatrix(pMe->m_p3DUtil,&pMe->transformMtx) != SUCCESS)
{
DBGPRINTF("Error: can't set identity");
}
if(I3D_SetCullingMode(pMe->m_p3D, AEE3D_CULLING_BACK_FACING) != SUCCESS)
{
DBGPRINTF("Error: setting culling mode");
}
pMe->translateVector.x = 0;
pMe->translateVector.y = -100<<16;
pMe->translateVector.z = 128<<16;
if(I3DUtil_SetTranslationMatrix(pMe->m_p3DUtil,&pMe->translateVector,
&pMe->transformMtx) != SUCCESS)
{
DBGPRINTF("Error: can't set translation");
}
I3DUtil_GetRotateMatrix(pMe->m_p3DUtil,PI_3D/6, &m, AEE3D_ROTATE_X);
I3DUtil_MatrixMultiply(pMe->m_p3DUtil,&pMe->transformMtx,&m);
// keep a copy of the initial transform matrix
MEMCPY(&pMe->initalTransMtx, &pMe->transformMtx, sizeof(AEE3DTransformMatrix));
}
/*===========================================================================
FUNCTION: TutorI3D_DrawField
DESCRIPTION
Draw function for the field. This function should only be called
after the initialization function has been callled for this model.
This function will start the rendering process and draw one frame.
I3D sends an AEE3D_EVENT_FRAME_COMPLETED event to the registered
I3D event notifier when the frame is finished rendering.
PROTOTYPE:
static void TutorI3D_DrawField(TutorI3D * pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture;
DEPENDENCIES
TutorI3D_InitField() needs to be called before this function
RETURN VALUE
none
SIDE EFFECTS
none
===========================================================================*/
static void TutorI3D_DrawField(TutorI3D * pMe)
{
if(!pMe) return;
// Clear the 3D drawing region
IDISPLAY_EraseRect(pMe->a.m_pIDisplay, &pMe->screen3DRect);
I3D_ResetZBuf(pMe->m_p3D);
// Apply the given transformation matrix for the entire model.
if(I3DModel_SetSegmentMVT(pMe->pModelField, &pMe->transformMtx, -1) != SUCCESS)
{
DBGPRINTF("Error: model-view transform not set");
}
if(I3DModel_Draw(pMe->pModelField,pMe->m_p3D) != SUCCESS)
{
DBGPRINTF("Error: can't draw model");
}
if(I3D_StartFrame(pMe->m_p3D) != SUCCESS)
{
DBGPRINTF("Error: StartFrame() failed");
}
}
/*===========================================================================
FUNCTION: TutorI3D_InitSphere
DESCRIPTION
Initialization function for drawing the sphere model.
This function should be called before calling the draw function
for this model.
PROTOTYPE:
void TutorI3D_InitSphere(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture;
DEPENDENCIES
none
RETURN VALUE
none
SIDE EFFECTS
none
===========================================================================*/
void TutorI3D_InitSphere(TutorI3D* pMe)
{
AEE3DColor color = {255,127,100,0};
AEE3DPoint srcDirection = {2000,3000,65536};
AEE3DPoint direction;
AEE3DLight light_value;
AEE3DMaterial myMat;
if(!pMe) return;
pMe->drawModel = MODEL_SPHERE;
//GetUnitVector returns a Q12 unit vector. Multiply this by 2^2=4
//to get a Q14 unit vector as SetLight expects
if(I3DUtil_GetUnitVector(pMe->m_p3DUtil, &srcDirection, &direction) != SUCCESS)
{
DBGPRINTF("Error: gettings unit vector");
}
direction.x <<= 2;
direction.y <<= 2;
direction.z <<= 2;
light_value.color = color;
light_value.direction = direction;
light_value.type = AEE3D_LIGHT_DIFFUSED;
if(I3D_SetLight(pMe->m_p3D, &light_value) != SUCCESS)
{
DBGPRINTF("Error: setting light");
}
light_value.type = AEE3D_LIGHT_SPECULAR;
if(I3D_SetLight(pMe->m_p3D, &light_value) != SUCCESS)
{
DBGPRINTF("Error: setting light");
}
myMat.color.r = 248;
myMat.color.g = 191;
myMat.color.b = 36;
myMat.shininess = 50;
myMat.emissive = 5;
if(I3D_SetMaterial(pMe->m_p3D, &myMat) != SUCCESS)
{
DBGPRINTF("Error: setting material");
}
if(I3D_SetRenderMode(pMe->m_p3D, AEE3D_RENDER_SMOOTH_SHADING) != SUCCESS)
{
DBGPRINTF("Error: setting render mode");
}
IDISPLAY_ClearScreen (pMe->a.m_pIDisplay);
I3D_ResetZBuf(pMe->m_p3D);
if(I3D_SetCullingMode(pMe->m_p3D, AEE3D_CULLING_FRONT_FACING) != SUCCESS)
{
DBGPRINTF("Error: setting culling mode");
}
if(I3DUtil_SetIdentityMatrix(pMe->m_p3DUtil,&pMe->transformMtx) != SUCCESS)
{
DBGPRINTF("Error: can't set identity");
}
// increase the size of the model by 2
/* pMe->transformMtx.m00 /= 3/2;
pMe->transformMtx.m11 /= 3/2;
pMe->transformMtx.m22 /= 3/2;
*/
pMe->transformMtx.m00 = 9*pMe->transformMtx.m00/10 ;
pMe->transformMtx.m11 = 9*pMe->transformMtx.m11/10;
pMe->transformMtx.m22 = 9*pMe->transformMtx.m22/10;
pMe->translateVector.x = 0;
pMe->translateVector.y = -15 << 16;
pMe->translateVector.z = 200<<16;
if(I3DUtil_SetTranslationMatrix(pMe->m_p3DUtil,&pMe->translateVector,
&pMe->transformMtx) != SUCCESS)
{
DBGPRINTF("Error: setting translation matrix");
}
// keep a copy of the initial transform matrix
MEMCPY(&pMe->initalTransMtx, &pMe->transformMtx, sizeof(AEE3DTransformMatrix));
}
/*===========================================================================
FUNCTION: TutorI3D_DrawSphere
DESCRIPTION
Draw function for the sphere. This function should only be called
after the initialization function has been callled for this model.
This function will start the rendering process and draw one frame.
I3D sends an AEE3D_EVENT_FRAME_COMPLETED event to the registered
I3D event notifier when the frame is finished rendering.
PROTOTYPE:
static void TutorI3D_DrawSphere(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture;
DEPENDENCIES
TutorI3D_InitSphere() needs to be called before this function
RETURN VALUE
none
SIDE EFFECTS
none
===========================================================================*/
static void TutorI3D_DrawSphere(TutorI3D* pMe)
{
if(!pMe) return;
// Clear the 3D drawing region
IDISPLAY_EraseRect(pMe->a.m_pIDisplay, &pMe->screen3DRect);
I3D_ResetZBuf(pMe->m_p3D);
// Draw the Background for the sphere tutorial
TutorI3D_DrawBackground(pMe, IDB_BACKGROUND_BRICK);
if(!Obj_RenderObj(pMe, pMe->sphereModel, &pMe->transformMtx, TRUE))
{
DBGPRINTF("Error: can't render object");
}
if(I3D_StartFrame(pMe->m_p3D) != SUCCESS)
{
DBGPRINTF("Error: StartFrame() failed");
}
}
/*===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -