Jump to content
  • Advertisement
Sign in to follow this  
Anddos

Third person camera problem

This topic is 2335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

[attachment=7830:plane.jpg]

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); // set the material for the subset
if(texture != NULL) // if the subset has a texture (if texture is not NULL)
d3ddev->SetTexture(0, texture); // ...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;
}

Share this post


Link to post
Share on other sites
Advertisement

Yes. What if you change it to e.g. vEye -= vCharFacing*5 ?


if i do vEye -= vCharFacing*1

it stays the same if i do anything over that it goes out of sight

Share this post


Link to post
Share on other sites
[source]
D3DXVECTOR3 vCharPos; //
D3DXVECTOR3 vCharFacing(0.0f,0.0f,-1.0f); //facing down -z;
vCharPos.x = 0.0f; vCharPos.y; vCharPos.z -= 5.0f * dt;
[/source]
vCharPos.y and vCharPos.z are uninitialised. I'm surprised your compiler isn't warning you about that...

Share this post


Link to post
Share on other sites
That should be fine, any other idea's how to pull the camera back so i can see the whole plane..

Share this post


Link to post
Share on other sites
Why should it be fine? The variables contain garbage data, so any references to them will have undefined results.

What do you think the value of vCharPos.z is?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!