- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
#include <iostream>
#include <cmath>
struct Point3D
{
float x,y,z;
Point3D () {}
Point3D (float x, float y, float z) : x(x), y(y), z(z) {}
Point3D& operator -= (const Point3D& p) { x-=p.x; y-=p.y; z-=p.z; return *this; }
Point3D operator - (const Point3D& p) const { Point3D p2(*this); return (p2-=p); }
Point3D& operator *= (const float f) { x*=f; y*=f; z*=f; return *this; }
Point3D operator * (const float f) const { Point3D p2(*this); return (p2*=f); }
};
float Dot (const Point3D& p1, const Point3D& p2) { return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z; }
struct Face
{
Point3D n;
float nc;
float Dist (const Point3D& p) const { return Dot(p,n)-nc; }
};
int show_float(float src)
{
union
{
int i;
float f;
} u;
u.f = src;
return u.i;
}
float from_int(int src)
{
union
{
int i;
float f;
} u;
u.i = src;
return u.f;
}
template<typename T>
T& operator<<(T& str, const Point3D& p)
{
str << std::hex << "Point3D(from_int(0x" << show_float(p.x) << "), from_int(0x" << show_float(p.y) << "), from_int(0x" << show_float(p.z) << "))";
return str;
}
struct SPoint
{
Point3D p;
bool DoCorrectFace(const Face& face)
{
bool correct = true;
float j=1.0f;
Point3D np=p;
for (;;)
{
float ad = face.Dist(np);
if (ad<=0.0f)
break;
correct=false;
np = p - (face.n*(ad*j));
j += 1.0f;
}
p=np;
return correct;
}
};
using namespace std;
int main()
{
cout << "Hello World!" << endl;
SPoint spoint;
spoint.p = Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0));
cout << "Initial p:" << endl;
cout << spoint.p << endl;
cout << "Corrected:" << endl;
Face f;
f.n = Point3D(from_int(0x3d6cc83b), from_int(0x3f0e8841), from_int(0x3f5422bd));
f.nc = from_int(0x41bac3dc);
bool result = spoint.DoCorrectFace(f);
cout << spoint.p << endl;
cout << "Done: " << result << endl;
return 0;
}