Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:36:20+00:00 2026-05-14T09:36:20+00:00

I am creating a 3d plane that lies on the x and z axis,

  • 0

I am creating a 3d plane that lies on the x and z axis, and has hills that extend on the y axis. The bulk of the code looks like this:

float PeaksAndValleys::getHeight(float x, float z)const
{
    return 0.3f*( z*sinf(0.1f*x) + x*cosf(0.1f*z) );
}

void PeaksAndValleys::init(ID3D10Device* device, DWORD m, DWORD n, float dx)
{
    md3dDevice = device;

    mNumRows  = m;
    mNumCols  = n;

    mNumVertices = m*n;
    mNumFaces    = (m-1)*(n-1)*2;


    // Create the geometry and fill the vertex buffer. 

    std::vector<Vertex> vertices(mNumVertices);
    float halfWidth = (n-1)*dx*0.5f;
    float halfDepth = (m-1)*dx*0.5f;
    for(DWORD i = 0; i < m; ++i)
    {
        float z = halfDepth - i*dx;
        for(DWORD j = 0; j < n; ++j)
        {
            float x = -halfWidth + j*dx;

            // Graph of this function looks like a mountain range.
            float y = getHeight(x,z);

            vertices[i*n+j].pos = D3DXVECTOR3(x, y, z);

            // Color the vertex based on its height.
            if( y < -10.0f )
                vertices[i*n+j].color = BEACH_SAND;
            else if( y < 5.0f )
                vertices[i*n+j].color = LIGHT_YELLOW_GREEN;
            else if( y < 12.0f )
                vertices[i*n+j].color = DARK_YELLOW_GREEN;
            else if( y < 20.0f )
                vertices[i*n+j].color = DARKBROWN;
            else
                vertices[i*n+j].color = WHITE;
        }
    }

    D3D10_BUFFER_DESC vbd;
    vbd.Usage = D3D10_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(Vertex) * mNumVertices;
    vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    D3D10_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = &vertices[0];
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB));


    // Create the index buffer.  The index buffer is fixed, so we only 
    // need to create and set once.

    std::vector<DWORD> indices(mNumFaces*3); // 3 indices per face

    // Iterate over each quad and compute indices.
    int k = 0;
    for(DWORD i = 0; i < m-1; ++i)
    {
        for(DWORD j = 0; j < n-1; ++j)
        {
            indices[k]   = i*n+j;
            indices[k+1] = i*n+j+1;
            indices[k+2] = (i+1)*n+j;

            indices[k+3] = (i+1)*n+j;
            indices[k+4] = i*n+j+1;
            indices[k+5] = (i+1)*n+j+1;

            k += 6; // next quad
        }
    }

    D3D10_BUFFER_DESC ibd;
    ibd.Usage = D3D10_USAGE_IMMUTABLE;
    ibd.ByteWidth = sizeof(DWORD) * mNumFaces*3;
    ibd.BindFlags = D3D10_BIND_INDEX_BUFFER;
    ibd.CPUAccessFlags = 0;
    ibd.MiscFlags = 0;
    D3D10_SUBRESOURCE_DATA iinitData;
    iinitData.pSysMem = &indices[0];
    HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mIB));
}

My question pertains to the cosf and sinf. I am familiar with trigonometry and I understand sin, cosine, and tangent, but I am not familiar with cosf and sinf and what they do. From looking at this example, they have a lot to do with finding a y value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:36:21+00:00Added an answer on May 14, 2026 at 9:36 am

    cosf and sinf are simply the float versions of cos and sin. The normal cos and sin functions return double values instead of floats. Note that all these functions work in radians, not degrees.

    Combined in the way above, they give a landscape that looks somewhat like a mountain range, as in this plot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an air traffic control system. I have a class called plane that
I'm creating the perspective projection like this: function quickViewMatrix( pos, center, w, h )
In my program I've create a mesh that look like this: http://en.wikibooks.org/wiki/File:Blender3DNoobToPro-Creating_The_Canvas.jpg And I
Sorry, I know that this topic has been covered a bit. I've read the
I am creating a tabbed pane for the amount of rooms that I have
I am creating a small game for students, and in a place, it has
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Hey I have some problems creating my query into doctrine: My sql query looks
I was wondering if anyone had some code, or knew of a place that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.