Jump to content
  • Advertisement
Sign in to follow this  
Cacks

Translating my Camera

This topic is 4703 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 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!