就196分了,orz

解决方案 »

  1.   

    去定火车票,明天晚上去杭州,go my way!
      

  2.   


    那帖子lfchen提议了下,也没见有人响应啊,估计只是个想法
      

  3.   

    到CSDN来格式化个代码,orzclass Vector3
    {
    public:
    float x,y,z; //缺省构造函数
    Vector3();
    //拷贝构造函数
    Vector3(const Vector3 &a):x(a.x),y(a.y),z(a.z){}
    //带参的构造函数
    Vector3(float nx,float ny,float nz):x(nx),y(ny),z(nz){} //重载赋值操作符
    Vector3 &operator =(const Vector3 &a)
    {
    x = a.x;
    y = a.y;
    z = a.z;
    return *this;
    } //重载==操作符
    bool operator ==(const Vector3 &a) const
    {
    return x==a.x && y==a.y && z==a.z;
    } //重载!=操作符
    bool operator !=(const Vector3 &a) const
    {
    return x!=a.x || y!=a.y || z!=a.z;
    } //向量运算 //零向量
    void zero() 
    {
    x = y = z = 0.0f;
    }
    //向量求负
    Vector3 operator - ()const 
    {
    return Vector3(-x,-y-z);
    }
    //向量加减法
    Vector3 operator + (const Vector3 &a) const
    {
    return Vector3(x+a.x,y+a.y,z+a.z);
    }
    Vector3 operator - (const Vector3 &a) const
    {
    return Vector3(x-a.x,y-a.y,z-a.z);
    }
    //向量与标量的乘除法
    Vector3 operator *(float a) const
    {
    return  Vector3(x*a,y*a,z*a);
    }
    Vector3 operator /(float a) const
    {
    ASSERT(a!=0.0f);
    float reverse = 1.0f / a;
    return  Vector3(x*reverse,y*reverse,z*reverse);
    }
    //重载复合运算操作符
    Vector3 *operator +=(const Vector3 &a)
    {
    x += a.x;
    y += a.y;
    z += a.z;
    return *this;
    }
    Vector3 *operator +=(const Vector3 &a)
    {
    x += a.x;
    y += a.y;
    z += a.z;
    return *this;
    }
    Vector3 *operator -=(const Vector3 &a)
    {
    x -= a.x;
    y -= a.y;
    z -= a.z;
    return *this;
    }
    Vector3 *operator *=(float a)
    {
    x *= a;
    y *= a;
    z *= a;
    return *this;
    }
    Vector3 *operator /=(float a)
    {
    ASSERT(a!=0.0f);
    float reverse = 1.0f / a;
    x *= reverse;
    y *= reverse;
    z *= reverse;
    return *this;
    }
    //向量归一
    void normalize()
    {
    float magSq = x*x+y*y+z*z;
    if(magSq > 0.0f)
    {
    float reverse = 1.0f / a;
    x *= reverse;
    y *= reverse;
    z *= reverse;
    }
    }
    //向量点乘
    float operator *(const Vector3 &a) const
    {
    return x*a.x + y*a.y + z*a.z;
    }
    };//就地展开运算//求模
    inline float vectorMag(const Vector3 &a)
    {
    return sqrt(a.x*a.x,a.y*a.y+a.z*a.z);
    }
    //叉乘
    inline Vector3 crossProduct(const Vector3 &a,const Vector3 &b)
    {
    return Vector3(a.y*b.z - a.z*b.y,
    a.z*b.x - a.x*b.z,
    a.x*b.y - a.y*b.x);
    }
    //标量左乘
    inline Vector3 operator *(float k,const Vector3 &v)
    {
    return Vector3(k*v.x,k*v.y,k*v.z);
    }
    //两点距离
    inline float distance(const Vector3 &a,const Vector3 &b)
    {
    float dx = a.x - b.x;
    float dy = a.y - b.y;
    float dz = a.z - b.z;
    return sqrt(dx*dx,dy*dy,dz*dz);
    }extern const Vector3 g_ZeroVector;