minor changes. started writting own 3d math library and started implementation for linux/mac
This commit is contained in:
46
uff.cpp
Normal file
46
uff.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user