• Advertisement
Sign in to follow this  

Third person camera problem

This topic is 2157 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
If the camera should be looking at around (0, 0, 0), then yes.

Also, what is the value of dt?

Share this post


Link to post
Share on other sites
i put D3DXVECTOR3 vCharPos(0.0f,0.0f,0.0f);
that is going to lock the positon always to that value so i dont think that will work

dt is the timer stuff

Share this post


Link to post
Share on other sites

i put D3DXVECTOR3 vCharPos(0.0f,0.0f,0.0f);
that is going to lock the positon always to that value so i dont think that will work

dt is the timer stuff
Well, your code changes the Z position based on 5.0*dt, so no - it won't lock it to that unless you want it to.

The point is that you cannot have any uninitialised variables anywhere in your code or all bets are off. All varaibles need to be initialised to known values; the exact value they're initialised to depends entirely on your code.

My point about dt was - what is the value of it? Is it 0? 9000.473? Because your fat clip plane is set to 100 units, so you need to make sure everything is within that distance.

Share this post


Link to post
Share on other sites

[quote name='Anddos' timestamp='1332349802' post='4924007']
i put D3DXVECTOR3 vCharPos(0.0f,0.0f,0.0f);
that is going to lock the positon always to that value so i dont think that will work

dt is the timer stuff
Well, your code changes the Z position based on 5.0*dt, so no - it won't lock it to that unless you want it to.

The point is that you cannot have any uninitialised variables anywhere in your code or all bets are off. All varaibles need to be initialised to known values; the exact value they're initialised to depends entirely on your code.

My point about dt was - what is the value of it? Is it 0? 9000.473? Because your fat clip plane is set to 100 units, so you need to make sure everything is within that distance.
[/quote]


if i add D3DXVECTOR3 vCharPos(0.0f,0.0f,0.0f);
and look at the output positon then its locked to the same poistion and its obvious it would do that as its in the render loop

the dt value is ever changing, theres no set value

Share this post


Link to post
Share on other sites
So you now have:

D3DXVECTOR3 vCharPos(0.0f,0.0f,0.0f);
D3DXVECTOR3 vCharFacing(0.0f,0.0f,-1.0f); //facing down -z;
vCharPos.x = 0.0f; vCharPos.y; vCharPos.z -= 5.0f * dt;
Right? Then vCharPos.z is changing based on the value of dt, it shouldn't be locked to the same value.

Share this post


Link to post
Share on other sites
it is because render is in a loop , everytime it loops its going to set z to 0.0f again

Share this post


Link to post
Share on other sites
You said that dt is changing every frame...

Assuming on frame 1, dt=0, frame 2, dt=1, frame 3, dt=2, etc:
Frame 1: vCharPos = (0, 0, 0)
Frame 2: vCharPos = (0, 0, -5)
Frame 3: vCharPos = (0, 0, -10)

Share this post


Link to post
Share on other sites
yes but thats going to get reset on the next frame render if its going back to 0.0f isnt it?

Share this post


Link to post
Share on other sites
Ok, then what does your debugger tell you? You can examine the vCharPos, vAt and vEye variables across a few frames and see how / why they change (or don't change).

Share this post


Link to post
Share on other sites
yes i am sure mFollow is true as in the picture you see its really close up to the plane, i just need to adjust it back or something so i can see the whole of the thing...

Share this post


Link to post
Share on other sites
that problem is sorted now, what i am trying todo next is rotate the camera with mouse, here hows its done for key pressing

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]( GetKeyState( [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]'A'[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] ) < 0 )[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]m_fFacing = [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]float[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]( m_fFacing + m_fSpeedTurn * dTimeDelta ); [/font][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//left[/font][/font][/font]


[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]( GetKeyState( [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]'D'[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] ) < 0 )[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]m_fFacing = [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]float[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]( m_fFacing - m_fSpeedTurn * dTimeDelta ); [/font][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//right[/font][/font][/font]

so now i thought , this would work, its using directx input btw

[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]gDInput->yAngle = gDInput->mouseDX() / 100.0f;[/font][/font][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"] m_fFacing = float( m_fFacing + gDInput->yAngle * m_fSpeedTurn * dTimeDelta ); //left[/font][/font][/font]


[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]m_fFacing = float( m_fFacing - gDInput->yAngle * m_fSpeedTurn * dTimeDelta ); //right[/font][/font][/font]

Share this post


Link to post
Share on other sites
Yup, that looks fine. Although gDInput->mouseDX should give negative values if the mouse is moved to the left, and positive values if it's moved to the right.

Share this post


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

  • Advertisement