1
0
Fork 0

Merge remote-tracking branch 'xdot/master'

This commit is contained in:
madmaxoft 2014-03-12 14:42:04 +01:00
commit f2df33f746
35 changed files with 546 additions and 632 deletions

View File

@ -11,6 +11,7 @@ typedef unsigned int UInt32;
typedef unsigned short UInt16;
$cfile "../Vector3.h"
$cfile "../ChunkDef.h"
$cfile "../BiomeDef.h"
@ -62,10 +63,6 @@ $cfile "../BlockEntities/MobHeadEntity.h"
$cfile "../BlockEntities/FlowerPotEntity.h"
$cfile "../WebAdmin.h"
$cfile "../Root.h"
$cfile "../Vector3f.h"
$cfile "../Vector3d.h"
$cfile "../Vector3i.h"
$cfile "../Matrix4f.h"
$cfile "../Cuboid.h"
$cfile "../BoundingBox.h"
$cfile "../Tracer.h"
@ -97,4 +94,10 @@ typedef unsigned char Byte;
// Aliases
$renaming Vector3<double> @ Vector3d
$renaming Vector3<float> @ Vector3f
$renaming Vector3<int> @ Vector3i

View File

@ -29,6 +29,8 @@ extern "C"
#include "lua/src/lauxlib.h"
}
#include "../Vector3.h"
@ -52,7 +54,6 @@ class cWebAdmin;
struct HTTPTemplateRequest;
class cTNTEntity;
class cCreeper;
class Vector3i;
class cHopperEntity;
class cBlockEntity;

View File

@ -13,13 +13,13 @@
#pragma once
#include "ForEachChunkProvider.h"
#include "Vector3.h"
// fwd:
class cCuboid;
class Vector3i;

View File

@ -8,7 +8,7 @@
#pragma once
#include "Vector3d.h"
#include "Vector3.h"
#include "Defines.h"

View File

@ -62,7 +62,6 @@ if (NOT MSVC)
Inventory.h
Item.h
ItemGrid.h
Matrix4f.h
Mobs/Monster.h
OSSupport/File.h
Root.h
@ -70,9 +69,7 @@ if (NOT MSVC)
StringUtils.h
Tracer.h
UI/Window.h
Vector3d.h
Vector3f.h
Vector3i.h
Vector3.h
WebAdmin.h
World.h
)

View File

@ -9,7 +9,7 @@
#pragma once
#include "Vector3i.h"
#include "Vector3.h"
#include "BiomeDef.h"

View File

@ -22,9 +22,6 @@
#include "Blocks/BlockSlab.h"
#include "Blocks/ChunkInterface.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Root.h"
#include "Authenticator.h"

View File

@ -12,7 +12,7 @@
#define CCLIENTHANDLE_H_INCLUDED
#include "Defines.h"
#include "Vector3d.h"
#include "Vector3.h"
#include "OSSupport/SocketThreads.h"
#include "ChunkDef.h"
#include "ByteBuffer.h"

View File

@ -1,8 +1,7 @@
#pragma once
#include "Vector3i.h"
#include "Vector3d.h"
#include "Vector3.h"

View File

@ -4,7 +4,7 @@
#include "../World.h"
#include "../Server.h"
#include "../Root.h"
#include "../Matrix4f.h"
#include "../Matrix4.h"
#include "../ClientHandle.h"
#include "../Chunk.h"
#include "../Simulator/FluidSimulator.h"

View File

@ -2,9 +2,7 @@
#pragma once
#include "../Item.h"
#include "../Vector3d.h"
#include "../Vector3f.h"
#include "../Vector3i.h"
#include "../Vector3.h"

View File

@ -14,6 +14,7 @@
#include "../OSSupport/Timer.h"
#include "../Chunk.h"
#include "../Items/ItemHandler.h"
#include "../Vector3.h"
#include "inifile/iniFile.h"
#include "json/json.h"

View File

@ -246,6 +246,14 @@ T Clamp(T a_Value, T a_Min, T a_Max)
#ifndef TOLUA_TEMPLATE_BIND
#define TOLUA_TEMPLATE_BIND(x)
#endif
// Common headers (part 2, with macros):
#include "ChunkDef.h"
#include "BiomeDef.h"

View File

@ -5,7 +5,7 @@
#include "Globals.h"
#include "LineBlockTracer.h"
#include "Vector3d.h"
#include "Vector3.h"
#include "World.h"
#include "Chunk.h"

224
src/Matrix4.h Normal file
View File

@ -0,0 +1,224 @@
#pragma once
#include <math.h>
template <typename T>
// tolua_begin
class Matrix4
{
TOLUA_TEMPLATE_BIND((T, float, double))
// tolua_end
public:
T cell[16];
// tolua_begin
inline Matrix4(void)
{
Identity();
}
inline Matrix4(const Matrix4 & a_Rhs)
{
*this = a_Rhs;
}
inline Matrix4 & operator = (const Matrix4 & a_Rhs)
{
for (unsigned int i = 0; i < 16; ++i)
{
cell[i] = a_Rhs.cell[i];
}
return *this;
}
inline T & operator [] (int a_N)
{
ASSERT(a_N < 16);
return cell[a_N];
}
inline void Identity()
{
cell[1] = cell[2] = cell[3] = cell[4] = 0;
cell[6] = cell[7] = cell[8] = cell[9] = 0;
cell[11] = cell[12] = cell[13] = cell[14] = 0;
cell[0] = cell[5] = cell[10] = cell[15] = 1;
}
inline void Init(const Vector3<T> & a_Pos, T a_RX, T a_RY, T a_RZ)
{
Matrix4<T> t;
t.RotateX(a_RZ);
RotateY(a_RY);
Concatenate(t);
t.RotateZ(a_RX);
Concatenate(t);
Translate(a_Pos);
}
inline void RotateX(T a_RX)
{
T sx = (T) sin(a_RX * M_PI / 180);
T cx = (T) cos(a_RX * M_PI / 180);
Identity();
cell[5] = cx; cell[6] = sx;
cell[9] = -sx; cell[10] = cx;
}
inline void RotateY(T a_RY)
{
T sy = (T) sin(a_RY * M_PI / 180);
T cy = (T) cos(a_RY * M_PI / 180);
Identity();
cell[0] = cy; cell[2] = -sy;
cell[8] = sy; cell[10] = cy;
}
inline void RotateZ(T a_RZ)
{
T sz = (T) sin(a_RZ * M_PI / 180);
T cz = (T) cos(a_RZ * M_PI / 180);
Identity();
cell[0] = cz; cell[1] = sz;
cell[4] = -sz; cell[5] = cz;
}
inline void Translate(const Vector3<T> & a_Pos)
{
cell[3] += a_Pos.x;
cell[7] += a_Pos.y;
cell[11] += a_Pos.z;
}
inline void SetTranslation(const Vector3<T> & a_Pos)
{
cell[3] = a_Pos.x;
cell[7] = a_Pos.y;
cell[11] = a_Pos.z;
}
inline void Concatenate(const Matrix4 & m2)
{
Matrix4 res;
for (unsigned int c = 0; c < 4; ++c)
{
for (unsigned int r = 0; r < 4; ++r)
{
res.cell[r * 4 + c] = (
cell[r * 4 + 0] * m2.cell[c + 0] +
cell[r * 4 + 1] * m2.cell[c + 4] +
cell[r * 4 + 2] * m2.cell[c + 8] +
cell[r * 4 + 3] * m2.cell[c + 12]
);
}
}
*this = res;
}
inline Vector3<T> Transform(const Vector3<T> & v) const
{
T x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3];
T y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7];
T z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11];
return Vector3<T>(x, y, z);
}
inline void Invert(void)
{
Matrix4 t;
T tx = -cell[3];
T ty = -cell[7];
T tz = -cell[11];
for (unsigned int h = 0; h < 3; ++h)
{
for (unsigned int v = 0; v < 3; ++v)
{
t.cell[h + v * 4] = cell[v + h * 4];
}
}
for (unsigned int i = 0; i < 11; ++i)
{
cell[i] = t.cell[i];
}
cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2];
cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6];
cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10];
}
inline Vector3<T> GetXColumn(void) const
{
return Vector3<T>(cell[0], cell[1], cell[2]);
}
inline Vector3<T> GetYColumn(void) const
{
return Vector3<T>(cell[4], cell[5], cell[6]);
}
inline Vector3<T> GetZColumn(void) const
{
return Vector3<T>(cell[8], cell[9], cell[10]);
}
inline void SetXColumn(const Vector3<T> & a_X)
{
cell[0] = a_X.x;
cell[1] = a_X.y;
cell[2] = a_X.z;
}
inline void SetYColumn(const Vector3<T> & a_Y)
{
cell[4] = a_Y.x;
cell[5] = a_Y.y;
cell[6] = a_Y.z;
}
inline void SetZColumn(const Vector3<T> & a_Z)
{
cell[8] = a_Z.x;
cell[9] = a_Z.y;
cell[10] = a_Z.z;
}
};
// tolua_end
// tolua_begin
typedef Matrix4<double> Matrix4d;
typedef Matrix4<float> Matrix4f;
// tolua_end

View File

@ -1,4 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
// _X: empty file??

