need help with D3DXVec3TransformCoord on second mesh

This is a discussion on need help with D3DXVec3TransformCoord on second mesh within the Game Programming forums, part of the General Programming Boards category; when i got to use this in render loop , Mesh2 gets the same converted x,y,z as Mesh 1 , ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    need help with D3DXVec3TransformCoord on second mesh

    when i got to use this in render loop , Mesh2 gets the same converted x,y,z as Mesh 1 , both meshs are placed next to each other so i dont know why they get the same values after D3DXVec3TransformCoord
    do you have to create a new matrix where you draw the mesh?
    http://img136.imageshack.us/my.php?image=shipsbi5.jpg
    Code:
    void CreateBoundingBox2(LPD3DXMESH Mesh2){
      
      if(Mesh2) //if its valid
      {
      BYTE* pVertices=NULL;
      HRESULT hr=Mesh2->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
     
      D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices, 
    	                      Mesh2->GetNumVertices(), 
    						  D3DXGetFVFVertexSize(Mesh2->GetFVF()), 
    						  &minBounds2, 
    						  &maxBounds2);
      Mesh2->UnlockVertexBuffer();
      }
    
      
    //put each corner to worldspace
    // We have min and max values, use these to get the 8 corners of the bounding box
    m_objectBounds2[0] = D3DXVECTOR3( minBounds2.x, minBounds2.y, minBounds2.z ); // xyz
    m_objectBounds2[1] = D3DXVECTOR3( maxBounds2.x, minBounds2.y, minBounds2.z ); // Xyz
    m_objectBounds2[2] = D3DXVECTOR3( minBounds2.x, maxBounds2.y, minBounds2.z ); // xYz
    m_objectBounds2[3] = D3DXVECTOR3( maxBounds2.x, maxBounds2.y, minBounds2.z ); // XYz
    m_objectBounds2[4] = D3DXVECTOR3( minBounds2.x, minBounds2.y, maxBounds2.z ); // xyZ
    m_objectBounds2[5] = D3DXVECTOR3( maxBounds2.x, minBounds2.y, maxBounds2.z ); // XyZ
    m_objectBounds2[6] = D3DXVECTOR3( minBounds2.x, maxBounds2.y, maxBounds2.z ); //   
    m_objectBounds2[7] = D3DXVECTOR3( maxBounds2.x, maxBounds2.y, maxBounds2.z ); // XYZ
    
    // Transform the 8 corners of our object space bounding box into world space
    //sprintf(data , "%s %f\n" , "m_objectBounds[0].x", m_objectBounds[0].x);
    //WriteConsole(Console,data, sizeof(data) , &written, NULL);
    
    //convert
    for( int i = 0; i < 8; i++ ){
       D3DXVec3TransformCoord( &worldBounds2[i], &m_objectBounds2[i], &matTrans );
    }
    
    
    
    
    
    Sleep(50);
    }
    Last edited by Anddos; 02-15-2008 at 02:21 PM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Why are you doing this manually?

    The correct way to compute bounding boxes is to transform and then re-compute the bounding box. Otherwise you will end up with some bounding volumes that are not accurate. You cannot create the bounding volume and then just transform it.

    D3DXComputeBoundingBox() might interest you.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    right so now in BeginScene i have

    Code:
    D3DXMatrixTranslation(&matTrans , Left , 0.0f , Forward);
    	d3ddev->SetTransform(D3DTS_WORLD, &(matTrans));
        CreateBoundingBox(meshSpaceship);
    	d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 0, 0));
    	
    
    
        for(DWORD i = 0; i < numMaterials; i++)    // loop through each subset
        {
             d3ddev->SetMaterial(&material[i]);    // set the material for the subset
             meshSpaceship->DrawSubset(i);    // draw the subset
    		
        }

  4. #4

    Join Date
    May 2005
    Posts
    1,041
    Uhh in the code above (first post), you were writing the values before transforming them. Don't be offended it that isn't the problem (but gotta get the obvious stuff out of the way).
    I'm not immature, I'm refined in the opposite direction.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    As Bob said your previous code could have worked but in the end your algo would not have worked. Due to floating point roundoff and all of the transformations you would have put your original bounding volume through your system would not have worked.

    Transform then recreate the bounding volume. I recommend you render your volumes so you will see what begins to happen after several transforms.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    i am now struggling to figure out how the collisions is done ,
    ive got 2 meshs loaded to screen and have there Bounding Min Max and converted to world space , is it something like if(WorldBounds[0].x > WorldBounds2[0].x)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mesh Class Design problem
    By sarah22 in forum Game Programming
    Replies: 2
    Last Post: 05-20-2009, 05:52 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  3. Completely Automatic Mesh Morphing Algorithm
    By Zeeshan in forum Game Programming
    Replies: 5
    Last Post: 05-15-2008, 08:05 AM
  4. Mesh Release() Problem
    By Morgul in forum Game Programming
    Replies: 6
    Last Post: 03-07-2006, 02:50 PM
  5. Mesh Rendering: Z-Buffer and Lighting
    By Epo in forum Game Programming
    Replies: 6
    Last Post: 04-20-2005, 08:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21