vector.hpp

来自「The goal of this project is to explore t」· HPP 代码 · 共 62 行

HPP
62
字号
#if !defined(BRL_VECTOR_HPP)
#define BRL_VECTOR_HPP
/*+-------------------------------------------------------------------
  Vector.hpp

  A 3D vector class that is suitable for use with the corresponding
  Point class in Point.hpp.  
  
*/

class Vector
{
private:
    float m_x; 
    float m_y;
    float m_z;

public:
    Vector (void); 
    Vector (const Vector& vec);
    Vector (float x, float y, float z);
    ~Vector ();
  
    const Vector& operator=(const Vector& vec);
  
    // operator *  with another Vector means cross product.
    Vector operator* (const Vector& vec) const;

    // operator * with a scalar is scalar multiplication.
    Vector operator* (float t) const;
  
    // A vector minus another vector yields another vector.
    Vector operator- (const Vector& vec) const;
    
    // Friend function that does the same thing as
    // the scalar version of operator*. This is so
    // t * vec works as well as vec * t.
    friend Vector operator*(float t, const Vector& vec);
  
    void set (float x, float y, float z);
  
    float x (void) const {return m_x;}
    float y (void) const {return m_y;}
    float z (void) const {return m_z;}
  
    void normalize (void);
  
    float length (void) const;
  
    void set_length (float len);
  
    static Vector interpolate (const Vector& A, float t, const Vector& B);
    
    float dot (const Vector& vec); // compute the dot product

    void get_perpendicular_vector (Vector& vec) const;
};

Vector operator*(float t, const Vector& vec);

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?