View File

@ -1,225 +0,0 @@
#pragma once
#define _USE_MATH_DEFINES
#include <math.h>
#include "Vector3f.h"
class Matrix4f
{
public:
enum
{
TX=3,
TY=7,
TZ=11,
D0=0, D1=5, D2=10, D3=15,
SX=D0, SY=D1, SZ=D2,
W=D3
};
Matrix4f() { Identity(); }
float& operator [] ( int a_N ) { return cell[a_N]; }
void Identity()
{
cell[1] = cell[2] = cell[TX] = cell[4] = cell[6] = cell[TY] =
cell[8] = cell[9] = cell[TZ] = cell[12] = cell[13] = cell[14] = 0;
cell[D0] = cell[D1] = cell[D2] = cell[W] = 1;
}
void Init( Vector3f a_Pos, float a_RX, float a_RY, float a_RZ )
{
Matrix4f t;
t.RotateX( a_RZ );
RotateY( a_RY );
Concatenate( t );
t.RotateZ( a_RX );
Concatenate( t );
Translate( a_Pos );
}
void RotateX( float a_RX )
{
float sx = (float)sin( a_RX * M_PI / 180 );
float cx = (float)cos( a_RX * M_PI / 180 );
Identity();
cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx;
}
void RotateY( float a_RY )
{
float sy = (float)sin( a_RY * M_PI / 180 );
float cy = (float)cos( a_RY * M_PI / 180 );
Identity ();
cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy;
}
void RotateZ( float a_RZ )
{
float sz = (float)sin( a_RZ * M_PI / 180 );
float cz = (float)cos( a_RZ * M_PI / 180 );
Identity ();
cell[0] = cz, cell[1] = sz, cell[4] = -sz, cell[5] = cz;
}
void Translate( Vector3f a_Pos ) { cell[TX] += a_Pos.x; cell[TY] += a_Pos.y; cell[TZ] += a_Pos.z; }
void SetTranslation( Vector3f a_Pos ) { cell[TX] = a_Pos.x; cell[TY] = a_Pos.y; cell[TZ] = a_Pos.z; }
void Concatenate( const Matrix4f& m2 )
{
Matrix4f res;
int c;
for ( c = 0; c < 4; c++ ) for ( int r = 0; r < 4; r++ )
res.cell[r * 4 + c] = cell[r * 4] * m2.cell[c] +
cell[r * 4 + 1] * m2.cell[c + 4] +
cell[r * 4 + 2] * m2.cell[c + 8] +
cell[r * 4 + 3] * m2.cell[c + 12];
for ( c = 0; c < 16; c++ ) cell[c] = res.cell[c];
}
Vector3f Transform( const Vector3f& v ) const
{
float x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3];
float y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7];
float z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11];
return Vector3f( x, y, z );
}
void Invert()
{
Matrix4f t;
int h, i;
float tx = -cell[3], ty = -cell[7], tz = -cell[11];
for ( h = 0; h < 3; h++ ) for ( int v = 0; v < 3; v++ ) t.cell[h + v * 4] = cell[v + h * 4];
for ( i = 0; i < 11; i++ ) cell[i] = t.cell[i];
cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2];
cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6];
cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10];
}
Vector3f GetXColumn() { return Vector3f( cell[0], cell[1], cell[2] ); }
Vector3f GetYColumn() { return Vector3f( cell[4], cell[5], cell[6] ); }
Vector3f GetZColumn() { return Vector3f( cell[8], cell[9], cell[10] ); }
void SetXColumn( const Vector3f & a_X )
{
cell[0] = a_X.x;
cell[1] = a_X.y;
cell[2] = a_X.z;
}
void SetYColumn( const Vector3f & a_Y )
{
cell[4] = a_Y.x;
cell[5] = a_Y.y;
cell[6] = a_Y.z;
}
void SetZColumn( const Vector3f & a_Z )
{
cell[8] = a_Z.x;
cell[9] = a_Z.y;
cell[10] = a_Z.z;
}
float cell[16];
};
class Matrix4d
{
public:
enum
{
TX=3,
TY=7,
TZ=11,
D0=0, D1=5, D2=10, D3=15,
SX=D0, SY=D1, SZ=D2,
W=D3
};
Matrix4d() { Identity(); }
double& operator [] ( int a_N ) { return cell[a_N]; }
void Identity()
{
cell[1] = cell[2] = cell[TX] = cell[4] = cell[6] = cell[TY] =
cell[8] = cell[9] = cell[TZ] = cell[12] = cell[13] = cell[14] = 0;
cell[D0] = cell[D1] = cell[D2] = cell[W] = 1;
}
void Init( Vector3f a_Pos, double a_RX, double a_RY, double a_RZ )
{
Matrix4d t;
t.RotateX( a_RZ );
RotateY( a_RY );
Concatenate( t );
t.RotateZ( a_RX );
Concatenate( t );
Translate( a_Pos );
}
void RotateX( double a_RX )
{
double sx = (double)sin( a_RX * M_PI / 180 );
double cx = (double)cos( a_RX * M_PI / 180 );
Identity();
cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx;
}
void RotateY( double a_RY )
{
double sy = (double)sin( a_RY * M_PI / 180 );
double cy = (double)cos( a_RY * M_PI / 180 );
Identity ();
cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy;
}
void RotateZ( double a_RZ )
{
double sz = (double)sin( a_RZ * M_PI / 180 );
double cz = (double)cos( a_RZ * M_PI / 180 );
Identity ();
cell[0] = cz, cell[1] = sz, cell[4] = -sz, cell[5] = cz;
}
void Translate( Vector3d a_Pos ) { cell[TX] += a_Pos.x; cell[TY] += a_Pos.y; cell[TZ] += a_Pos.z; }
void SetTranslation( Vector3d a_Pos ) { cell[TX] = a_Pos.x; cell[TY] = a_Pos.y; cell[TZ] = a_Pos.z; }
void Concatenate( const Matrix4d & m2 )
{
Matrix4d res;
int c;
for ( c = 0; c < 4; c++ ) for ( int r = 0; r < 4; r++ )
res.cell[r * 4 + c] = cell[r * 4] * m2.cell[c] +
cell[r * 4 + 1] * m2.cell[c + 4] +
cell[r * 4 + 2] * m2.cell[c + 8] +
cell[r * 4 + 3] * m2.cell[c + 12];
for ( c = 0; c < 16; c++ ) cell[c] = res.cell[c];
}
Vector3d Transform( const Vector3d & v ) const
{
double x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3];
double y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7];
double z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11];
return Vector3d( x, y, z );
}
void Invert()
{
Matrix4d t;
int h, i;
double tx = -cell[3], ty = -cell[7], tz = -cell[11];
for ( h = 0; h < 3; h++ ) for ( int v = 0; v < 3; v++ ) t.cell[h + v * 4] = cell[v + h * 4];
for ( i = 0; i < 11; i++ ) cell[i] = t.cell[i];
cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2];
cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6];
cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10];
}
Vector3d GetXColumn() { return Vector3d( cell[0], cell[1], cell[2] ); }
Vector3d GetYColumn() { return Vector3d( cell[4], cell[5], cell[6] ); }
Vector3d GetZColumn() { return Vector3d( cell[8], cell[9], cell[10] ); }
void SetXColumn( const Vector3d & a_X )
{
cell[0] = a_X.x;
cell[1] = a_X.y;
cell[2] = a_X.z;
}
void SetYColumn( const Vector3d & a_Y )
{
cell[4] = a_Y.x;
cell[5] = a_Y.y;
cell[6] = a_Y.z;
}
void SetZColumn( const Vector3d & a_Z )
{
cell[8] = a_Z.x;
cell[9] = a_Z.y;
cell[10] = a_Z.z;
}
double cell[16];
} ;

