Archived

This topic is now archived and is closed to further replies.

SiN

Object translation problem (yes, another one)

Recommended Posts

SiN    122
hey guys, okay, i'm no programming n00b, but i am a DirectX n00b ... having just got into directx yesterday, ive havent been doing too badly ... using the AppWizard, i created a DirectX 8.1 project. i made a camera, rendered a bunch of polys from the vertex buffer, and loaded & rendered a model. problem is that i cant position the model wherever i want to ... after a bit of searching on gamedev, i find that u need to make a world matrix ... tried it , didnt work ... heres the my render method, its nice & short , so it shouldnt be TOO much trouble to look thru ... i kno im screwing up on something silly, i'd just like to kno what
HRESULT CMyD3DApplication::Render()
{
    // Clear the viewport

    m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                         0x000000ff, 1.0f, 0L );

    // Begin the scene

    if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
    {
	D3DXMATRIX matView;
	D3DXMATRIX matWorld;

	// Set-up and apply the View Matrix

	D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( camx, 25.0f, camz-10.0f ),
						  &D3DXVECTOR3( camx,  0.0f, camz ),
						  &D3DXVECTOR3( 0.0f,  1.0f, 0.0f ) );

	m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
       
	// Set-up and apply the World Matrix

	D3DXMatrixTranslation( &matWorld, 4.0f, 0.0f, 0.0f );
	m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

        // Render the vertex buffer contents

        m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(CUSTOMVERTEX) );
        m_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );

        m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 5000 );

        // Render the model

	test->Render(m_pd3dDevice);

        // Render stats and help text  

        RenderText();

        // End the scene.

        m_pd3dDevice->EndScene();
    }

    return S_OK;
}
btw, "test" is a CD3DMesh, and i loaded the "tiger.x" model into it ... thats what i'd like to move around the screen ... cant though. i'd appreciate the help thanx SiN [edit] just cleaning up source [/edit] [edited by - SiN on August 6, 2003 8:48:19 PM] [edited by - SiN on August 6, 2003 8:49:23 PM]

Share this post


Link to post
Share on other sites
you are using the correct functions but i dont see you setting up a projection matrix.

heres a little cut and past from one of the basic tutorials with a quick translate tossed in.



D3DXMATRIX matWorld;
D3DXMATRIX matTranslate;
D3DXMATRIX matTemp;


D3DXMatrixIdentity(&matWorld);

D3DXMatrixRotationY( &matTemp, GetTickCount()/1000.0f );
D3DXMatrixTranslation(&matTranslate, -2.0f, 0.0f, 0.0f);
D3DXMatrixMultiply(&matWorld, &matTemp, &matTranslate);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

// Set up our view matrix. A view matrix can be defined given an eye point,

// a point to lookat, and a direction for which way is up. Here, we set the

// eye five units back along the z-axis and up three units, look at the

// origin, and define "up" to be in the y-direction.

D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

// For the projection matrix, we set up a perspective transform (which

// transforms geometry from 3D view space to 2D viewport space, with

// a perspective divide making objects smaller in the distance). To build

// a perpsective transform, we need the field of view (1/4 pi is common),

// the aspect ratio, and the near and far clipping planes (which define at

// what distances geometry should be no longer be rendered).

D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );


Share this post


Link to post
Share on other sites
SiN    122
i already set up the projection matrix in the RestoreDeviceObjects() method ... should i set it up every time when i render the scene or will just once do it ?

and i tried sticking some of ur code into mine, but not much luck ... i mean the thing renders either way (w/ or w/o ur code) but the "test" model is still positioned at 0,0,0 ... i''d like to move it around ...

... help please

SiN

Share this post


Link to post
Share on other sites
thats odd, if you want you can e-mail me what you have to
jmatt@mithralsoft.com and i can take a look at it, from the code you've posted i see no problems so im guessing the problem lies elsewhere. or you can post your code here maybe we can find it. To answer your question, you only have to set your projMatrix once so thats not it, i never used the App wizard so im not sure what your framework looks like. sorry wish i could be of more help.

[edited by - Dreddnafious Maelstrom on August 6, 2003 12:39:49 AM]

Share this post


Link to post
Share on other sites
SiN    122
okay, i modified the code a bit (not too much) ... here, check it out:


HRESULT CMyD3DApplication::Render()
{
// Clear the viewport

m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0x000000ff, 1.0f, 0L );

// Begin the scene

if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
{
D3DXMATRIX matView;
D3DXMATRIX matWorld;


// Render the vertex buffer contents

m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(CUSTOMVERTEX) );
m_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );

m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 5000 );


// Set-up and apply the World Matrix

D3DXMatrixTranslation( &matWorld, 24.0f, 0.0f, 0.0f );
m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );


// Render the test model

test->Render(m_pd3dDevice);


// Set-up and apply the View Matrix

D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( camx, 25.0f, camz-10.0f ),
&D3DXVECTOR3( camx, 0.0f, camz ),
&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );

m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );


// Render stats and help text

RenderText();
m_pFont->DrawText(0, 80, D3DCOLOR_ARGB(255,0,255,0), TEXT("helllllllo?"), 0);


// End the scene.

m_pd3dDevice->EndScene();
}

return S_OK;
}


okay, but what happens now is that the camera (or viewport) moves by -24 points , but not the model. so the "set transform" modified the viewport, instead of moving the model ...

... maybe that might help ... any suggestions?

thanx

SiN

Share this post


Link to post
Share on other sites