Thread: Conceptual Problem in D3D - Tranformations

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Conceptual Problem in D3D - Tranformations

    So I am trying to demonstrate the phenomenon of moire fringes in d3d, because I hope to model the fringes in 3d using rapid prototyping in a cse class i'm taking

    http://www.jstor.org/view/07468342/di020744/02p0043o/0

    So but basically, I'm just trying to simulate the concept of two screens running by each other.

    I have two sets of lines in two different vertex buffers.

    What I want to do is quite like this image

    http://www.jstor.org/cgi-bin/jstor/g.../18b.jpg?jstor

    I have something like this

    Code:
    	pd3dDevice->BeginScene();
    
    	static float i = 0.0;
    	i += 0.01;
    
    	D3DXMATRIX mWorld, mView;
    	D3DXMatrixRotationY( &mView, i );
    	D3DXMatrixTranslation( &mWorld, 0.0f, 0.0f, 5.0f );
    
    	pd3dDevice->SetTransform( D3DTS_WORLD, &mWorld );
    	pd3dDevice->SetFVF( D3DFVF_MY_VERTEX );
    
    	pd3dDevice->SetStreamSource( 0, pCircleList, 0, sizeof(Vertex) );
    	pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, (67 * 720) / 2);
    
    	pd3dDevice->SetTransform( D3DTS_WORLD, &mView );
    
    	pd3dDevice->SetStreamSource( 0, pLineList, 0, sizeof(Vertex) );
    	pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, (300) / 2);
    
    	pd3dDevice->EndScene();
    This has the intention of only rotating one set of lines, but the whole world gets flipped around when I apply the rotation. I just want one of the two sets of lines to rotate around the z. Tipz

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You need to rotate the object representing the lines first.

    Code:
    D3DXMATRIX mWorld, mView;
    	D3DXMatrixRotationY( &mView, i );
    	D3DXMatrixTranslation( &mWorld, 0.0f, 0.0f, 5.0f );
    
    	pd3dDevice->SetTransform( D3DTS_WORLD, &mWorld );
    	pd3dDevice->SetFVF( D3DFVF_MY_VERTEX );
    
    	pd3dDevice->SetStreamSource( 0, pCircleList, 0, sizeof(Vertex) );
    	pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, (67 * 720) / 2);
    
    	pd3dDevice->SetTransform( D3DTS_WORLD, &mView );
    You are setting the world matrix for the object to the view matrix which is incorrect. You need to create an object representing the line grid and then create 2 of these objects. Each of these then will have their own world transformations.

    Based on your setup you seem a bit fuzzy on how 3D transformations work. I suggest doing some research on the topic for further understanding.

    Here is how I would do it:

    Code:
    class LineGrid
    {
      public:
         ...
         void Render();
    
      private:
         D3DXVECTOR3 m_vecPos;
         D3DXVECTOR3 m_vecRot;
         D3DXVECTOR3 m_vecScale;
        
    };
    ...
    void LineGrid::Render()
    {
      D3DXMATRIX matWorld,matTrans,matRot,matScale;
    
      //Scale
      D3DXMatrixScaling(&matScale,m_vecScale.x,m_vecScale.y,m_vecScale.z);
    
      //Rotate - will suffer gimble lock
      D3DXMatrixRotationYawPitchRoll(&matRot,m_vecRot.x,m_vecRot.y,m_vecRot.z);
    
      //Translate
      D3DXMatrixTranslation(&matTrans,m_vecPos.x,m_vecPos.y,m_vecPos.z);
    
      //Concatenate - order is important
      //If you translate then rotate, rotation is around new position
      //If you rotate then translate, rotation is around 0,0,0
      //You may wish to do both depending on the application
    
      //Scale in model space
      //Rotate in model space 
      //Translate to position
      matWorld=matScale*matRot*matTrans;
    
      //Set world transform
      m_pDevice->SetTransform(D3DTS_WORLD,&matWorld);
    
      //Draw object
      ...
      ...
    }
      
    ...
    ...
    void My3DApp::Render()
    {
       //Set view matrix
       m_pDevice->SetTransform(D3DTS_VIEW,m_pCameraMgr->GetActiveCamera());
    
       //Render line grid objects
       ...
       ...
       for (int i=0;i<static_cast<int>(vLineGrids.size());i++)
       {
          vLineGrids[i]->Render();
       }
       ...
       ...
    }

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Thanks. Probably should go over stuff but I'm just being a hack.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM