View Single Post
Old 06-12-2007, 9:41 PM   #7
Scott Campbell
 
Scott Campbell's Avatar
 
Posts: n/a
My Photos: ()

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Camera Rotation Problem

> "Scott Campbell" <nospam@spiffysoftware.com> wrote in message
> news:bespml$8i89u$1@ID-180785.news.uni-berlin.de...
> > > What did you EXPECT the camera to do when you flipped it upside down,

by
> > > pitching it up over 90 degrees from horizontal?

> >
> > When I pitch up over 90 degrees I would like the view flipped upside

> down...
> > Instead the view is always right way up... The ground is always

underneath
> > me and the sky is always above... Take your view from being inside a

space
> > ship (or something like that). If I was to pitch up over 90 deg, the

> ground
> > would be up, the sky would be down. When I do it with my current code,

> this
> > does not happen. I believe the problem is my look-up vector.
> >
> > D3DXMatrixLookAtRH( &matView, &CameraPos,
> > &LookAt,
> > &D3DXVECTOR3( 0.0f, 0.0f, 1.0f ) );
> >
> > See in this case, the lookup vector is 0, 0, 1.
> >
> > Should I have the lookup vector change from 0, 0, 1 to 0, 0, -1 based on

> the
> > pitch maybe... Or can I have the lookup vector always pointing up from

the
> > camera?

>
> I don't have the Direct3D documentation, so this is educated guesswork,

but
> that looks like it may be the problem.
>
> D3DXMatrixMultiply(&LookAtRot,&LookAtRotX,&LookAtR otY); // Multiply
> rotations
> D3DXVec3TransformCoord(&LookAt,&D3DXVECTOR3(0,40,0 ),&LookAtRot); // What
> is (0,40,0) which you rotate through the camera viewing angles?
>
> LookAt += CameraPos; // ???
>
> D3DXMatrixLookAtRH( &matView, &CameraPos,
> &LookAt,
> &D3DXVECTOR3( 0.0f, 0.0f, 1.0f ) );
>
> // Apparently, (0,0,1) is supposed to give a local vertical orientation.
>
> g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
>
>
> You MIGHT try pushing (0,0,1) through the camera rotation matrix

LookAtRot,
> then feeding that to D3DXMatrixLookAtRH() and see what happens.



Great. It works now. The funny thing is I thought I had tried this method
before and it had failed... Must have been some other changes I made also.

D3DXMATRIX LookAtRotX;
D3DXMATRIX LookAtRotY;
D3DXMATRIX LookAtRot;
D3DXVECTOR3 LookAt;
D3DXVECTOR3 LookUp; //Added variable for LookUp vector.
D3DXVECTOR3 CameraPos(PositionX,PositionY,PositionZ);

D3DXMatrixRotationX(&LookAtRotX,AngleY);
D3DXMatrixRotationZ(&LookAtRotY,AngleX);
D3DXMatrixMultiply(&LookAtRot,&LookAtRotX,&LookAtR otY);
D3DXVec3TransformCoord(&LookAt,&D3DXVECTOR3(0,1,0) ,&LookAtRot); /*
Changed to 1 from 40. Doesn't really matter, but anyway :o) */
D3DXVec3TransformCoord(&LookUp,&D3DXVECTOR3(0,0,1) ,&LookAtRot); /*
LookUp vector is above your head. So rotate it in relation to camera
roatation */

LookAt += CameraPos;

D3DXMatrixLookAtRH( &matView, &CameraPos,
&LookAt,
&LookUp); // Now use the new lookup vector.

g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );


  Reply With Quote