Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct vec3{
- float x, y, z;
- vec3(float X, float Y, float Z):
- x(X),
- y(Y),
- z(Z){}
- vec3():
- x(0.0f),
- y(0.0f),
- z(0.0f){}
- vec3(float f):
- x(f),
- y(f),
- z(f){}
- vec3(const vec3 &v):
- x(v.x),
- y(v.y),
- z(v.z){}
- vec3(float a, float b): // Vektor aus Winkeln
- x(float(sin(a))),
- y(float(tan((b-(floor(b/M_PI))*M_PI-M_PI/2)))),
- z(float(cos(a))){}
- float operator[](const int v){
- if(v == 0){
- return x;
- }
- else if(v == 1){
- return y;
- }
- else{
- return z;
- }
- }
- vec3 operator=(const vec3 v){
- x = v.x;
- y = v.y;
- z = v.z;
- return *this;
- }
- vec3 operator+(const vec3 v){
- return vec3(x+v.x, y+v.y, z+v.z);
- }
- vec3 operator+(const float s){
- return vec3(x+s, y+s, z+s);
- }
- vec3 operator-(const vec3 v){
- return vec3(x-v.x, y-v.y, z-v.z);
- }
- vec3 operator-(const float s){
- return vec3(x-s, y-s, z-s);
- }
- vec3 operator*(const vec3 &v){
- return vec3(x*v.x, y*v.y, z*v.z);
- }
- vec3 operator*(const float s){
- return vec3(x*s, y*s, z*s);
- }
- vec3 operator/(const vec3 &v){
- return vec3(x/v.x, y/v.y, z/v.z);
- }
- vec3 operator/(const float s){
- return vec3(x/s, y/s, z/s);
- }
- vec3 operator+=(const vec3 v){
- x += v.x;
- y += v.y;
- z += v.z;
- return *this;
- }
- vec3 operator+=(const float s){
- x += s;
- y += s;
- z += s;
- return *this;
- }
- vec3 operator-=(const vec3 v){
- x -= v.x;
- y -= v.y;
- z -= v.z;
- return *this;
- }
- vec3 operator-=(const float s){
- x -= s;
- y -= s;
- z -= s;
- return *this;
- }
- vec3 operator*=(const vec3 v){
- x *= v.x;
- y *= v.y;
- z *= v.z;
- return *this;
- }
- vec3 operator*=(const float s){
- x *= s;
- y *= s;
- z *= s;
- return *this;
- }
- vec3 operator/=(const vec3 v){
- x /= v.x;
- y /= v.y;
- z /= v.z;
- return *this;
- }
- vec3 operator/=(const float s){
- x /= s;
- y /= s;
- z /= s;
- return *this;
- }
- float length(){
- return sqrtf(dot());
- }
- float dot(){
- return x*x+y*y+z*z;
- }
- float dot(const vec3 v){
- return x*v.x+y*v.y+z*v.z;
- }
- void normalize(){
- float l = length();
- x /= l;
- y /= l;
- z /= l;
- }
- vec3 cross(const vec3 &v){
- x = (y*v.z)-(z*v.y);
- y = (z*v.x)-(x*v.z);
- z = (x*v.y)-(y*v.x);
- return *this;
- }
- vec3 cross(const vec3 &a, const vec3 &b){
- x = (a.y*b.z)-(a.z*b.y);
- y = (a.z*b.x)-(a.x*b.z);
- z = (a.x*b.y)-(a.y*b.x);
- return *this;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement