• Advertisement
Sign in to follow this  

Rotate meshes separately?

This topic is 3735 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

Hi , Ive been following the matrices tutorials for D3D and Ive got a problem see when the code shows how to rotate the triangle, it does not explain how to assign a rotation for every mesh you have in your scene. Ive tried adding a second vertex buffer in my code and is rotating as well What do I need so I can rotate (transform) each mesh separately? heres what Ive got so far
//-----------------------------------------------------------------------------
// Name: Render
// Desc: Direct3D Render Routine
//-----------------------------------------------------------------------------
void Render()
{
    // Clear the back buffer to a blue color
    D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );

    // Setup the transformation matrices
    WorldTransform();
    ViewTransform();
    PerspectiveTransform();

    // Begin the scene
    D3DDevice->BeginScene();

    // Identify the fixed function vertex
    D3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );


    // QUAD
    // Rendering of scene objects happens here
    D3DDevice->SetStreamSource( 0, VB_quad, 0, sizeof(TYPE_D3DVERTEX)  );
    // Render the vertices from the buffer
    D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

    // TRIANGLE
    // Rendering of scene objects happens here
    D3DDevice->SetStreamSource( 0, VB_triangle, 0, sizeof(TYPE_D3DVERTEX) );
    // Render the vertices from the buffer
    D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST , 0, 1 );

    // End the scene
    D3DDevice->EndScene();

    // After rendering is finished, present the scene
    D3DDevice->Present( NULL, NULL, NULL, NULL );
}//Render()

//-----------------------------------------------------------------------------
// Name: WorldTransform()
// Desc: defines the world transformation
//-----------------------------------------------------------------------------

void WorldTransform ()
{

    static float index = 0.0f; index+=0.05f;    // an ever-increasing float value

    D3DXMATRIX matRotateY;      // a matrix to store the rotation information
    D3DXMATRIX matTranslate;    // a matrix to store the translation information
    D3DXMATRIX matScale;        // a matrix to store the scaling information

    // D3DXMatrixRotationX(&matRotateY, index);
    D3DXMatrixRotationY(&matRotateY, index);
    // D3DXMatrixRotationZ(&matRotateY, index);               

    // D3DXMatrixRotationYawPitchRoll(&matRotateY, index, index, index);

    

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

} 

Share this post


Link to post
Share on other sites
Advertisement
You need to use a seperate world matrix for each mesh you're rendering. It would look like this.

// first mesh
SetStreamSource(...)
SetTransform(... , &world1);
DrawPrimitive(...)

// second mesh
SetStreamSource(...)
SetTransform(... , &world2);
DrawPrimitive(...)

Share this post


Link to post
Share on other sites
It may be worth noting that for performance reasons, it's a good idea to store as many objects in one vertex buffer as possible. While it won't make much of a difference with just two objects, it'll matter if you have a few hundred objects.

If two meshes have the same vertex layout, then they should really be in the same vertex buffer. In your case, you could create a vertex buffer with 7 vertices, and put the triangle in vertices 0..2 and the quad in vertices 3..6. Then you can use the StartVertex parameter to DrawPrimitive to select where to start readng vertices (Index 0 for the triangle, index 3 for the quad).

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
It may be worth noting that for performance reasons, it's a good idea to store as many objects in one vertex buffer as possible. While it won't make much of a difference with just two objects, it'll matter if you have a few hundred objects.

If two meshes have the same vertex layout, then they should really be in the same vertex buffer. In your case, you could create a vertex buffer with 7 vertices, and put the triangle in vertices 0..2 and the quad in vertices 3..6. Then you can use the StartVertex parameter to DrawPrimitive to select where to start readng vertices (Index 0 for the triangle, index 3 for the quad).


Oh yea Ive been reading this everywhere but...

how do I save data from 2 meshes on a single VB?

and how do I access it later , when I need to make my draw calls



could you please make a brief example of this? I would really appreciate it

thank you

Share this post


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

  • Advertisement