Vec3

vec3.png

List of pages tagged with vec3:

#ifndef MIFFYVEC3
#define MIFFYVEC3
namespace miffy{
template <typename T>
    struct vec3{//計算用の頂点構造体
        T x;
        T y;
        T z;
        vec3(){}
        vec3(T _x,T _y,T _z):x(_x),y(_y),z(_z){}
        vec3<T> operator=(const vec3<T>& _in){
            x=_in.x;
            y=_in.y;
            z=_in.z;
            return *this;
        }
        vec3<T> operator=(const T _in){
            x=_in;
            y=_in;
            z=_in;
            return *this;
        }
        vec3<T> operator*(const T& _in){
            return vec3<T>(x*_in,y*_in,z*_in);
        }
        vec3<T> operator-(const vec3<T>& _in){
            return vec3<T>(x-_in.x,y-_in.y,z-_in.z);
        }
        vec3<T> operator*(const vec3<T>& _in){
            return vec3<T>(x*_in.x,y*_in.y,z*_in.z);
        }
        vec3<T> operator+(const vec3<T>& _in){
            return vec3<T>(x+_in.x,y+_in.y,z+_in.z);
        }
        vec3<T> operator+=(const vec3<T>& _in){
            x+=_in.x;
            y+=_in.y;
            z+=_in.z;
            return *this;
        }
        vec3<T> operator*=(const T _in){
            x*=_in;
            y*=_in;
            z*=_in;
            return *this;
        }
        vec3<T> operator*=(const vec3<T>& _in){
            x*=_in.x;
            y*=_in.y;
            z*=_in.z;
            return *this;
        }
        vec3<T> operator+(const T _in){
            return vec3<T>(x+_in,y+_in,z+_in);
        }
        vec3<T> operator-(const T& _in){
            return vec3<T>(x-_in,y-_in,z-_in);
        }
        vec3<T> operator/(const vec3<T>& _in){
            return vec3<T>(x/_in.x,y/_in.y,z/_in.z);
        }
        vec3<T> operator/(const T& _in){
            return vec3<T>(x/_in,y/_in,z/_in);
        }
        vec3<T> cross(const vec3<T>& _in){//外積実装するぞ
            return (vec3<T>(y*_in.z-z*_in.y, z*_in.x-x*_in.z, x*_in.y-y*_in.x));
        }
        void set(T _x,T _y,T _z){x=_x;y=_y;z=_z;}
        void normalize(){
            T length=sqrt(x*x+y*y+z*z);
            if(length!=0.0){
                x/=length;
                y/=length;
                z/=length;
            }
        }
        T length(){return sqrt((double)(x*x+y*y+z*z));}
#ifdef  __FREEGLUT_H__
        void glVertex(){
            glVertex3f(x,y,z);
        }
#endif
#ifdef _INC_STDIO
        void print(){
            printf("%f,%f,%f\n",x,y,z);
        }
#endif
    };
}
#endif

サポートサイト Wikidot.com