2011-12-15 13 views
0

三人称カメラには言語以外のアルゴリズムが必要です。何が問題になっているのかは、カメラをオブジェクトの後ろに置き、カメラの回転をオブジェクトの回転と同じに保つ方法です。何か案は?三角法三次元三人カメラアルゴリズム

例:

UpdateCamera(camera, target){ 
    offset = vector(0,height,distance); 
    cameraPos = targetPos+offset; 
    camAngle = ?????; 
} 

私は、それは単純だが、あなたはそれの要点を得るでしょうイムていることを確認してはならないことを知っています。その絶対的な最も単純で

+0

3人目のカメラは、StackOverflowの答えで完全に説明するのはかなり複雑です。「3Dゲーム:リアルタイムレンダリングとソフトウェアテクノロジ」と「3Dゲーム:アニメーションと高度なリアルタイムレンダリング "しかし、私はそれを行う方法のまともな記述を含むそれらのいずれかを覚えています。 –

+0

ここをクリックしてください:http://www.amazon.co.uk/Games-Real-Time-Rendering-Technology-Real-time/dp/0201619210およびhttp://www.amazon.co.uk/3D-Games-アニメーション - リアルタイムレンダリング/ dp/0201787067 –

+0

答えをいただきありがとうございます...私は完全な第三者のカメラはかなり広範であることを理解していますが、カメラのピボットポイントとしてターゲットを使用するとどうなりますか?それは自己があまりにも広範であるように見えないが、それはちょうど私が素朴であるかもしれない。 – ddan

答えて

0

、あなたはこのような単純なNUVカメラクラスがあるとします。今

/// <summary> 
/// An instance of this class represents a camera for a 3D view. 
/// Cameras are defined with a position and three mutually-orthogonal 
/// axes, namely N (points in the direction faced by the camera), 
/// U (points to the left of the camera) and V (points to the top 
/// of the camera). 
/// </summary> 
sealed class Camera 
{ 
    //#################### PRIVATE VARIABLES #################### 
    #region 

    private Vector3 m_n; 
    private Vector3 m_position; 
    private Vector3 m_u; 
    private Vector3 m_v; 

    #endregion 

    //#################### PROPERTIES #################### 
    #region 

    /// <summary> 
    /// The position of the camera. 
    /// </summary> 
    public Vector3 Position { get { return m_position; } } 

    /// <summary> 
    /// A vector pointing in the direction faced by the camera. 
    /// </summary> 
    public Vector3 N { get { return m_n; } } 

    /// <summary> 
    /// A vector pointing to the left of the camera. 
    /// </summary> 
    public Vector3 U { get { return m_u; } } 

    /// <summary> 
    /// A vector pointing to the top of the camera. 
    /// </summary> 
    public Vector3 V { get { return m_v; } } 

    #endregion 

    //#################### CONSTRUCTORS #################### 
    #region 

    /// <summary> 
    /// Constructs a new camera. 
    /// </summary> 
    /// <param name="position">The position of the camera.</param> 
    /// <param name="look">A vector pointing in the direction faced by the camera.</param> 
    /// <param name="up">The "up" direction for the camera.</param> 
    public Camera(Vector3 position, Vector3 look, Vector3 up) 
    { 
     m_position = position; 

     m_n = look; 
     m_n.Normalize(); 

     m_v = up; 
     m_v.Normalize(); 

     m_u = Vector3.Cross(m_v, m_n); 
     m_u.Normalize(); 
    } 

    #endregion 

    //#################### PUBLIC METHODS #################### 
    #region 

    /// <summary> 
    /// Moves the camera by the specified displacement in the n direction. 
    /// </summary> 
    /// <param name="delta">The displacement by which to move.</param> 
    public void MoveN(float delta) 
    { 
     m_position += delta * m_n; 
    } 

    /// <summary> 
    /// Moves the camera by the specified displacement in the u direction. 
    /// </summary> 
    /// <param name="delta">The displacement by which to move.</param> 
    public void MoveU(float delta) 
    { 
     m_position += delta * m_u; 
    } 

    /// <summary> 
    /// Moves the camera by the specified displacement in the v direction. 
    /// </summary> 
    /// <param name="delta">The displacement by which to move.</param> 
    public void MoveV(float delta) 
    { 
     m_position += delta * m_v; 
    } 

    /// <summary> 
    /// Rotates the camera anticlockwise by the specified angle about the specified axis. 
    /// </summary> 
    /// <param name="axis">The axis about which to rotate.</param> 
    /// <param name="angle">The angle by which to rotate (in radians).</param> 
    public void Rotate(Vector3 axis, float angle) 
    { 
     // Note: We try and optimise things a little by observing that there's no point rotating an axis about itself. 
     if(axis != m_n) m_n = MathUtil.RotateAboutAxis(m_n, angle, axis); 
     if(axis != m_u) m_u = MathUtil.RotateAboutAxis(m_u, angle, axis); 
     if(axis != m_v) m_v = MathUtil.RotateAboutAxis(m_v, angle, axis); 
    } 

    #endregion 
} 

、各フレーム:

1)は、位置ppとプレイヤーの方向pdirを取得します。
2)位置= pp - offset * pdir、見た目= pdir、上=賢明なもの(例:(0,0,1))でカメラを再作成します。

+0

すごく、ありがとう。 – ddan