2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-07-19 12:34:11 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2010-07-19 12:34:11 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include "Common/ChunkFile.h"
|
2010-07-19 12:34:11 +00:00
|
|
|
|
|
|
|
class Vec3
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
float x,y,z;
|
|
|
|
Vec3() { }
|
|
|
|
explicit Vec3(float f) {x=y=z=f;}
|
|
|
|
explicit Vec3(const float *f) {x=f[0]; y=f[1]; z=f[2];}
|
|
|
|
Vec3(const float _x, const float _y, const float _z) {
|
|
|
|
x=_x; y=_y; z=_z;
|
|
|
|
}
|
|
|
|
void set(const float _x, const float _y, const float _z) {
|
|
|
|
x=_x; y=_y; z=_z;
|
|
|
|
}
|
|
|
|
Vec3 operator + (const Vec3 &other) const {
|
|
|
|
return Vec3(x+other.x, y+other.y, z+other.z);
|
|
|
|
}
|
|
|
|
void operator += (const Vec3 &other) {
|
|
|
|
x+=other.x; y+=other.y; z+=other.z;
|
|
|
|
}
|
|
|
|
Vec3 operator -(const Vec3 &v) const {
|
|
|
|
return Vec3(x-v.x,y-v.y,z-v.z);
|
|
|
|
}
|
|
|
|
void operator -= (const Vec3 &other)
|
|
|
|
{
|
|
|
|
x-=other.x; y-=other.y; z-=other.z;
|
|
|
|
}
|
|
|
|
Vec3 operator -() const {
|
|
|
|
return Vec3(-x,-y,-z);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vec3 operator * (const float f) const {
|
|
|
|
return Vec3(x*f,y*f,z*f);
|
|
|
|
}
|
|
|
|
Vec3 operator / (const float f) const {
|
|
|
|
float invf = (1.0f/f);
|
|
|
|
return Vec3(x*invf,y*invf,z*invf);
|
|
|
|
}
|
|
|
|
void operator /= (const float f)
|
|
|
|
{
|
|
|
|
*this = *this / f;
|
|
|
|
}
|
|
|
|
float operator * (const Vec3 &other) const {
|
|
|
|
return x*other.x + y*other.y + z*other.z;
|
|
|
|
}
|
|
|
|
void operator *= (const float f) {
|
|
|
|
*this = *this * f;
|
|
|
|
}
|
|
|
|
Vec3 scaled_by(const Vec3 &other) const {
|
|
|
|
return Vec3(x*other.x, y*other.y, z*other.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vec3 operator %(const Vec3 &v) const {
|
|
|
|
return Vec3(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
|
2013-10-29 05:23:17 +00:00
|
|
|
}
|
2010-07-19 12:34:11 +00:00
|
|
|
float length2() const {
|
|
|
|
return x*x+y*y+z*z;
|
|
|
|
}
|
|
|
|
float length() const {
|
|
|
|
return sqrtf(length2());
|
|
|
|
}
|
|
|
|
float distance2_to(Vec3 &other)
|
|
|
|
{
|
|
|
|
return (other-(*this)).length2();
|
|
|
|
}
|
|
|
|
Vec3 normalized() const {
|
|
|
|
return (*this) / length();
|
|
|
|
|
|
|
|
}
|
|
|
|
void normalize() {
|
|
|
|
(*this) /= length();
|
|
|
|
}
|
|
|
|
float &operator [] (int i)
|
|
|
|
{
|
|
|
|
return *((&x) + i);
|
|
|
|
}
|
2010-08-01 16:14:35 +00:00
|
|
|
float operator [] (const int i) const
|
2010-07-19 12:34:11 +00:00
|
|
|
{
|
|
|
|
return *((&x) + i);
|
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
bool operator == (const Vec3 &other) const
|
2010-07-19 12:34:11 +00:00
|
|
|
{
|
|
|
|
if (x==other.x && y==other.y && z==other.z)
|
|
|
|
return true;
|
2013-10-29 05:23:17 +00:00
|
|
|
else
|
2010-07-19 12:34:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void setZero()
|
|
|
|
{
|
|
|
|
memset((void *)this,0,sizeof(float)*3);
|
|
|
|
}
|
2013-02-26 04:49:24 +00:00
|
|
|
void DoState(PointerWrap &p)
|
|
|
|
{
|
|
|
|
p.Do(x);
|
|
|
|
p.Do(y);
|
|
|
|
p.Do(z);
|
|
|
|
}
|
2010-07-19 12:34:11 +00:00
|
|
|
};
|