# moving in the dir you're lookin....

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

## Recommended Posts

Hi Ok this is the simpliest question i have ever asked in this forum but i don't understand why adding the ViewDir multiplied by a certain amount to the position doesn't move the position along the ViewDirection...my code looks like this: D3DXVECTOR3 ViewDir; ViewDir=Cam.LookAt-Cam.Pos; ViewDir=ViewDir/sqrtf(ViewDir.x*ViewDir.x+ ViewDir.y*ViewDir.y+ ViewDir.z*ViewDir.z); if(SysKeyboard.GetKeyState(DIK_W))Cam.Pos+=ViewDir*0.001f; but i just get some strange flickering...i noticed that this flickering occurs because 1frame my triangles appear and in the next frame the triangles are gone... btw i thought that probably the D3DXVec3Normalize() function does sth wrong that's why i wrote the normalisation myself.. regards, m4gnus

##### Share on other sites
That should work fine - although you will not move far with 0.001f as your scaler, perhaps the problem is elsewhere?

##### Share on other sites
don't know...looking arounf works fine so lookat seems fine...earlier i simply moved the pos on the x and z axis for moving around and that also worked fine...so i don't know where the prob could be...but i'll post my (very simple) gameloop:
while(true) {if(!Engine.DoMsgLoop()) break;Engine.render();SetCursorPos(512,380);D3DXVECTOR3 ViewDir;ViewDir=Cam.LookAt-Cam.Pos;ViewDir=ViewDir/sqrtf(ViewDir.x*ViewDir.x+					  ViewDir.y*ViewDir.y+					  ViewDir.z*ViewDir.z);if(SysKeyboard.GetKeyState(DIK_W))Cam.Pos+=ViewDir*0.001f;if(SysKeyboard.GetKeyState(DIK_S))Cam.Pos.x-=0.1f;if(SysKeyboard.GetKeyState(DIK_A))Cam.Pos.z+=0.1f;if(SysKeyboard.GetKeyState(DIK_D))Cam.Pos.z-=0.1f;/*if(SysKeyboard.GetKeyState(DIK_W))Cam.LookAt.x+=0.1f;if(SysKeyboard.GetKeyState(DIK_S))Cam.LookAt.x-=0.1f;if(SysKeyboard.GetKeyState(DIK_A))Cam.LookAt.z+=0.1f;if(SysKeyboard.GetKeyState(DIK_D))Cam.LookAt.z-=0.1f;*/SysMouse.GetState(&xMouse,&yMouse);x-=xMouse/fInvXSens;y-=yMouse/fInvYSens;Cam.LookAt.y=sin(y);Cam.LookAt.x=cos(x);if(SysKeyboard.GetKeyState(DIK_ESCAPE))break;

 ok i think the mistake is that i don't change LookAt while moving around... but changing it the same way i change my position does not work...LookAt get's totally messed up after some moving around[/edit]
regards,
m4gnus

##### Share on other sites
Yes, hence it is a better idea to abandon the 'look at' concept of modelling a camera and instead use the other method of up, right, and look vectors (forming an axis) that can then be rotated to orientate the camera and used to create a view matrix from. It is much easier to code and work with. As an aside you can then move more easily e.g.

// move forward
cameraPos+=m_look*speed;

// move backward
cameraPos-=m_look*speed;

// move right
cameraPos+=m_right*speed;

// move left
cameraPos-=m_right*speed;

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5
JoeJ
13

• 9
• 14
• 10
• 25
• 9
• ### Forum Statistics

• Total Topics
632645
• Total Posts
3007628
• ### Who's Online (See full list)

There are no registered users currently online

×