Sign in to follow this  
Capsule03

DirectX 11 , Beginner Simple Animation Question

Recommended Posts

I'm just learning how to use DirectX11, and I've hit a snag. I've gone through all the 'tutorial' samples in the SDK, and I've searched online (and on gamedev) for code samples or tutorials, but I can't figure out a really simple thing.

Lets say I have a cube and a pyramid. For simplicity, all the application does is rotate the cube around the (stationary) pyramid. How do I do this?

The only thing that I've found is in the SDK. In the transform tutorial, they update a constant buffer every frame by setting a world matrix, and then drawing the object. Does this mean I have to set the world matrix, update the constant buffer, and call draw() for every single object that I render? (in this example, the moving cube. In a more general scope, perhaps hundreds of entities on the screen, meaning hundreds of draw calls).

Please direct me down the right track - a tutorial, sample code of any sort.. If I can find any code that handles simple animation like this, I'll be able to learn from it, but I'm completely lost.

Share this post


Link to post
Share on other sites
If all you do is change the World matrix each frame, you don't need to update your Buffers. Create them once, fill them with data and finito. As long as the stored Data is supposed to be static, you don't need to update.

As for your other question, yes you have to set the World Matrix and then call the Draw function for each object you render. Unless you put EVERYTHING in one constant buffer, which personally, I don't like, and is very difficult to pull off.

(This is pulled straight out of my ass, so no guarantees this will actually work ;)

Your render Routine might look something like this:

// Set the Vertex Buffer for your Pyramid
pd3dDevice->IASetVertexBuffers( 0, 1, PyramidVB, Strides, Offsets );
pd3dDevice->IASetIndexBuffer( NULL, DXGI_FORMAT_R16_UINT, 0 );
pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

// Set World-View-Projection Matrix for your Pyramid
// Might as well Set the World Matrix as an Identity-Matrix if it's in the center anyways
// The ViewProjection Part should be coming from your Camera Class (if you have one)
pmWorldViewProjection->SetMatrix( ( float* )&mPyramidWorldViewProjection );

// Draw The Pyramid
D3D10_TECHNIQUE_DESC techDesc;
pTechnique->GetDesc( &techDesc );
for( UINT p = 0; p < techDesc.Passes; ++p )
{
pTechnique->GetPassByIndex( p )->Apply( 0 );
pd3dDevice->Draw( 36, 0 );
}


// Now on to the Cube
pd3dDevice->IASetVertexBuffers( 0, 1, CubeVB, Strides, Offsets );
pd3dDevice->IASetIndexBuffer( NULL, DXGI_FORMAT_R16_UINT, 0 );
pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

// Create the Matrix based on the rotation around the Pyramid
D3DXMATRIX mTranslation;
D3DXMATRIX mRotation;
// So that it doesnt rotate inside the Pyramid, move it 100 along the X-Axis
D3DXMatrixTranslation( &mTranslation, 100.0f, 0.0f, 0.0f );
// Now Rotate it based on time. 1000.0f is just a random factor i pulled .. you know out of where
D3DXMatrixRotationY( &mRotation, fTime / 1000.0f );
// Now multiply them all together
D3DXMatrixMultiply( &mCubeWorldViewProjection, &mTranslation, &mRotation);
D3DXMatrixMultiply( &mCubeWorldViewProjection, &mCubeWorldViewProjection, &CameraViewProjection);

// Set the new Matrix
pmWorldViewProjection->SetMatrix( ( float* )&mCubeWorldViewProjection );

// Draw the Cube
D3D10_TECHNIQUE_DESC techDesc;
pTechnique->GetDesc( &techDesc );
for( UINT p = 0; p < techDesc.Passes; ++p )
{
pTechnique->GetPassByIndex( p )->Apply( 0 );
pd3dDevice->Draw( 36, 0 );
}

Share this post


Link to post
Share on other sites
That's definitely the easiest and simplest way to do it. If necessary you can use instancing to draw many instances of the same mesh (each with different data like world matrix or color) in a single draw call. However I'd recommend you continue with the basics first, and then move on to instancing either once you have better grasp of things or when you feel you need it for performance reasons.

Share this post


Link to post
Share on other sites

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

Sign in to follow this