View File

@ -2,7 +2,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Bat.h"
#include "../Vector3d.h"
#include "../Vector3.h"
#include "../Chunk.h"

View File

@ -2,7 +2,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Squid.h"
#include "../Vector3d.h"
#include "../Vector3.h"
#include "../Chunk.h"

View File

@ -150,6 +150,8 @@ public:
/** Removes all registered players */
void Reset(void);
// tolua_begin
/** Returns the number of registered players */
unsigned int GetNumPlayers(void) const;

View File

@ -24,7 +24,7 @@
#include "MersenneTwister.h"
#include "inifile/iniFile.h"
#include "Vector3f.h"
#include "Vector3.h"
#include <fstream>
#include <sstream>

View File

@ -3,7 +3,6 @@
#include "Simulator.h"
#include "../World.h"
#include "../Vector3i.h"
#include "../BlockID.h"
#include "../Defines.h"
#include "../Chunk.h"

View File

@ -1,7 +1,7 @@
#pragma once
#include "../Vector3i.h"
#include "../Vector3.h"
#include "inifile/iniFile.h"

View File

@ -4,10 +4,6 @@
#include "Tracer.h"
#include "World.h"
#include "Vector3f.h"
#include "Vector3i.h"
#include "Vector3d.h"
#include "Entities/Entity.h"
#ifndef _WIN32

View File

@ -1,8 +1,7 @@
#pragma once
#include "Vector3i.h"
#include "Vector3f.h"
#include "Vector3.h"

