ID3DXLine::DrawTransform problem

This is a discussion on ID3DXLine::DrawTransform problem within the Game Programming forums, part of the General Programming Boards category; Hi! I can't figure out why DrawTransform does not work for me. While ID3DXLine: raw draws the line as expected, ...

  1. #1
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463

    ID3DXLine::DrawTransform problem

    Hi!

    I can't figure out why DrawTransform does not work for me.
    While ID3DXLine:raw draws the line as expected, I just can't manage this with DrawTransform.
    Here's the code:
    Code:
    D3DXMATRIX matView;
        D3DXVECTOR3 vFromPt   = D3DXVECTOR3( 0.0f, 0.0f, -5.0f );
        D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
        D3DXVECTOR3 vUpVec    = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
        D3DXMatrixLookAtLH( &matView, &vFromPt, &vLookatPt, &vUpVec );
        m_pd3dDevice->SetTransform( D3DTS_WORLD, &matView );
        
    	
    	ppLine->Begin();
    	if ( ppLine->DrawTransform( myCoordVectPtr, myVertexCount, &matView, D3DCOLOR_RGBA( 0, 0, 0, 255 ) ) != D3D_OK )
    	{
    		cout << "DrawTransform failed!" << endl;	
    	}
    	//ppLine->Draw( myCoordVectPtr, myVertexCount, D3DCOLOR_RGBA( 0, 0, 0, 150 ) );
    	ppLine->End();
    Thank you in advance!

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    It fails because your view matrix is not setup correctly. You need to create a camera class that will handle this for you.

    For instance I do not see any translation in your matView matrix at all. The view matrix can only be setup properly by correct concatenation of the translation, scaling, and world matrices.

    Here is a sample of translation, scaling, and rotation:

    Translation = T

    T =
    [1,0,0,0]
    [0,1,0,0]
    [0,0,1,0]
    [dx,dy,dz,1]

    Scaling=S
    S=
    [sx,0,0,0]
    [0,sy,0,0]
    [0,0,sz,0]
    [0,0,0,1]

    Rotation:
    Rv=rotation about v axis
    Rx=
    [1,0,0,0]
    [0,cos,sin,0,0]
    [0,-sin,cos,1,0]
    [0,0,0,1]

    Ry=
    [cos,0,-sin,0]
    [0,1,0,0]
    [sin,0,cos,0]
    [0,0,0,1]

    Rz=
    [cos, sin, 0, 0]
    [-sin, cos, 0, 0]
    [0,0,1,0]
    [0,0,0,1]

    But you must setup a projection matrix or it will not display correctly. Concatenation with the projection matrix does not actually yield 2D coordinates, but it prepares the pipeline to do so by setting up for division by W.

    [1,0,0,0]
    [0,1,0,0]
    [0,0,1,1/d]
    [0,0,0,0]

    Clip matrix:
    zoomx=zoom on x axis
    zoomy=zoom on y axis
    f=distance to far clipping plane
    n=distance to near clipping plane

    [zoomx,0,0,0]
    [0,zoomy,0,0]
    [0,0,f/(f-n),1]
    [0,0,(n*f)/(n-f),0]

  3. #3
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Thank you, Bubba! I thought DirectX AppWizard sets up these matrices for me...

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Nope. No matrices are setup automatically for you. You don't have to directly set these up, but you must call DirectX helper functions that set them up for you. So while you don't have to bother with the tedium of writing a function to set the matrix up piece by piece, you still have to call the correct function(s) to set matrices up. The reason for this is very clear.

    D3D has absolutely no way of knowing how you want to use the matrices. Of course it knows that translation will be a 3D translation from one point to another, but it has no idea about where you want to translate to in 3D space. So it really does not make sense to create a default matrix for the programmer. It would probably work against you in most cases.


    D3DXMATRIX Translation;

    D3DXMatrixTranslation(&Translation,50.0f,60.0f,70. 0f);

    Sets this matrix up:

    Translation=
    [1,0,0,0]
    [0,1,0,0]
    [0,0,1,0]
    [50.0f,60.0f,70.0f,1]

    Look at the D3DX helper functions for matrices. They are all in the form D3DXMatrix.....


    Also I would trend away from using the DirectX AppWizard stuff. I've never found them to be very useful and you are pretty much stuck in their design rather than creating your own. Good to start with but will work against you more and more as your skills improve.
    Last edited by VirtualAce; 09-20-2004 at 03:45 PM.

  5. #5
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Thanks, I get the math and the theory, however can't display a single line using ID3DXLine:rawTransform...
    Here's the code:

    Code:
    	D3DXMATRIX mTransfo;
    	D3DXMatrixTranslation(&mTransfo,1.0f,1.0f,-1.0f);
    	ppLine->Begin();
    	if ( ppLine->DrawTransform( myCoordVectPtr, myVertexCount, &mTransfo, D3DCOLOR_RGBA( 0, 0, 0, 255 ) ) != D3D_OK )
    	{
    		cout << "DrawTransform failed!" << endl;	
    	}
    	// line is displayed correctly when myCoordVectPtr is declared as D3DXVECTOR2,
    	// using ID3DXLine::Draw() API
    	//ppLine->Draw( myCoordVectPtr, myVertexCount, D3DCOLOR_RGBA( 0, 0, 0, 150 ) );
    	ppLine->End();
    I searched with google for code snippets, found nothing. I feel somehow frustrated.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    What color are you clearing the screen to? If it's black then, Houston we have a problem. You are specifying

    D3DCOLOR_RGBA( 0, 0, 0, 255 )

    as your color to draw the line, which is black.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  7. #7
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    The background is not black, of course
    Code:
        m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                             0x00FFFFFF, 1.0f, 0L );
    I managed to draw using DrawTransform a simple line, however with my nicely set up vertex buffer still does not work. I keep trying.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Hey, it can happen to the best of us

    I'll assume your pointer to the vertices is valid. You translate Z by -1. Are you using a Left-Handed system? This would be behind the view plane and thus not visible. Also, I've said it before and I'll say it again, turn your debug output level up to maximum in the directX control panel settings and run your program through the debugger and see what it spits out.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Thank you, MrWizard!
    I thing there is a scaling problem: while ID3DXLine::Draw expects screen coordinates, DrawTransform works with small float values. I'm experimenting with scaling down the coords.

    ...and indeed, scaling was the problem!
    I displayed my line somewhere in the outer space ;).
    Scaling down (1:1000) helped.

    Thank you all for all the hints and help!
    Last edited by Carlos; 09-21-2004 at 03:12 AM.

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    DrawTransform sends the vertexes through the pipeline and transformations. Draw does not. It renders vertexes of type TLVertex. These are assumed to be transformed, lit, translated, etc. Essentially they are assumed to have been through another pipeline. Direct3D does not process these which is exactly what you want.

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, 10: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

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