Files
Visualizer/uff.cpp

46 lines
1.0 KiB
C++

class Vec3 {
public:
float x, y, z;
Vec3(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
}
Vec3 add (Vec3 other) {
Vec3 result (x + other.x, y + other.y, z + other.z);
return result;
}
Vec3 subtract (Vec3 other) {
Vec3 result (x - other.x, y - other.y, z - other.z);
return result;
}
Vec3 scalar (float scalar) {
Vec3 result (x * scalar, y * scalar, z * scalar);
return result;
}
float dot (Vec3 other) {
float result (x * other.x + y * other.y + z * other.z);
return result;
}
Vec3 cross (Vec3 other) {
Vec3 result (y*other.z - z*other.y, z*other.x - x*other.z, x*other.y - y*other.x);
return result;
}
float length () {
float result = sqrt(x*x + y*y + z*z);
return result;
}
Vec3 normalize () {
float len = sqrt(x*x + y*y + z*z);
Vec3 result (x / len, y / len, z / len);
return result;
}
};