Jump to content
  • Advertisement
Sign in to follow this  

[DirectX9] Rotating Triangle while flat...

This topic is 3660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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);


    // select which vertex format we are using


    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

                       &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

                               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->Present(NULL, NULL, NULL, NULL);


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!