Table of Contents

Summary

Calculates the position of an object orbiting a point, given the rotation centre, the radius of rotation, and the horizontal and vertical angles involved.

Tips

This method is very useful for doing third-person and first-person movement. Examples:

Third person

  • Let horiz_angle = your left-right look angle
  • Let vert_angle = your up-down look angle
  • Let radius = how far you want your camera away from your player
  • Let player_position = your player’s position, as a 3d vector
  • Let camera_position = your camera’s position, as a 3d vector

camera_position = MoveAroundPoint( player_position, radius, horiz_angle, vert_angle )

Scene.SetCamera( camera_position.x, camera_position.y, camera_position.z, player_position.x, player_position.y, player_position.z )

First person

  • Let horiz_angle = your left-right look angle
  • Let vert_angle = your up-down look angle
  • Let player_position = your player’s position, as a 3d vector
  • Let look_vector = a 3d vector, the return variable

look_vector = MoveAroundPoint( player_position, 1, horiz_angle, vert_angle )

Scene.SetCamera( player_position.x, player_position.y, player_position.z, player_position.x + look_vector.x, player_position.y + look_vector.y, player_position.z + look_vector.z )

Source Snippet

If you like to make your own MoveAroundPoint function...

    Public Function MoveAroundPoint( vecPosition As D3DVector, Radius As Float, AlphaV As Float, AlphaH As Float ) As D3DVector
        'Translate angles to radians...
        AlphaV = PI * (AlphaV / 180.0)
        AlphaH = PI * (AlphaH / 180.0)
        'Get the world point...
        MoveAroundPoint.x = vecPosition.x + (cos( AlphaH ) * cos( AlphaV ) * Radius)
        MoveAroundPoint.y = vecPosition.y - (sin( AlphaV ) * Radius)
        MoveAroundPoint.z = vecPosition.z + (sin( AlphaH ) * cos( AlphaV ) * Radius)
    End Function
 
movearoundpoint.txt · Last modified: 2013/11/22 13:31