# Translating my Camera

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

## Recommended Posts

Hi guys, I'm making good progress with my camera class for my CAD app. I have it rotating about its origin to look at my scene. I also have it translating, though not very accurately. The problem is, when I move away from looking at the origin (down the -z axis) my camera doesn't translate relative to the cameras current view. Eg if I change the camera to looking down the positive z-axis, trying to increment the x co-ordinates to translate the caamera right, now translates it left as I am looking at the x-axis the wrong way around. What I am proposing to do is to create some methods which determine the correct position to translate to. But before I embark on doing this i'm wondering is there any easier way that can save me a lot of hastle? Thanks for any help given!

##### Share on other sites
I had a similar problem for my FPS game that I'm making, ie if i rotate the camera round and tried walking forward then i'd end up walking to the right or whatever. It's simple Trigonometry to get it working. The visual basic code is written below to show you, but the maths is all the same.

      If (gbKeys(vbKeyW) = True) Then        xTrans = xTrans + Sin(-xrot * piover180) * 0.05     ' Move On The X-Plane Based On Player Direction        zTrans = zTrans + Cos(-xrot * piover180) * 0.05      ' Move On The Z-Plane Based On Player Direction      End If      If (gbKeys(vbKeyS) = True) Then        xTrans = xTrans - Sin(-xrot * piover180) * 0.05       ' Move On The X-Plane Based On Player Direction        zTrans = zTrans - Cos(-xrot * piover180) * 0.05      ' Move On The Z-Plane Based On Player Direction      End If      If (gbKeys(vbKeyA) = True) Then        xTrans = xTrans - Sin(-(xrot + 90) * piover180) * 0.05     ' Move On The X-Plane Based On Player Direction        zTrans = zTrans - Cos(-(xrot + 90) * piover180) * 0.05    ' Move On The Z-Plane Based On Player Direction      End If      If (gbKeys(vbKeyD) = True) Then        xTrans = xTrans - Sin(-(xrot - 90) * piover180) * 0.05     ' Move On The X-Plane Based On Player Direction        zTrans = zTrans - Cos(-(xrot - 90) * piover180) * 0.05   ' Move On The Z-Plane Based On Player Direction      End If      End If

Hope this helps

##### Share on other sites
I was thinking of doing something madly stupid. Ur solution seems very clean. Can I ask what type is 'piover180' & what is its purpose? It means 'point of view over 180'?

Thanks!

##### Share on other sites
it's simply the constant Pi

Pi/180

• 40
• 15
• 10
• 23
• 10