# [DirectX9] Rotating Triangle while flat...

## Recommended Posts

I am learning to use DirectX via DirectXTutorial.com and I am having trouble doing the suggested exercises. I am doing Direct3D Basics Lesson 5: Transforming Vertices. I am attempting to do exercise number four but I am kind of at a loss and would greatly appreciate some help to get over this hump. Here is the question and the website: "Now make the triangle lie flat while it rotates (be careful, it can only be seen from one side)." http://www.directxtutorial.com/Tutorial9/B-Direct3DBasics/dx9B5.aspx (Source code is near the bottom on a spoiler button) The lesson is learn what the three Transformations(World, View, Projection) are and how they work. The only thing I can think of is to change the X and Y coordinates of the vertices. Any and all help, suggestions, and criticism is greatly appreciated.
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

d3ddev->BeginScene();

// select which vertex format we are using
d3ddev->SetFVF(CUSTOMFVF);

// SET UP THE PIPELINE

D3DXMATRIX matRotateY;    // a matrix to store the rotation information
D3DXMATRIX matTranslate;  // a matrix to store the translation information
static float index = 0.0f; index+=0.05f;    // an ever-increasing float value

// build a matrix to rotate the model based on the increasing float value
D3DXMatrixRotationY(&matRotateY, index);

// tell Direct3D about our matrix
d3ddev->SetTransform(D3DTS_WORLD, &(matRotateY * matTranslate));

D3DXMATRIX matView;    // the view transform matrix

D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (0.0f, 0.0f, 10.0f),    // the camera position
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // the look-at position
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction

d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView

D3DXMATRIX matProjection;     // the projection transform matrix

D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),    // the horizontal field of view
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
1.0f,    // the near view-plane
(indexRise));    // the far view-plane

d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection

// select the vertex buffer to display
d3ddev->SetStreamSource(0, t_buffer, 0, sizeof(CUSTOMVERTEX));

// copy the vertex buffer to the back buffer
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

d3ddev->EndScene();

d3ddev->Present(NULL, NULL, NULL, NULL);

return;
}



## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Forum Statistics

• Total Topics
627752
• Total Posts
2978920

• 10
• 10
• 22
• 14
• 14