286
src/Vector3.h Normal file
View File

@ -0,0 +1,286 @@
#pragma once
#include <math.h>
template <typename T>
// tolua_begin
class Vector3
{
TOLUA_TEMPLATE_BIND((T, int, float, double))
public:
T x, y, z;
inline Vector3(void) : x(0), y(0), z(0) {}
inline Vector3(T a_x, T a_y, T a_z) : x(a_x), y(a_y), z(a_z) {}
// Hardcoded copy constructors (tolua++ does not support function templates .. yet)
Vector3(const Vector3<float> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
Vector3(const Vector3<double> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
Vector3(const Vector3<int> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
// tolua_end
template <typename _T>
Vector3(const Vector3<_T> & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {}
template <typename _T>
Vector3(const Vector3<_T> * a_Rhs) : x(a_Rhs->x), y(a_Rhs->y), z(a_Rhs->z) {}
// tolua_begin
inline void Set(T a_x, T a_y, T a_z)
{
x = a_x;
y = a_y;
z = a_z;
}
inline void Normalize(void)
{
double Len = 1.0 / Length();
x *= Len;
y *= Len;
z *= Len;
}
inline Vector3<T> NormalizeCopy(void) const
{
double Len = 1.0 / Length();
return Vector3<T>(
x * Len,
y * Len,
z * Len
);
}
inline void NormalizeCopy(Vector3<T> & a_Rhs) const
{
double Len = 1.0 / Length();
a_Rhs.Set(
x * Len,
y * Len,
z * Len
);
}
inline double Length(void) const
{
return sqrt((double)(x * x + y * y + z * z));
}
inline double SqrLength(void) const
{
return x * x + y * y + z * z;
}
inline T Dot(const Vector3<T> & a_Rhs) const
{
return x * a_Rhs.x + y * a_Rhs.y + z * a_Rhs.z;
}
inline Vector3<T> Cross(const Vector3<T> & a_Rhs) const
{
return Vector3<T>(
y * a_Rhs.z - z * a_Rhs.y,
z * a_Rhs.x - x * a_Rhs.z,
x * a_Rhs.y - y * a_Rhs.x
);
}
inline bool Equals(const Vector3<T> & a_Rhs) const
{
return x == a_Rhs.x && y == a_Rhs.y && z == a_Rhs.z;
}
inline bool operator < (const Vector3<T> & a_Rhs)
{
// return (x < a_Rhs.x) && (y < a_Rhs.y) && (z < a_Rhs.z); ?
return (x < a_Rhs.x) || (x == a_Rhs.x && y < a_Rhs.y) || (x == a_Rhs.x && y == a_Rhs.y && z < a_Rhs.z);
}
inline void Move(T a_X, T a_Y, T a_Z)
{
x += a_X;
y += a_Y;
z += a_Z;
}
// tolua_end
inline void operator += (const Vector3<T> & a_Rhs)
{
x += a_Rhs.x;
y += a_Rhs.y;
z += a_Rhs.z;
}
inline void operator -= (const Vector3<T> & a_Rhs)
{
x -= a_Rhs.x;
y -= a_Rhs.y;
z -= a_Rhs.z;
}
inline void operator *= (const Vector3<T> & a_Rhs)
{
x *= a_Rhs.x;
y *= a_Rhs.y;
z *= a_Rhs.z;
}
inline void operator *= (T a_v)
{
x *= a_v;
y *= a_v;
z *= a_v;
}
// tolua_begin
inline Vector3<T> operator + (const Vector3<T>& a_Rhs) const
{
return Vector3<T>(
x + a_Rhs.x,
y + a_Rhs.y,
z + a_Rhs.z
);
}
inline Vector3<T> operator - (const Vector3<T>& a_Rhs) const
{
return Vector3<T>(
x - a_Rhs.x,
y - a_Rhs.y,
z - a_Rhs.z
);
}
inline Vector3<T> operator * (const Vector3<T>& a_Rhs) const
{
return Vector3<T>(
x * a_Rhs.x,
y * a_Rhs.y,
z * a_Rhs.z
);
}
inline Vector3<T> operator * (T a_v) const
{
return Vector3<T>(
x * a_v,
y * a_v,
z * a_v
);
}
inline Vector3<T> operator / (T a_v) const
{
return Vector3<T>(
x / a_v,
y / a_v,
z / a_v
);
}
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord.
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).z = a_Z
If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
inline double LineCoeffToXYPlane(const Vector3<T> & a_OtherEnd, T a_Z) const
{
if (abs(z - a_OtherEnd.z) < EPS)
{
return NO_INTERSECTION;
}
return (a_Z - z) / (a_OtherEnd.z - z);
}
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord.
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).y = a_Y
If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
inline double LineCoeffToXZPlane(const Vector3<T> & a_OtherEnd, T a_Y) const
{
if (abs(y - a_OtherEnd.y) < EPS)
{
return NO_INTERSECTION;
}
return (a_Y - y) / (a_OtherEnd.y - y);
}
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord.
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).x = a_X
If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
inline double LineCoeffToYZPlane(const Vector3<T> & a_OtherEnd, T a_X) const
{
if (abs(x - a_OtherEnd.x) < EPS)
{
return NO_INTERSECTION;
}
return (a_X - x) / (a_OtherEnd.x - x);
}
/** The max difference between two coords for which the coords are assumed equal. */
static const double EPS;
/** Return value of LineCoeffToPlane() if the line is parallel to the plane. */
static const double NO_INTERSECTION;
};
// tolua_end
template <typename T>
const double Vector3<T>::EPS = 0.000001;
template <typename T>
const double Vector3<T>::NO_INTERSECTION = 1e70;
// tolua_begin
typedef Vector3<double> Vector3d;
typedef Vector3<float> Vector3f;
typedef Vector3<int> Vector3i;
// tolua_end
typedef std::list<Vector3i> cVector3iList;
typedef std::vector<Vector3i> cVector3iArray;

View File

@ -1,77 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Vector3d.h"
#include "Vector3f.h"
const double Vector3d::EPS = 0.000001; ///< The max difference between two coords for which the coords are assumed equal
const double Vector3d::NO_INTERSECTION = 1e70; ///< Return value of LineCoeffToPlane() if the line is parallel to the plane
Vector3d::Vector3d(const Vector3f & v) :
x(v.x),
y(v.y),
z(v.z)
{
}
Vector3d::Vector3d(const Vector3f * v) :
x(v->x),
y(v->y),
z(v->z)
{
}
double Vector3d::LineCoeffToXYPlane(const Vector3d & a_OtherEnd, double a_Z) const
{
if (abs(z - a_OtherEnd.z) < EPS)
{
return NO_INTERSECTION;
}
return (a_Z - z) / (a_OtherEnd.z - z);
}
double Vector3d::LineCoeffToXZPlane(const Vector3d & a_OtherEnd, double a_Y) const
{
if (abs(y - a_OtherEnd.y) < EPS)
{
return NO_INTERSECTION;
}
return (a_Y - y) / (a_OtherEnd.y - y);
}
double Vector3d::LineCoeffToYZPlane(const Vector3d & a_OtherEnd, double a_X) const
{
if (abs(x - a_OtherEnd.x) < EPS)
{
return NO_INTERSECTION;
}
return (a_X - x) / (a_OtherEnd.x - x);
}

View File

@ -1,81 +0,0 @@
#pragma once
#include <math.h>
class Vector3f;
// tolua_begin
class Vector3d
{
public:
// convert from float
Vector3d(const Vector3f & v);
Vector3d(const Vector3f * v);
Vector3d() : x(0), y(0), z(0) {}
Vector3d(double a_x, double a_y, double a_z) : x(a_x), y(a_y), z(a_z) {}
inline void Set(double a_x, double a_y, double a_z) { x = a_x, y = a_y, z = a_z; }
inline void Normalize() { double l = 1.0f / Length(); x *= l; y *= l; z *= l; }
inline Vector3d NormalizeCopy() { double l = 1.0f / Length(); return Vector3d( x * l, y * l, z * l ); }
inline void NormalizeCopy(Vector3d & a_V) { double l = 1.0f / Length(); a_V.Set(x*l, y*l, z*l ); }
inline double Length() const { return (double)sqrt( x * x + y * y + z * z ); }
inline double SqrLength() const { return x * x + y * y + z * z; }
inline double Dot( const Vector3d & a_V ) const { return x * a_V.x + y * a_V.y + z * a_V.z; }
inline Vector3d Cross( const Vector3d & v ) const { return Vector3d( y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); }
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).z = a_Z
If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
double LineCoeffToXYPlane(const Vector3d & a_OtherEnd, double a_Z) const;
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).y = a_Y
If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
double LineCoeffToXZPlane(const Vector3d & a_OtherEnd, double a_Y) const;
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).x = a_X
If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
double LineCoeffToYZPlane(const Vector3d & a_OtherEnd, double a_X) const;
inline bool Equals(const Vector3d & v) const { return ((x == v.x) && (y == v.y) && (z == v.z)); }
// tolua_end
void operator += ( const Vector3d& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; }
void operator += ( Vector3d* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; }
void operator -= ( const Vector3d& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; }
void operator -= ( Vector3d* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; }
void operator *= ( double a_f ) { x *= a_f; y *= a_f; z *= a_f; }
// tolua_begin
Vector3d operator + (const Vector3d & v2) const { return Vector3d(x + v2.x, y + v2.y, z + v2.z ); }
Vector3d operator + (const Vector3d * v2) const { return Vector3d(x + v2->x, y + v2->y, z + v2->z ); }
Vector3d operator - (const Vector3d & v2) const { return Vector3d(x - v2.x, y - v2.y, z - v2.z ); }
Vector3d operator - (const Vector3d * v2) const { return Vector3d(x - v2->x, y - v2->y, z - v2->z ); }
Vector3d operator * (const double f) const { return Vector3d(x * f, y * f, z * f ); }
Vector3d operator * (const Vector3d & v2) const { return Vector3d(x * v2.x, y * v2.y, z * v2.z ); }
Vector3d operator / (const double f) const { return Vector3d(x / f, y / f, z / f ); }
double x, y, z;
static const double EPS; ///< The max difference between two coords for which the coords are assumed equal
static const double NO_INTERSECTION; ///< Return value of LineCoeffToPlane() if the line is parallel to the plane
} ;
// tolua_end

