Jump to content


D3DX9 Third person camera problem


  • You cannot reply to this topic
No replies to this topic

#1 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 177 posts

Posted 21 March 2012 - 05:18 PM

I cant seem to figure out how to make how to view the whole of the plane and not just right close it to , if you look at the DirectX sample MultiAnimation i want it like that, thats where i got this code from btw, if anyone can help with this problem that would be great.

picure of what i seee

Posted Image

render code
void render_frame(void)
{
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
	d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	d3ddev->BeginScene();

	D3DXVECTOR3 vCharPos; //
	D3DXVECTOR3 vCharFacing(0.0f,0.0f,-1.0f); //facing down -z;
	vCharPos.x = 0.0f; vCharPos.y; vCharPos.z  -= 5.0f * dt;
	// SET UP THE TRANSFORMS
	
	D3DXMATRIX matView;	// the view transform matrix
	D3DXMATRIX mScale;

	if(mFollow)
	{
	//Third person Camera
	
	D3DXVECTOR3 vEye;
	vEye = D3DXVECTOR3( vCharPos.x, 0.25f, vCharPos.z ); //0.25f
	D3DXVECTOR3 vAt	 ( vCharPos.x, 0.0125f, vCharPos.z), //0.0125f
				vUp	 ( 0.0f, 1.0f, 0.0f );
			
	//vCharFacing.x *= .25; vCharFacing.y = 0.f; vCharFacing.z *= .25; //z  = .25f y = 0.f
	vEye -= vCharFacing;
	vAt += vCharFacing;

	D3DXMatrixLookAtLH( &matView, &vEye, &vAt, &vUp );
	d3ddev->SetTransform( D3DTS_VIEW, &matView);
	}
	else
	{
		D3DXMatrixLookAtLH(&matView,
		&D3DXVECTOR3 (0.0f, 8.0f, 16.0f),	// the camera position
		&D3DXVECTOR3 (0.0f, 0.0f, 0.0f),	// the look-at position
		&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));	// the up direction
		d3ddev->SetTransform(D3DTS_VIEW, &matView);	// set the view transform to matView
	}

	D3DXMATRIX matProjection;	// the projection transform matrix
	D3DXMatrixPerspectiveFovLH(&matProjection,
							   D3DXToRadian(45),	// the horizontal field of view
							   SCREEN_WIDTH / SCREEN_HEIGHT,	// the aspect ratio
							   0.1f,	// the near view-plane
							   100.0f);	// the far view-plane
	d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);	// set the projection
	

	//static float index = 0.0f; index+=0.03f;	// an ever-increasing float value
	
	D3DXMATRIX matRotateY,matTrans;	// a matrix to store the rotation for each triangle
	//D3DXMatrixRotationY(&matRotateY, index);	// the rotation matrix
	D3DXMatrixTranslation(&matTrans,0.0f,0.0f,vCharPos.z);
	D3DXMatrixScaling(&mScale,-0.01f,-0.01f,-0.01f);
	d3ddev->SetTransform(D3DTS_WORLD, &(matTrans));	// set the world transform


	  // draw the spaceship
	for(DWORD i = 0; i < numMaterials; i++)	// loop through each subset
	{
		d3ddev->SetMaterial(&material[i]);	// set the material for the subset
		if(texture[i] != NULL)	// if the subset has a texture (if texture is not NULL)
			d3ddev->SetTexture(0, texture[i]);	// ...then set the texture

		meshSpaceship->DrawSubset(i);	// draw the subset
	}

	//calculate fps
	sprintf(outBuffer,"Frames Per Second = %.2f\n",FPS);
	dxfont->DrawTextA(NULL,
					  outBuffer,
					  strlen(outBuffer),
					  NULL,
					  NULL,//DT_CENTER | DT_VCENTER,
					  D3DCOLOR_ARGB(255, 255, 0, 0));

	d3ddev->EndScene();

	d3ddev->Present(NULL, NULL, NULL, NULL);

	return;
}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users