Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

DirectX Tutorial 3 - DXUT

Started by slugonamission May 24, 2006 at 9:23 AM 0 replies 2.2k views
Original Post
slugonamission
slugonamission
OK, ive managed to port tutorial 2 to DXUT (im using the feb 2006 SDK, unmanaged), the problem comes with the matrices Basically, i used the simplesample, and my current render code is this
HRESULT hr;
	D3DXMATRIXA16 mWorld;
	D3DXMATRIXA16 mView;
	D3DXMATRIXA16 mProj;
	D3DXMATRIXA16 mWorldViewProjection;

	//If the settings dlg is shown, render that instead of the scene
	if(g_SettingsDlg.IsActive())
	{
		g_SettingsDlg.OnRender(fElapsedTime);
		return;
	}

	//Clear the render target and Z buffer
	V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0,0,0,255), 1.0f, 0));

	//Render the scene
	if (SUCCEEDED( pd3dDevice->BeginScene()))
	{
		//Get view and projection from camera class
		mWorld = *g_Camera.GetWorldMatrix();
		mView = *g_Camera.GetViewMatrix();
		mProj = *g_Camera.GetProjMatrix();

		mWorldViewProjection = mWorld * mView * mProj;

		//Update the effect variables
		V( g_pEffect->SetMatrix("g_mWorldViewProjection", &mWorldViewProjection));
		V( g_pEffect->SetMatrix("g_mWorld", &mWorld));
		V( g_pEffect->SetFloat("g_fTime", (float)dTime));

		DXUT_BeginPerfEvent(DXUT_PERFEVENTCOLOR, L"HUD / Stats"); //these events help PIX identify what the code is doing
		RenderText();
		V( g_HUD.OnRender(fElapsedTime));
		V( g_SampleUI.OnRender(fElapsedTime));
		DXUT_EndPerfEvent();

		//Render our triangle :D
		pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX));
		pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
		pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

		V( pd3dDevice->EndScene());
	}
}
Now, since there is already some vertex transforms for the camera, how would i go about integrating

// For our world matrix, we will just rotate the object about the y-axis.
    D3DXMATRIXA16 matWorld;

    // Set up the rotation matrix to generate 1 full rotation (2*PI radians) 
    // every 1000 ms. To avoid the loss of precision inherent in very high 
    // floating point numbers, the system time is modulated by the rotation 
    // period before conversion to a radian angle.
    UINT  iTime  = timeGetTime() % 1000;
    FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;
    D3DXMatrixRotationY( &matWorld, fAngle );
    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 );
Im just curious as to if the code in the second exert would intefere with the first (i.e. do we still need the view and projection matrices as they are defined in the camera in the DXUT sample?) Thanks in advance and sorry if that was very confusing lol ~Slug

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.