View File

@ -1,34 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Vector3f.h"
#include "Vector3d.h"
#include "Vector3i.h"
Vector3f::Vector3f( const Vector3d & v )
: x( (float)v.x )
, y( (float)v.y )
, z( (float)v.z )
{
}
Vector3f::Vector3f( const Vector3d * v )
: x( (float)v->x )
, y( (float)v->y )
, z( (float)v->z )
{
}
Vector3f::Vector3f( const Vector3i & v )
: x( (float)v.x )
, y( (float)v.y )
, z( (float)v.z )
{
}
Vector3f::Vector3f( const Vector3i * v )
: x( (float)v->x )
, y( (float)v->y )
, z( (float)v->z )
{
}

View File

@ -1,47 +0,0 @@
#pragma once
#include <math.h>
class Vector3i;
class Vector3d;
class Vector3f // tolua_export
{ // tolua_export
public: // tolua_export
Vector3f( const Vector3d & v ); // tolua_export
Vector3f( const Vector3d * v ); // tolua_export
Vector3f( const Vector3i & v ); // tolua_export
Vector3f( const Vector3i * v ); // tolua_export
Vector3f() : x(0), y(0), z(0) {} // tolua_export
Vector3f(float a_x, float a_y, float a_z) : x(a_x), y(a_y), z(a_z) {} // tolua_export
inline void Set(float a_x, float a_y, float a_z) { x = a_x, y = a_y, z = a_z; } // tolua_export
inline void Normalize() { float l = 1.0f / Length(); x *= l; y *= l; z *= l; } // tolua_export
inline Vector3f NormalizeCopy() const { float l = 1.0f / Length(); return Vector3f( x * l, y * l, z * l ); }// tolua_export
inline void NormalizeCopy(Vector3f & a_V) const { float l = 1.0f / Length(); a_V.Set(x*l, y*l, z*l ); } // tolua_export
inline float Length() const { return (float)sqrtf( x * x + y * y + z * z ); } // tolua_export
inline float SqrLength() const { return x * x + y * y + z * z; } // tolua_export
inline float Dot( const Vector3f & a_V ) const { return x * a_V.x + y * a_V.y + z * a_V.z; } // tolua_export
inline Vector3f Cross( const Vector3f & v ) const { return Vector3f( y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); } // tolua_export
inline bool Equals( const Vector3f & v ) const { return (x == v.x && y == v.y && z == v.z ); } // tolua_export
void operator += ( const Vector3f& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; }
void operator += ( Vector3f* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; }
void operator -= ( const Vector3f& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; }
void operator -= ( Vector3f* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; }
void operator *= ( float a_f ) { x *= a_f; y *= a_f; z *= a_f; }
void operator *= ( Vector3f* a_V ) { x *= a_V->x; y *= a_V->y; z *= a_V->z; }
void operator *= ( const Vector3f& a_V ) { x *= a_V.x; y *= a_V.y; z *= a_V.z; }
Vector3f operator + ( const Vector3f& v2 ) const { return Vector3f( x + v2.x, y + v2.y, z + v2.z ); } // tolua_export
Vector3f operator + ( const Vector3f* v2 ) const { return Vector3f( x + v2->x, y + v2->y, z + v2->z ); } // tolua_export
Vector3f operator - ( const Vector3f& v2 ) const { return Vector3f( x - v2.x, y - v2.y, z - v2.z ); } // tolua_export
Vector3f operator - ( const Vector3f* v2 ) const { return Vector3f( x - v2->x, y - v2->y, z - v2->z ); } // tolua_export
Vector3f operator * ( const float f ) const { return Vector3f( x * f, y * f, z * f ); } // tolua_export
Vector3f operator * ( const Vector3f& v2 ) const { return Vector3f( x * v2.x, y * v2.y, z * v2.z ); } // tolua_export
float x, y, z; // tolua_export
};// tolua_export

