| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include "Vector.h"
- Vec3f::Vec3f(float x, float y, float z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- /*The length of the vector*/
- float Vec3f::Length()
- {
- return (float)sqrt(x*x+y*y+z*z);
- }
- float Vec3f::Distance(const Vec3f &other)
- {
- return (float)sqrt(pow(other.x - x, 2)+pow(other.y - y, 2)+pow(other.z - z, 2));
- }
- Vec3f::Vec3f()
- {
- this->x = 0;
- this->y = 0;
- this->z = 0;
- }
- Vec3f::Vec3f(Vec3f &other)
- {
- this->x = other.x;
- this->y = other.y;
- this->z = other.z;
- }
- float& Vec3f::operator [](int index)
- {
- return v[index];
- }
- Vec3f Vec3f::operator+(const Vec3f & other)
- {
- return Vec3f(x + other.x, y + other.y, z + other.z);
- }
- Vec3f Vec3f::operator/(float value)
- {
- return Vec3f(x / value, y / value, z / value);
- }
- bool Vec3f::operator==(const Vec3f & other)
- {
- /*bool xb, yb,zb;
- xb = x == other.x;
- yb = y == other.y;
- zb = z == other.z;
- if (xb & yb & zb)
- return true;*/
- return x == other.x & y == other.y & z == other.z;
- }
- bool Vec3f::operator!=(const Vec3f & other)
- {
- return x != other.x & y != other.y & z != other.z;
- }
- Vec2f::Vec2f(float x, float y)
- {
- this->x = x;
- this->y = y;
- }
- Vec2f::Vec2f()
- {
- this->x = 0;
- this->y = 0;
- }
- Vec2f::Vec2f(Vec2f &other)
- {
- this->x = other.x;
- this->y = other.y;
- }
- float& Vec2f::operator [](int index)
- {
- return v[index];
- }
- Vec2f Vec2f::operator+(const Vec2f & other)
- {
- return Vec2f(x + other.x, y+other.y);
- }
- float Vec2f::length()
- {
- return (float)sqrt(x*x + y*y);
- }
|