Remove aabb, hamming, perlin

This commit is contained in:
Henrik Rydgård 2015-09-19 10:32:35 +02:00
parent 58ffa5f38c
commit 1a59e3820a
11 changed files with 0 additions and 430 deletions

View file

@ -960,8 +960,6 @@ add_library(native STATIC
ext/native/math/curves.h
ext/native/math/expression_parser.cpp
ext/native/math/expression_parser.h
ext/native/math/lin/aabb.cpp
ext/native/math/lin/aabb.h
ext/native/math/lin/matrix4x4.cpp
ext/native/math/lin/matrix4x4.h
ext/native/math/lin/plane.cpp
@ -1008,13 +1006,10 @@ add_library(native STATIC
ext/native/ui/virtual_input.h
ext/native/util/bits/bits.cpp
ext/native/util/bits/bits.h
ext/native/util/bits/hamming.h
ext/native/util/bits/varint.cpp
ext/native/util/bits/varint.h
ext/native/util/hash/hash.cpp
ext/native/util/hash/hash.h
ext/native/util/random/perlin.cpp
ext/native/util/random/perlin.h
ext/native/util/random/rng.h
ext/native/util/text/utf8.h
ext/native/util/text/utf8.cpp

View file

@ -57,7 +57,6 @@ LOCAL_SRC_FILES :=\
math/math_util.cpp \
math/curves.cpp \
math/expression_parser.cpp \
math/lin/aabb.cpp.arm \
math/lin/plane.cpp.arm \
math/lin/quat.cpp.arm \
math/lin/vec3.cpp.arm \
@ -95,7 +94,6 @@ LOCAL_SRC_FILES :=\
ui/ui_context.cpp \
ui/screen.cpp \
ui/virtual_input.cpp \
util/random/perlin.cpp \
util/text/utf8.cpp \
util/text/parsers.cpp \
util/hash/hash.cpp

View file

@ -2,7 +2,6 @@ set(SRCS
lin/matrix4x4.cpp
lin/vec3.cpp
lin/quat.cpp
lin/aabb.cpp
curves.cpp
math_util.cpp
)

View file

@ -1,268 +0,0 @@
#include "math/lin/aabb.h"
#include "math/lin/ray.h"
#include "math/lin/plane.h"
#define NUMDIM 3
#define RIGHT 0
#define LEFT 1
#define MIDDLE 2
static const float flt_plus_inf = -logf(0); // let's keep C and C++ compilers happy.
AABB::AABB() : minB(0,0,0),maxB(0,0,0) {
}
void AABB::Add(const Vec3 &pt) {
for (int i=0; i<3; i++)
{
if (pt[i] < minB[i])
minB[i] = pt[i];
if (pt[i] > maxB[i])
maxB[i] = pt[i];
}
}
bool AABB::Contains(const Vec3 &pt) const {
for (int i=0; i<3; i++)
{
if (pt[i] < minB[i])
return false;
if (pt[i] > maxB[i])
return false;
}
return true;
}
bool AABB::IntersectRay(const Ray &ray, float &tnear, float &tfar) const {
float tNear=-flt_plus_inf, tFar=flt_plus_inf;
//For each pair of planes P associated with X, Y, and Z do:
//(example using X planes)
for (int i=0; i<3; i++)
{
float min = minB[i];
float max = maxB[i];
if (ray.dir[i] == 0.0f) //parallell! ARGH!
if (ray.origin[i] < min || ray.origin[i] > max)
return false;
//Intersect with slab
float T1 = (min - ray.origin[i]) * ray.invdir[i];
float T2 = (max - ray.origin[i]) * ray.invdir[i];
//Swap if necessary
if (T1 > T2)
{
float temp=T1; T1=T2; T2=temp;
}
//Save closest/farthest hits
if (T1 > tNear) tNear = T1;
if (T2 < tFar) tFar = T2;
}
if (tNear > tFar)
return false; //missed the box
else
{
if (tFar < 0)
return false; //behind camera
tnear = tNear;
tfar = tFar;
}
return true;
}
// Possible orientation of the splitting plane in the interior node of the kd-tree,
// "No axis" denotes a leaf.
enum Axes
{
Xaxis,
Yaxis,
Zaxis,
Noaxis
};
int AABB::GetShortestAxis() const
{
Vec3 delta = maxB-minB;
if (delta.y<delta.x)
{
if (delta.z<delta.y)
return 2;
else
return 1;
}
else
{
if (delta.z<delta.x)
return 2;
else
return 0;
}
}
int AABB::GetLongestAxis() const
{
Vec3 delta = maxB-minB;
if (fabsf(delta.y) > fabsf(delta.x))
{
if (fabsf(delta.z) > fabsf(delta.y))
return 2;
else
return 1;
}
else
{
if (fabsf(delta.z) > fabsf(delta.x))
return 2;
else
return 0;
}
}
inline void FINDMINMAX(float x0, float x1, float x2, float &min, float &max )
{
min = max = x0;
if(x1<min)
min=x1;
if(x1>max)
max=x1;
if(x2<min)
min=x2;
if(x2>max)
max=x2;
}
// X-tests
#define AXISTEST_X01( a, b, fa, fb ) \
p0 = a * v0[1] - b * v0[2], p2 = a * v2[1] - b * v2[2]; \
if (p0 < p2) { min = p0; max = p2;} else { min = p2; max = p0; } \
rad = fa * a_BoxHalfsize[1] + fb * a_BoxHalfsize[2]; \
if (min > rad || max < -rad) return 0;
#define AXISTEST_X2( a, b, fa, fb ) \
p0 = a * v0[1] - b * v0[2], p1 = a * v1[1] - b * v1[2]; \
if (p0 < p1) { min = p0; max = p1; } else { min = p1; max = p0;} \
rad = fa * a_BoxHalfsize[1] + fb * a_BoxHalfsize[2]; \
if(min>rad || max<-rad) return 0;
// Y-tests
#define AXISTEST_Y02( a, b, fa, fb ) \
p0 = -a * v0[0] + b * v0[2], p2 = -a * v2[0] + b * v2[2]; \
if(p0 < p2) { min = p0; max = p2; } else { min = p2; max = p0; } \
rad = fa * a_BoxHalfsize[0] + fb * a_BoxHalfsize[2]; \
if (min > rad || max < -rad) return 0;
#define AXISTEST_Y1( a, b, fa, fb ) \
p0 = -a * v0[0] + b * v0[2], p1 = -a * v1[0] + b * v1[2]; \
if (p0 < p1) { min = p0; max = p1; } else { min = p1; max = p0; } \
rad = fa * a_BoxHalfsize[0] + fb * a_BoxHalfsize[2]; \
if (min > rad || max < -rad) return 0;
// Z-tests
#define AXISTEST_Z12( a, b, fa, fb ) \
p1 = a * v1[0] - b * v1[1], p2 = a * v2[0] - b * v2[1]; \
if(p2 < p1) { min = p2; max = p1; } else { min = p1; max = p2; } \
rad = fa * a_BoxHalfsize[0] + fb * a_BoxHalfsize[1]; \
if (min > rad || max < -rad) return 0;
#define AXISTEST_Z0( a, b, fa, fb ) \
p0 = a * v0[0] - b * v0[1], p1 = a * v1[0] - b * v1[1]; \
if(p0 < p1) { min = p0; max = p1; } else { min = p1; max = p0; } \
rad = fa * a_BoxHalfsize[0] + fb * a_BoxHalfsize[1]; \
if (min > rad || max < -rad) return 0;
bool PlaneBoxOverlap(const Vec3& a_Normal, const Vec3& a_Vert, const Vec3& a_MaxBox )
{
Vec3 vmin, vmax;
for (int q = 0; q < 3; q++)
{
float v = a_Vert[q];
if (a_Normal[q] > 0.0f)
{
vmin[q] = -a_MaxBox[q] - v;
vmax[q] = a_MaxBox[q] - v;
}
else
{
vmin[q] = a_MaxBox[q] - v;
vmax[q] = -a_MaxBox[q] - v;
}
}
if (( a_Normal * vmin) > 0.0f)
return false;
if (( a_Normal * vmax) >= 0.0f)
return true;
return false;
}
bool AABB::IntersectsTriangle(const Vec3& a_V0, const Vec3& a_V1, const Vec3& a_V2 ) const
{
Vec3 a_BoxCentre = GetMidpoint();
Vec3 a_BoxHalfsize = GetExtents() / 2.0f;
Vec3 v0, v1, v2, normal, e0, e1, e2;
float min, max, p0, p1, p2, rad, fex, fey, fez;
v0 = a_V0 - a_BoxCentre;
v1 = a_V1 - a_BoxCentre;
v2 = a_V2 - a_BoxCentre;
e0 = v1 - v0, e1 = v2 - v1, e2 = v0 - v2;
fex = fabsf(e0[0]);
fey = fabsf(e0[1]);
fez = fabsf(e0[2]);
AXISTEST_X01( e0[2], e0[1], fez, fey );
AXISTEST_Y02( e0[2], e0[0], fez, fex );
AXISTEST_Z12( e0[1], e0[0], fey, fex );
fex = fabsf(e1[0]);
fey = fabsf(e1[1]);
fez = fabsf(e1[2]);
AXISTEST_X01( e1[2], e1[1], fez, fey );
AXISTEST_Y02( e1[2], e1[0], fez, fex );
AXISTEST_Z0 ( e1[1], e1[0], fey, fex );
fex = fabsf(e2[0]);
fey = fabsf(e2[1]);
fez = fabsf(e2[2]);
AXISTEST_X2 ( e2[2], e2[1], fez, fey );
AXISTEST_Y1 ( e2[2], e2[0], fez, fex );
AXISTEST_Z12( e2[1], e2[0], fey, fex );
FINDMINMAX( v0[0], v1[0], v2[0], min, max );
if (min > a_BoxHalfsize[0] || max < -a_BoxHalfsize[0])
return false;
FINDMINMAX( v0[1], v1[1], v2[1], min, max );
if (min > a_BoxHalfsize[1] || max < -a_BoxHalfsize[1])
return false;
FINDMINMAX( v0[2], v1[2], v2[2], min, max );
if (min > a_BoxHalfsize[2] || max < -a_BoxHalfsize[2])
return false;
normal = e0 % e1;
if (!PlaneBoxOverlap( normal, v0, a_BoxHalfsize ))
return false;
return true;
}
bool AABB::BehindPlane(const Plane &plane) const {
if (plane.Distance(minB) > 0)
return false;
if (plane.Distance(maxB) > 0)
return false;
if (plane.Distance(maxB.x, minB.y, minB.z) > 0)
return false;
if (plane.Distance(maxB.x, maxB.y, minB.z) > 0)
return false;
if (plane.Distance(maxB.x, minB.y, maxB.z) > 0)
return false;
if (plane.Distance(minB.x, maxB.y, minB.z) > 0)
return false;
if (plane.Distance(minB.x, minB.y, maxB.z) > 0)
return false;
if (plane.Distance(minB.x, maxB.y, maxB.z) > 0)
return false;
return true;
}

View file

@ -1,40 +0,0 @@
#pragma once
#include "math/lin/vec3.h"
struct Ray;
class Plane;
struct AABB {
Vec3 minB;
int pad;
Vec3 maxB;
int pad2;
AABB();
bool Contains(const Vec3 &pt) const;
bool IntersectRay(const Ray &ray, float &tnear, float &tfar) const;
// Doesn't currently work.
bool IntersectRay2(const Ray &ray, float &tnear, float &tfar) const;
bool IntersectsTriangle(const Vec3& a_V0, const Vec3& a_V1, const Vec3& a_V2) const;
void Add(const Vec3 &pt);
int GetShortestAxis() const;
int GetLongestAxis() const;
float GetSize(int axis) const {
return maxB[axis] - minB[axis];
}
float GetMidpoint(int axis) const {
return (minB[axis] + maxB[axis]) / 2;
}
Vec3 GetMidpoint() const {
return (minB + maxB) / 2;
}
Vec3 GetExtents() const {
return maxB - minB;
}
bool BehindPlane(const Plane &plane) const;
};

View file

@ -254,7 +254,6 @@
<ClInclude Include="math\curves.h" />
<ClInclude Include="math\expression_parser.h" />
<ClInclude Include="math\geom2d.h" />
<ClInclude Include="math\lin\aabb.h" />
<ClInclude Include="math\lin\matrix4x4.h" />
<ClInclude Include="math\lin\plane.h" />
<ClInclude Include="math\lin\quat.h" />
@ -720,7 +719,6 @@
<ClCompile Include="json\json_writer.cpp" />
<ClCompile Include="math\curves.cpp" />
<ClCompile Include="math\expression_parser.cpp" />
<ClCompile Include="math\lin\aabb.cpp" />
<ClCompile Include="math\lin\matrix4x4.cpp" />
<ClCompile Include="math\lin\plane.cpp" />
<ClCompile Include="math\lin\quat.cpp" />

View file

@ -168,9 +168,6 @@
<ClInclude Include="base\backtrace.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="math\lin\aabb.h">
<Filter>math</Filter>
</ClInclude>
<ClInclude Include="math\lin\plane.h">
<Filter>math</Filter>
</ClInclude>
@ -452,9 +449,6 @@
<ClCompile Include="base\backtrace.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="math\lin\aabb.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="math\lin\plane.cpp">
<Filter>math</Filter>
</ClCompile>

View file

@ -1,7 +1,6 @@
set(SRCS
bits/bits.cpp
bits/varint.cpp
random/perlin.cpp
hash/hash.cpp
text/utf8.cpp
)

View file

@ -1,27 +0,0 @@
#ifndef _UTIL_BITS_HAMMING
#define _UTIL_BITS_HAMMING
#include <string>
#include "base/logging.h"
inline int Hamming(const std::string &a, const std::string &b) {
CHECK_EQ(a.size(), b.size());
int hamming = 0;
for (size_t i = 0; i < a.size(); i++)
hamming += a[i] == b[i];
return hamming;
}
inline int Hamming4(const std::string &a, const std::string &b) {
CHECK_EQ(a.size(), b.size());
int hamming = 0;
const uint32 *au = (const uint32 *)a.data();
const uint32 *bu = (const uint32 *)b.data();
for (size_t i = 0; i < a.size() / 4; i++)
hamming += au[i] == bu[i];
return hamming * 4;
}
#endif // _UTIL_BITS_HAMMING

View file

@ -1,72 +0,0 @@
#include "util/random/perlin.h"
#include <math.h>
// This should go in the const section of the binary.
static const int p[512] = {
151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,
151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,
};
inline float fade(float t) {
return t * t * t * (t * (t * 6 - 15) + 10);
}
inline float lerp(float t, float a, float b) {
return a + t * (b - a);
}
inline float grad(int hash, float x, float y, float z) {
int h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE
float u = h < 8 ? x : y; // INTO 12 GRADIENT DIRECTIONS.
float v = h < 4 ? y : (h == 12 || h == 14 ? x : z);
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
}
float Noise(double iz, double iy, double ix) {
double fx = floor(ix), fy = floor(iy), fz = floor(iz);
int X = (int)fx & 255, // FIND UNIT CUBE THAT
Y = (int)fy & 255, // CONTAINS POINT.
Z = (int)fz & 255;
float x = (float)(ix - fx); // FIND RELATIVE X,Y,Z
float y = (float)(iy - fy); // OF POINT IN CUBE.
float z = (float)(iz - fz);
float u = fade(x); // COMPUTE FADE CURVES
float v = fade(y); // FOR EACH OF X,Y,Z.
float w = fade(z);
int A = p[X ]+Y, B = p[X+1]+Y;
int AA = p[A]+Z, AB = p[A+1]+Z; // HASH COORDINATES OF
int BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS,
return lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD
grad(p[BA ], x-1, y , z )), // BLENDED
lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS
grad(p[BB ], x-1, y-1, z ))), // FROM 8
lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS
grad(p[BA+1], x-1, y , z-1 )), // OF CUBE
lerp(u, grad(p[AB+1], x , y-1, z-1 ),
grad(p[BB+1], x-1, y-1, z-1 ))));
}

View file

@ -1,6 +0,0 @@
#pragma once
// Implementation of "Improved Noise"
// http://mrl.nyu.edu/~perlin/noise/
// doubles are only used at the very start, not a big performance worry
float Noise(double x, double y, double z);