#include "vec.h" #include <stdio.h> #include <math.h> Vec::Vec(float vx, float vy, float vz) { c[0] = vx; c[1] = vy; c[2] = vz; } Vec::Vec(Vec* v) { Vec(v->x(), v->y(), v->z()); } float Vec::x() { return c[0]; } float Vec::y() { return c[1]; } float Vec::z() { return c[2]; } float* Vec::getCoords() { return c; } Vec Vec::operator+(Vec* v) { return Vec(x() + v->x(), y() + v->y(), z() + v->z()); } Vec Vec::operator+(Vec v) { return Vec(x() + v.x(), y() + v.y(), z() + v.z()); } void Vec::add(Vec& a) { c[0] += a.x(); c[1] += a.y(); c[2] += a.z(); } Vec Vec::operator-(Vec& v) { return Vec(x() - v.x(), y() - v.y(), z() - v.z()); } Vec Vec::operator*(float s) { Vec r = Vec(x()*s, y()*s, z()*s); return r; } Vec Vec::operator*(Vec& s) { return Vec(x()*s.x(), y()*s.y(), z()*s.z()); } Vec Vec::operator/(float s) { return Vec(x()/s, y()/s, z()/s); } Vec Vec::cross(Vec* v) { return Vec(y() * v->z() - z() * v->y(), z() * v->x() - x() * v->z(), x() * v->y() - y() * v->x()); } Vec Vec::normalize() { return *this * (1 / length()); } float Vec::length() { return sqrt(x()*x()+y()*y()+z()*z()); } void Vec::print() { printf (" vektor: %f, %f, %f\n", x(), y(), z()); } Vec* Vec::clone() { return new Vec(x(), y(), z()); }