[10097] Update G3D up to v8.0b4

+ Got rid of zip lib requirement in G3D...
  Still can re-enable code by defining _HAVE_ZIP...

+ Remove silly X11 lib dependency from G3D
  Code doesn't seem to do anything yet anyway, and even if, we don't want it :p

+ Fix another weird G3D build problem...

+ Remove some __asm usage in g3d, which is not available on Win64
  My editor also decided to remove a ton of trailing white spaces...tss...

+ Reapply G3D fixes for 64bit VC

+ not use SSE specific header when SSE not enabled in *nix

+ Updated project files

+ New vmap_assembler VC90/VC80 Project

+ vmap assembler binaries updates

NOTE: Old vmap fikes expected work (as tests show) with new library version.
      But better use new generated versions. Its different in small parts to bad or good...

(based on Lynx3d's repo commit 44798d3)

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Lynx3d 2010-06-23 04:01:54 +04:00 committed by VladimirMangos
parent 2f3c518935
commit ae3ad10bcf
235 changed files with 58189 additions and 4547 deletions

View file

@ -3,40 +3,80 @@
3D vector class
@maintainer Morgan McGuire, matrix@graphics3d.com
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
@cite Portions based on Dave Eberly's Magic Software Library at http://www.magic-software.com
@created 2001-06-02
@edited 2006-01-30
@edited 2009-11-27
*/
#include <limits>
#include <stdlib.h>
#include "G3D/Vector3.h"
#include "G3D/g3dmath.h"
#include "G3D/format.h"
#include "G3D/stringutils.h"
#include "G3D/BinaryInput.h"
#include "G3D/BinaryOutput.h"
#include "G3D/TextInput.h"
#include "G3D/TextOutput.h"
#include "G3D/Vector3int16.h"
#include "G3D/Matrix3.h"
#include "G3D/Vector2.h"
#include "G3D/Color3.h"
#include "G3D/Vector4int8.h"
#include "G3D/Vector3int32.h"
#include "G3D/Any.h"
namespace G3D {
Vector3 Vector3::dummy;
Vector3::Vector3(const Any& any) {
any.verifyName("Vector3");
any.verifyType(Any::TABLE, Any::ARRAY);
any.verifySize(3);
// Deprecated.
const Vector3 Vector3::ZERO(0, 0, 0);
const Vector3 Vector3::ZERO3(0, 0, 0);
const Vector3 Vector3::UNIT_X(1, 0, 0);
const Vector3 Vector3::UNIT_Y(0, 1, 0);
const Vector3 Vector3::UNIT_Z(0, 0, 1);
const Vector3 Vector3::INF3((float)G3D::inf(), (float)G3D::inf(), (float)G3D::inf());
const Vector3 Vector3::NAN3((float)G3D::nan(), (float)G3D::nan(), (float)G3D::nan());
if (any.type() == Any::ARRAY) {
x = any[0];
y = any[1];
z = any[2];
} else {
// Table
x = any["x"];
y = any["y"];
z = any["z"];
}
}
Vector3::operator Any() const {
Any any(Any::ARRAY, "Vector3");
any.append(x, y, z);
return any;
}
Vector3::Vector3(const class Color3& v) : x(v.r), y(v.g), z(v.b) {}
Vector3::Vector3(const class Vector3int32& v) : x((float)v.x), y((float)v.y), z((float)v.z) {}
Vector3::Vector3(const Vector4int8& v) : x(v.x / 127.0f), y(v.y / 127.0f), z(v.z / 127.0f) {}
Vector3::Vector3(const class Vector2& v, float _z) : x(v.x), y(v.y), z(_z) {
}
Vector3& Vector3::ignore() {
static Vector3 v;
return v;
}
const Vector3& Vector3::zero() { static const Vector3 v(0, 0, 0); return v; }
const Vector3& Vector3::one() { static const Vector3 v(1, 1, 1); return v; }
const Vector3& Vector3::unitX() { static const Vector3 v(1, 0, 0); return v; }
const Vector3& Vector3::unitY() { static const Vector3 v(0, 1, 0); return v; }
const Vector3& Vector3::unitZ() { static const Vector3 v(0, 0, 1); return v; }
const Vector3& Vector3::inf() { static const Vector3 v((float)G3D::finf(), (float)G3D::finf(), (float)G3D::finf()); return v; }
const Vector3& Vector3::nan() { static const Vector3 v((float)G3D::fnan(), (float)G3D::fnan(), (float)G3D::fnan()); return v; }
const Vector3& Vector3::minFinite(){ static const Vector3 v(-FLT_MAX, -FLT_MAX, -FLT_MAX); return v; }
const Vector3& Vector3::maxFinite(){ static const Vector3 v(FLT_MAX, FLT_MAX, FLT_MAX); return v; }
Vector3::Axis Vector3::primaryAxis() const {
Axis a = X_AXIS;
@ -63,7 +103,7 @@ Vector3::Axis Vector3::primaryAxis() const {
}
unsigned int Vector3::hashCode() const {
size_t Vector3::hashCode() const {
unsigned int xhash = (*(int*)(void*)(&x));
unsigned int yhash = (*(int*)(void*)(&y));
unsigned int zhash = (*(int*)(void*)(&z));
@ -82,6 +122,14 @@ double frand() {
return rand() / (double) RAND_MAX;
}
Vector3::Vector3(TextInput& t) {
deserialize(t);
}
Vector3::Vector3(BinaryInput& b) {
deserialize(b);
}
Vector3::Vector3(const class Vector3int16& v) {
x = v.x;
@ -90,57 +138,54 @@ Vector3::Vector3(const class Vector3int16& v) {
}
Vector3 Vector3::random() {
void Vector3::deserialize(BinaryInput& b) {
x = b.readFloat32();
y = b.readFloat32();
z = b.readFloat32();
}
void Vector3::deserialize(TextInput& t) {
t.readSymbol("(");
x = (float)t.readNumber();
t.readSymbol(",");
y = (float)t.readNumber();
t.readSymbol(",");
z = (float)t.readNumber();
t.readSymbol(")");
}
void Vector3::serialize(TextOutput& t) const {
t.writeSymbol("(");
t.writeNumber(x);
t.writeSymbol(",");
t.writeNumber(y);
t.writeSymbol(",");
t.writeNumber(z);
t.writeSymbol(")");
}
void Vector3::serialize(BinaryOutput& b) const {
b.writeFloat32(x);
b.writeFloat32(y);
b.writeFloat32(z);
}
Vector3 Vector3::random(Random& r) {
Vector3 result;
do {
result = Vector3(uniformRandom(-1.0, 1.0),
uniformRandom(-1.0, 1.0),
uniformRandom(-1.0, 1.0));
} while (result.squaredMagnitude() >= 1.0f);
result.unitize();
r.sphere(result.x, result.y, result.z);
return result;
}
//----------------------------------------------------------------------------
Vector3 Vector3::operator/ (float fScalar) const {
Vector3 kQuot;
if ( fScalar != 0.0 ) {
float fInvScalar = 1.0f / fScalar;
kQuot.x = fInvScalar * x;
kQuot.y = fInvScalar * y;
kQuot.z = fInvScalar * z;
return kQuot;
} else {
return Vector3::inf();
}
}
//----------------------------------------------------------------------------
Vector3& Vector3::operator/= (float fScalar) {
if (fScalar != 0.0) {
float fInvScalar = 1.0f / fScalar;
x *= fInvScalar;
y *= fInvScalar;
z *= fInvScalar;
} else {
x = (float)G3D::inf();
y = (float)G3D::inf();
z = (float)G3D::inf();
}
return *this;
}
//----------------------------------------------------------------------------
float Vector3::unitize (float fTolerance) {
float fMagnitude = magnitude();
float Vector3::unitize(float fTolerance) {
float fMagnitude = magnitude();
if (fMagnitude > fTolerance) {
float fInvMagnitude = 1.0f / fMagnitude;
float fInvMagnitude = 1.0f / fMagnitude;
x *= fInvMagnitude;
y *= fInvMagnitude;
z *= fInvMagnitude;
@ -151,10 +196,8 @@ float Vector3::unitize (float fTolerance) {
return fMagnitude;
}
//----------------------------------------------------------------------------
Vector3 Vector3::reflectAbout(const Vector3& normal) const {
Vector3 out;
Vector3 N = normal.direction();
@ -163,36 +206,49 @@ Vector3 Vector3::reflectAbout(const Vector3& normal) const {
return N * 2 * this->dot(N) - *this;
}
//----------------------------------------------------------------------------
#if 0
Vector3 Vector3::cosRandom(const Vector3& normal) {
double e1 = G3D::random(0, 1);
double e2 = G3D::random(0, 1);
// Angle from normal
double theta = acos(sqrt(e1));
Vector3 Vector3::cosHemiRandom(const Vector3& normal, Random& r) {
debugAssertM(G3D::fuzzyEq(normal.length(), 1.0f),
"cosHemiRandom requires its argument to have unit length");
// Angle about normal
double phi = 2 * G3D_PI * e2;
float x, y, z;
r.cosHemi(x, y, z);
// Make a coordinate system
Vector3 U = normal.direction();
Vector3 V = Vector3::unitX();
const Vector3& Z = normal;
if (abs(U.dot(V)) > .9) {
V = Vector3::unitY();
}
Vector3 X, Y;
normal.getTangents(X, Y);
Vector3 W = U.cross(V).direction();
V = W.cross(U);
// Convert to rectangular form
return cos(theta) * U + sin(theta) * (cos(phi) * V + sin(phi) * W);
return
x * X +
y * Y +
z * Z;
}
//----------------------------------------------------------------------------
Vector3 Vector3::hemiRandom(const Vector3& normal) {
Vector3 V = Vector3::random();
Vector3 Vector3::cosPowHemiRandom(const Vector3& normal, const float k, Random& r) {
debugAssertM(G3D::fuzzyEq(normal.length(), 1.0f),
"cosPowHemiRandom requires its argument to have unit length");
float x, y, z;
r.cosPowHemi(k, x, y, z);
// Make a coordinate system
const Vector3& Z = normal;
Vector3 X, Y;
normal.getTangents(X, Y);
return
x * X +
y * Y +
z * Z;
}
Vector3 Vector3::hemiRandom(const Vector3& normal, Random& r) {
const Vector3& V = Vector3::random(r);
if (V.dot(normal) < 0) {
return -V;
@ -200,7 +256,7 @@ Vector3 Vector3::hemiRandom(const Vector3& normal) {
return V;
}
}
#endif
//----------------------------------------------------------------------------
Vector3 Vector3::reflectionDirection(const Vector3& normal) const {
@ -308,6 +364,14 @@ Matrix3 Vector3::cross() const {
}
void serialize(const Vector3::Axis& a, class BinaryOutput& bo) {
bo.writeUInt8((uint8)a);
}
void deserialize(Vector3::Axis& a, class BinaryInput& bi) {
a = (Vector3::Axis)bi.readUInt8();
}
//----------------------------------------------------------------------------
// 2-char swizzles