View File

@ -1,58 +0,0 @@
// Vector3i.cpp
// Implements the Vector3i class representing an int-based 3D vector
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "math.h"
#include "Vector3i.h"
#include "Vector3d.h"
Vector3i::Vector3i(const Vector3d & v) :
x((int)v.x),
y((int)v.y),
z((int)v.z)
{
}
Vector3i::Vector3i(void) :
x(0),
y(0),
z(0)
{
}
Vector3i::Vector3i(int a_x, int a_y, int a_z) :
x(a_x),
y(a_y),
z(a_z)
{
}
void Vector3i::Move(int a_MoveX, int a_MoveY, int a_MoveZ)
{
x += a_MoveX;
y += a_MoveY;
z += a_MoveZ;
}

View File

@ -1,68 +0,0 @@
// Vector3i.h
// Declares the Vector3i class representing an int-based 3D vector
#pragma once
// fwd:
class Vector3d;
// tolua_begin
class Vector3i
{
public:
/** Creates an int vector based on the floor()-ed coords of a double vector. */
Vector3i(const Vector3d & v);
Vector3i(void);
Vector3i(int a_x, int a_y, int a_z);
inline void Set(int a_x, int a_y, int a_z) { x = a_x, y = a_y, z = a_z; }
inline float Length() const { return sqrtf( (float)( x * x + y * y + z * z) ); }
inline int SqrLength() const { return x * x + y * y + z * z; }
inline bool Equals( const Vector3i & v ) const { return (x == v.x && y == v.y && z == v.z ); }
inline bool Equals( const Vector3i * v ) const { return (x == v->x && y == v->y && z == v->z ); }
void Move(int a_MoveX, int a_MoveY, int a_MoveZ);
// tolua_end
void operator += ( const Vector3i& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; }
void operator += ( Vector3i* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; }
void operator -= ( const Vector3i& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; }
void operator -= ( Vector3i* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; }
void operator *= ( int a_f ) { x *= a_f; y *= a_f; z *= a_f; }
friend Vector3i operator + ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z ); }
friend Vector3i operator + ( const Vector3i& v1, Vector3i* v2 ) { return Vector3i( v1.x + v2->x, v1.y + v2->y, v1.z + v2->z ); }
friend Vector3i operator - ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z ); }
friend Vector3i operator - ( const Vector3i& v1, Vector3i* v2 ) { return Vector3i( v1.x - v2->x, v1.y - v2->y, v1.z - v2->z ); }
friend Vector3i operator - ( const Vector3i* v1, Vector3i& v2 ) { return Vector3i( v1->x - v2.x, v1->y - v2.y, v1->z - v2.z ); }
friend Vector3i operator * ( const Vector3i& v, const int f ) { return Vector3i( v.x * f, v.y * f, v.z * f ); }
friend Vector3i operator * ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x * v2.x, v1.y * v2.y, v1.z * v2.z ); }
friend Vector3i operator * ( const int f, const Vector3i& v ) { return Vector3i( v.x * f, v.y * f, v.z * f ); }
friend bool operator < ( const Vector3i& v1, const Vector3i& v2 ) { return (v1.x<v2.x)||(v1.x==v2.x && v1.y<v2.y)||(v1.x==v2.x && v1.y == v2.y && v1.z<v2.z); }
int x, y, z; // tolua_export
}; // tolua_export
typedef std::list<Vector3i> cVector3iList;
typedef std::vector<Vector3i> cVector3iArray;

View File

@ -46,7 +46,6 @@
#include "Generating/Trees.h"
#include "Bindings/PluginManager.h"
#include "Blocks/BlockHandler.h"
#include "Vector3d.h"
#include "Tracer.h"

View File

@ -14,8 +14,7 @@
#include "ChunkMap.h"
#include "WorldStorage/WorldStorage.h"
#include "Generating/ChunkGenerator.h"
#include "Vector3i.h"
#include "Vector3f.h"
#include "Vector3.h"
#include "ChunkSender.h"
#include "Defines.h"
#include "LightingThread.h"

View File

@ -12,7 +12,7 @@
#define WSSCOMPACT_H_INCLUDED
#include "WorldStorage.h"
#include "../Vector3i.h"
#include "../Vector3.h"
#include "json/json.h"