Synchronise with 2.1.2 release

A 2.1.2 release was pushed 10 years after the last modification
timestamp on CVS [1]. Unfortunately, that means these changes were
effectively untracked by CVS. What's even worse, while some of the
changes are stylistic, others are non-trivial and there is no rationale
behind them.

This commit attempts to match this 2.1.2 release, while removing
trailing whitespaces and newlines in order to keep Git (and also myself)
happy.

Trailing whitespaces have been removed with:

while read f
do
    sed -Ei 's/[[:space:]]+$//g' "$f"
done <<EOF
$(find . -iname '*.cpp' -o -iname '*.h')
EOF

Trailing newlines have been removed with:

while read f
do
    sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' -- "$f"
done <<EOF
$(find . -iname '*.cpp' -o -iname '*.h')
EOF

[1]: https://sourceforge.net/projects/freesolid/files/FreeSOLID-2.1.2.zip/download
This commit is contained in:
Xavier Del Campo Romero 2025-01-31 00:22:17 +01:00
parent 277f32db5d
commit 208c6e2031
Signed by: xavi
GPG key ID: 84FF3612A9BF43F2
93 changed files with 1606 additions and 2355 deletions

View file

@ -27,28 +27,19 @@
#ifndef _BASIC_H_
#define _BASIC_H_
#include <math.h>
#include <stdlib.h>
#include <float.h>
#include <cmath>
#include <cstdlib>
typedef float Scalar;
typedef double Scalar;
const Scalar DEGS_PER_RAD = 57.29577951308232286465f;
const Scalar RADS_PER_DEG = 0.01745329251994329547f;
const Scalar TWO_PI = 6.28318530717958623200f;
const Scalar EPSILON = FLT_EPSILON;
const Scalar EPSILON2 = FLT_EPSILON;
const Scalar SOLID_INFINITY = FLT_MAX;
const Scalar DEGS_PER_RAD = 57.29577951308232286465;
const Scalar RADS_PER_DEG = 0.01745329251994329547;
const Scalar TWO_PI = 6.28318530717958623200;
const Scalar EPSILON = 1.0e-10;
const Scalar EPSILON2 = 1.0e-20;
const Scalar SOLID_INFINITY = 1.0e50;
// These are for Double precision, we'll keep em for later use
//const Scalar DEGS_PER_RAD = 57.29577951308232286465;
//const Scalar RADS_PER_DEG = 0.01745329251994329547;
//const Scalar TWO_PI = 6.28318530717958623200;
//const Scalar EPSILON = 1.0e-20;
//const Scalar EPSILON2 = 1.0e-20;
//const Scalar SOLID_INFINITY = 1.0e50;
inline Scalar rnd() { return (Scalar(rand()) + 0.5f) / (Scalar(RAND_MAX) + 1.0f); }
inline Scalar rnd() { return (Scalar(rand()) + 0.5) / (Scalar(RAND_MAX) + 1); }
inline Scalar sabs(Scalar x) { return x < 0 ? -x : x; }
inline int sgn(Scalar x) { return x < 0 ? -1 : x > 0 ? 1 : 0; }
inline bool eqz(Scalar x) { return (sabs(x) <= EPSILON); }

View file

@ -38,19 +38,18 @@ class Matrix {
public:
Matrix() {}
Matrix(const float *m) { setValue(m); }
// Saved for later
// Matrix(const double *m) { setValue(m); }
Matrix(const double *m) { setValue(m); }
Matrix(const Quaternion& q) { setRotation(q); }
Matrix(Scalar x, Scalar y, Scalar z) { setScaling(x, y, z); }
Matrix(Scalar xx, Scalar xy, Scalar xz,
Scalar yx, Scalar yy, Scalar yz,
Scalar zx, Scalar zy, Scalar zz) {
Scalar zx, Scalar zy, Scalar zz) {
setValue(xx, xy, xz, yx, yy, yz, zx, zy, zz);
}
Vector& operator[](int i) { return *(Vector *)elem[i]; }
const Vector& operator[](int i) const { return *(Vector *)elem[i]; }
Mat3& getValue() { return elem; }
const Mat3& getValue() const { return elem; }
@ -60,22 +59,20 @@ public:
elem[X][Z] = *m++; elem[Y][Z] = *m++; elem[Z][Z] = *m;
}
// Saved for later
/*
void setValue(const double *m) {
elem[X][X] = *m++; elem[Y][X] = *m++; elem[Z][X] = *m++; m++;
elem[X][Y] = *m++; elem[Y][Y] = *m++; elem[Z][Y] = *m++; m++;
elem[X][Z] = *m++; elem[Y][Z] = *m++; elem[Z][Z] = *m;
}
*/
void setValue(Scalar xx, Scalar xy, Scalar xz,
Scalar yx, Scalar yy, Scalar yz,
void setValue(Scalar xx, Scalar xy, Scalar xz,
Scalar yx, Scalar yy, Scalar yz,
Scalar zx, Scalar zy, Scalar zz) {
elem[X][X] = xx; elem[X][Y] = xy; elem[X][Z] = xz;
elem[Y][X] = yx; elem[Y][Y] = yy; elem[Y][Z] = yz;
elem[Z][X] = zx; elem[Z][Y] = zy; elem[Z][Z] = zz;
}
void setRotation(const Quaternion& q) {
Scalar d = q.length2();
assert(!eqz(d));
@ -88,25 +85,25 @@ public:
xy + wz , 1 - (xx + zz), yz - wx,
xz - wy , yz + wx , 1 - (xx + yy));
}
void setScaling(Scalar x, Scalar y, Scalar z) {
setValue(x, 0, 0, 0, y, 0, 0, 0, z);
setValue(x, 0, 0, 0, y, 0, 0, 0, z);
}
void setIdentity() { setValue(1, 0, 0, 0, 1, 0, 0, 0, 1); }
Matrix& operator*=(const Matrix& m);
Matrix& operator*=(const Matrix& m);
Scalar tdot(int i, const Vector& v) const {
return elem[X][i] * v[X] + elem[Y][i] * v[Y] + elem[Z][i] * v[Z];
}
Scalar determinant() const;
Matrix absolute() const;
Matrix transpose() const;
Matrix adjoint() const;
Matrix inverse() const;
Matrix inverse() const;
protected:
Mat3 elem;
};
@ -139,7 +136,7 @@ inline Matrix& Matrix::operator*=(const Matrix& m) {
return *this;
}
inline Scalar Matrix::determinant() const {
inline Scalar Matrix::determinant() const {
return triple((*this)[X], (*this)[Y], (*this)[Z]);
}
@ -169,7 +166,7 @@ inline Matrix Matrix::adjoint() const {
inline Matrix Matrix::inverse() const {
Vector co(elem[Y][Y] * elem[Z][Z] - elem[Y][Z] * elem[Z][Y],
elem[Y][Z] * elem[Z][X] - elem[Y][X] * elem[Z][Z],
elem[Y][Z] * elem[Z][X] - elem[Y][X] * elem[Z][Z],
elem[Y][X] * elem[Z][Y] - elem[Y][Y] * elem[Z][X]);
Scalar d = dot((*this)[X], co);
assert(!eqz(d));

View file

@ -34,9 +34,8 @@
class Point : public Vector {
public:
Point() {}
Point(const float p[3]) : Vector(p) {}
// Saved for later
// Point(const double p[3]) : Vector(p) {}
Point(const float p[3]) : Vector(p) {}
Point(const double p[3]) : Vector(p) {}
Point(Scalar x, Scalar y, Scalar z) : Vector(x, y, z) {}
Point& operator+=(const Vector& v);
@ -102,11 +101,11 @@ inline bool operator<(const Point& p1, const Point& p2) {
return p1[X] < p2[X] && p1[Y] < p2[Y] && p1[Z] < p2[Z];
}
inline Point inf(const Point& p1, const Point& p2) {
inline Point inf(const Point& p1, const Point& p2) {
return Point(min(p1[X], p2[X]), min(p1[Y], p2[Y]), min(p1[Z], p2[Z]));
}
inline Point sup(const Point& p1, const Point& p2) {
inline Point sup(const Point& p1, const Point& p2) {
return Point(max(p1[X], p2[X]), max(p1[Y], p2[Y]), max(p1[Z], p2[Z]));
}
@ -116,12 +115,12 @@ inline Point affine(const Point& p1, const Point& p2, Scalar t) {
p1[Z] + (p2[Z] - p1[Z]) * t);
}
inline Scalar distance(const Point& p1, const Point& p2) {
return length(p1 - p2);
inline Scalar distance(const Point& p1, const Point& p2) {
return length(p1 - p2);
}
inline Scalar distance2(const Point& p1, const Point& p2) {
return length2(p1 - p2);
inline Scalar distance2(const Point& p1, const Point& p2) {
return length2(p1 - p2);
}
#endif

View file

@ -34,12 +34,11 @@ class Quaternion : public Tuple4 {
public:
Quaternion() {}
Quaternion(const float v[4]) : Tuple4(v) {}
// Saved for later
// Quaternion(const double v[4]) : Tuple4(v) {}
Quaternion(const double v[4]) : Tuple4(v) {}
Quaternion(Scalar x, Scalar y, Scalar z, Scalar w) : Tuple4(x, y, z, w) {}
Quaternion(const Vector& axis, Scalar angle) { setRotation(axis, angle); }
Quaternion(Scalar yaw, Scalar pitch, Scalar roll) {
setEuler(yaw, pitch, roll);
Quaternion(Scalar yaw, Scalar pitch, Scalar roll) {
setEuler(yaw, pitch, roll);
}
void setRotation(const Vector& axis, Scalar angle) {
@ -61,15 +60,13 @@ public:
sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,
cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);
}
inline void getMatrix(float *pMatrix) const;
Quaternion& operator+=(const Quaternion& q);
Quaternion& operator-=(const Quaternion& q);
Quaternion& operator*=(const Quaternion& q);
Quaternion& operator*=(Scalar s);
Quaternion& operator/=(Scalar s);
Scalar length2() const;
Scalar length() const;
@ -113,7 +110,7 @@ inline Quaternion& Quaternion::operator-=(const Quaternion& q) {
comp[X] -= q[X]; comp[Y] -= q[Y]; comp[Z] -= q[Z]; comp[W] -= q[W];
return *this;
}
inline Quaternion& Quaternion::operator*=(const Quaternion& q) {
setValue(comp[W] * q[X] + comp[X] * q[W] + comp[Y] * q[Z] - comp[Z] * q[Y],
comp[W] * q[Y] + comp[Y] * q[W] + comp[Z] * q[X] - comp[X] * q[Z],
@ -145,11 +142,11 @@ inline Quaternion operator-(const Quaternion& q) {
}
inline Quaternion operator*(const Quaternion& q1, const Quaternion& q2) {
return
return
Quaternion(q1[W] * q2[X] + q1[X] * q2[W] + q1[Y] * q2[Z] - q1[Z] * q2[Y],
q1[W] * q2[Y] + q1[Y] * q2[W] + q1[Z] * q2[X] - q1[X] * q2[Z],
q1[W] * q2[Z] + q1[Z] * q2[W] + q1[X] * q2[Y] - q1[Y] * q2[X],
q1[W] * q2[W] - q1[X] * q2[X] - q1[Y] * q2[Y] - q1[Z] * q2[Z]);
q1[W] * q2[W] - q1[X] * q2[X] - q1[Y] * q2[Y] - q1[Z] * q2[Z]);
}
inline Quaternion operator*(const Quaternion& q, Scalar s) {
@ -182,7 +179,7 @@ inline void Quaternion::conjugate() {
inline Quaternion Quaternion::conjugate() const {
return Quaternion(-comp[X], -comp[Y], -comp[Z], comp[W]);
}
inline void Quaternion::invert() {
conjugate();
*this /= length2();
@ -196,11 +193,11 @@ inline Scalar length2(const Quaternion& q) { return q.length2(); }
inline Scalar length(const Quaternion& q) { return q.length(); }
inline bool approxZero(const Quaternion& q) { return q.approxZero(); }
inline bool approxEqual(const Quaternion& q1, const Quaternion& q2) {
return approxZero(q1 - q2);
inline bool approxEqual(const Quaternion& q1, const Quaternion& q2) {
return approxZero(q1 - q2);
}
// From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III,
// From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III,
// pg. 124-132
inline Quaternion Quaternion::random() {
Scalar x0 = rnd();
@ -211,34 +208,4 @@ inline Quaternion Quaternion::random() {
return Quaternion(s1 * r1, c1 * r1, s2 * r2, c2 * r2);
}
inline void Quaternion::getMatrix(float *pMatrix) const
{
if(!pMatrix) return;
pMatrix[ 0] = 1.0f - 2.0f * ( comp[Y] * comp[Y] + comp[Z] * comp[Z] );
pMatrix[ 1] = 2.0f * (comp[X] * comp[Y] + comp[Z] * comp[W]);
pMatrix[ 2] = 2.0f * (comp[X] * comp[Z] - comp[Y] * comp[W]);
pMatrix[ 3] = 0.0f;
// Second row
pMatrix[ 4] = 2.0f * ( comp[X] * comp[Y] - comp[Z] * comp[W] );
pMatrix[ 5] = 1.0f - 2.0f * ( comp[X] * comp[X] + comp[Z] * comp[Z] );
pMatrix[ 6] = 2.0f * (comp[Z] * comp[Y] + comp[X] * comp[W] );
pMatrix[ 7] = 0.0f;
// Third row
pMatrix[ 8] = 2.0f * ( comp[X] * comp[Z] + comp[Y] * comp[W] );
pMatrix[ 9] = 2.0f * ( comp[Y] * comp[Z] - comp[X] * comp[W] );
pMatrix[10] = 1.0f - 2.0f * ( comp[X] * comp[X] + comp[Y] * comp[Y] );
pMatrix[11] = 0.0f;
// Fourth row
pMatrix[12] = 0;
pMatrix[13] = 0;
pMatrix[14] = 0;
pMatrix[15] = 1.0f;
}
#endif

View file

@ -38,8 +38,9 @@ class Tuple3 {
public:
Tuple3() {}
Tuple3(const float v[3]) { setValue(v); }
Tuple3(const double v[3]) { setValue(v); }
Tuple3(Scalar x, Scalar y, Scalar z) { setValue(x, y, z); }
Scalar& operator[](int i) { return comp[i]; }
const Scalar& operator[](int i) const { return comp[i]; }
@ -49,19 +50,17 @@ public:
void setValue(const float v[3]) {
comp[X] = v[X]; comp[Y] = v[Y]; comp[Z] = v[Z];
}
/*
// These saved for later PROPER double support
void setValue(const double v[3]) {
comp[X] = v[X]; comp[Y] = v[Y]; comp[Z] = v[Z];
}
Tuple3(const double v[3]) { setValue(v); }
*/
void setValue(Scalar x, Scalar y, Scalar z) {
comp[X] = x; comp[Y] = y; comp[Z] = z;
}
protected:
Scalar comp[3];
Scalar comp[3];
};
inline bool operator==(const Tuple3& t1, const Tuple3& t2) {

View file

@ -38,10 +38,9 @@ class Tuple4 {
public:
Tuple4() {}
Tuple4(const float v[4]) { setValue(v); }
// Saved for later
// Tuple4(const double v[4]) { setValue(v); }
Tuple4(const double v[4]) { setValue(v); }
Tuple4(Scalar x, Scalar y, Scalar z, Scalar w) { setValue(x, y, z, w); }
Scalar& operator[](int i) { return comp[i]; }
const Scalar& operator[](int i) const { return comp[i]; }
@ -51,18 +50,17 @@ public:
void setValue(const float v[4]) {
comp[X] = v[X]; comp[Y] = v[Y]; comp[Z] = v[Z]; comp[W] = v[W];
}
// Saved for later
/*
void setValue(const double v[4]) {
comp[X] = v[X]; comp[Y] = v[Y]; comp[Z] = v[Z]; comp[W] = v[W];
}
*/
void setValue(Scalar x, Scalar y, Scalar z, Scalar w) {
comp[X] = x; comp[Y] = y; comp[Z] = z; comp[W] = w;
}
protected:
Scalar comp[4];
Scalar comp[4];
};
inline bool operator==(const Tuple4& t1, const Tuple4& t2) {

View file

@ -33,15 +33,14 @@ class Vector : public Tuple3 {
public:
Vector() {}
Vector(const float v[3]) : Tuple3(v) {}
// Saved for double later
// Vector(const double v[3]) : Tuple3(v) {}
Vector(const double v[3]) : Tuple3(v) {}
Vector(Scalar x, Scalar y, Scalar z) : Tuple3(x, y, z) {}
Vector& operator+=(const Vector& v);
Vector& operator-=(const Vector& v);
Vector& operator*=(Scalar s);
Vector& operator/=(Scalar s);
Scalar length2() const;
Scalar length() const;
@ -49,7 +48,6 @@ public:
void normalize();
Vector normalized() const;
void normal(const Vector& p1,const Vector& p2,const Vector& p3);
int closestAxis() const;
@ -86,7 +84,7 @@ inline Vector& Vector::operator-=(const Vector& v) {
comp[X] -= v[X]; comp[Y] -= v[Y]; comp[Z] -= v[Z];
return *this;
}
inline Vector& Vector::operator*=(Scalar s) {
comp[X] *= s; comp[Y] *= s; comp[Z] *= s;
return *this;
@ -131,13 +129,6 @@ inline bool Vector::approxZero() const { return length2() < EPSILON2; }
inline void Vector::normalize() { *this /= length(); }
inline Vector Vector::normalized() const { return *this / length(); }
inline void Vector::normal(const Vector& p1,
const Vector& p2,
const Vector& p3)
{
*this = cross((p2 - p1),(p3 - p1));
*this /= length();
}
inline int Vector::closestAxis() const {
Scalar a[2];
@ -156,8 +147,8 @@ inline Scalar length2(const Vector& v) { return v.length2(); }
inline Scalar length(const Vector& v) { return v.length(); }
inline bool approxZero(const Vector& v) { return v.approxZero(); }
inline bool approxEqual(const Vector& v1, const Vector& v2) {
return approxZero(v1 - v2);
inline bool approxEqual(const Vector& v1, const Vector& v2) {
return approxZero(v1 - v2);
}
inline Scalar angle(const Vector& v1, const Vector& v2) {
@ -173,10 +164,9 @@ inline Vector cross(const Vector& v1, const Vector& v2) {
}
inline Scalar triple(const Vector& v1, const Vector& v2, const Vector& v3) {
return v1[X] * (v2[Y] * v3[Z] - v2[Z] * v3[Y]) +
v1[Y] * (v2[Z] * v3[X] - v2[X] * v3[Z]) +
return v1[X] * (v2[Y] * v3[Z] - v2[Z] * v3[Y]) +
v1[Y] * (v2[Z] * v3[X] - v2[X] * v3[Z]) +
v1[Z] * (v2[X] * v3[Y] - v2[Y] * v3[X]);
}
#endif

View file

@ -13,7 +13,7 @@
#ifdef __cplusplus
extern "C" {
#endif
DT_DECLARE_HANDLE(BP_SceneHandle);
DT_DECLARE_HANDLE(BP_ProxyHandle);
@ -21,19 +21,19 @@ typedef void (*BP_Callback)(void *client_data,
void *object1,
void *object2);
FREESOLID_DLL BP_SceneHandle BP_CreateScene(void *client_data,
BP_SceneHandle BP_CreateScene(void *client_data,
BP_Callback beginOverlap,
BP_Callback endOverlap);
FREESOLID_DLL void BP_DeleteScene(BP_SceneHandle scene);
FREESOLID_DLL BP_ProxyHandle BP_CreateProxy(BP_SceneHandle scene, void *object,
void BP_DeleteScene(BP_SceneHandle scene);
BP_ProxyHandle BP_CreateProxy(BP_SceneHandle scene, void *object,
const DT_Vector3 min, const DT_Vector3 max);
FREESOLID_DLL void BP_DeleteProxy(BP_SceneHandle scene,
void BP_DeleteProxy(BP_SceneHandle scene,
BP_ProxyHandle proxy);
FREESOLID_DLL void BP_SetBBox(BP_ProxyHandle proxy, const DT_Vector3 min, const DT_Vector3 max);
void BP_SetBBox(BP_ProxyHandle proxy, const DT_Vector3 min, const DT_Vector3 max);
#ifdef __cplusplus
}

View file

@ -1,5 +1,5 @@
/*
FreeSOLID - Software Library for Interference Detection
SOLID - Software Library for Interference Detection
Copyright (C) 1997-1998 Gino van den Bergen
This library is free software; you can redistribute it and/or
@ -31,7 +31,7 @@
extern "C" {
#endif
#include "types.h"
#include "SOLID/types.h"
typedef void *DtObjectRef;
DT_DECLARE_HANDLE(DtShapeRef);
@ -42,11 +42,11 @@ typedef enum DtPolyType {
DT_POLYHEDRON
} DtPolyType;
typedef enum DtResponseType {
typedef enum DtResponseType {
DT_NO_RESPONSE,
DT_SIMPLE_RESPONSE,
DT_SMART_RESPONSE,
DT_WITNESSED_RESPONSE,
DT_WITNESSED_RESPONSE
} DtResponseType;
typedef struct DtCollData {
@ -65,78 +65,77 @@ typedef void (*DtResponse)(
/* Shape definition */
extern FREESOLID_DLL DtShapeRef dtBox(DT_Scalar x, DT_Scalar y, DT_Scalar z);
extern FREESOLID_DLL DtShapeRef dtCone(DT_Scalar radius, DT_Scalar height);
extern FREESOLID_DLL DtShapeRef dtCylinder(DT_Scalar radius, DT_Scalar height);
extern FREESOLID_DLL DtShapeRef dtSphere(DT_Scalar radius);
extern FREESOLID_DLL DtShapeRef dtEllipsoid(DT_Scalar radiusx,DT_Scalar radiusy,DT_Scalar radiusz);
DECLSPEC DtShapeRef dtBox(DT_Scalar x, DT_Scalar y, DT_Scalar z);
DECLSPEC DtShapeRef dtCone(DT_Scalar radius, DT_Scalar height);
DECLSPEC DtShapeRef dtCylinder(DT_Scalar radius, DT_Scalar height);
DECLSPEC DtShapeRef dtSphere(DT_Scalar radius);
extern FREESOLID_DLL DtShapeRef dtNewComplexShape();
extern FREESOLID_DLL void dtEndComplexShape();
DECLSPEC DtShapeRef dtNewComplexShape();
DECLSPEC void dtEndComplexShape();
extern FREESOLID_DLL void dtBegin(DtPolyType type);
extern FREESOLID_DLL void dtEnd();
DECLSPEC void dtBegin(DtPolyType type);
DECLSPEC void dtEnd();
extern FREESOLID_DLL void dtVertex(DT_Scalar x, DT_Scalar y, DT_Scalar z);
extern FREESOLID_DLL void dtVertexBase(const void *base);
extern FREESOLID_DLL void dtVertexIndex(DT_Index index);
extern FREESOLID_DLL void dtVertexIndices(DtPolyType type, DT_Count count,
DECLSPEC void dtVertex(DT_Scalar x, DT_Scalar y, DT_Scalar z);
DECLSPEC void dtVertexBase(const void *base);
DECLSPEC void dtVertexIndex(DT_Index index);
DECLSPEC void dtVertexIndices(DtPolyType type, DT_Count count,
const DT_Index *indices);
extern FREESOLID_DLL void dtVertexRange(DtPolyType type, DT_Index first, DT_Count count);
DECLSPEC void dtVertexRange(DtPolyType type, DT_Index first, DT_Count count);
extern FREESOLID_DLL void dtChangeVertexBase(DtShapeRef shape, const void *base);
DECLSPEC void dtChangeVertexBase(DtShapeRef shape, const void *base);
extern FREESOLID_DLL void dtDeleteShape(DtShapeRef shape);
DECLSPEC void dtDeleteShape(DtShapeRef shape);
/* Object */
extern FREESOLID_DLL void dtCreateObject(DtObjectRef object, DtShapeRef shape);
extern FREESOLID_DLL void dtDeleteObject(DtObjectRef object);
extern FREESOLID_DLL void dtSelectObject(DtObjectRef object);
DECLSPEC void dtCreateObject(DtObjectRef object, DtShapeRef shape);
DECLSPEC void dtDeleteObject(DtObjectRef object);
DECLSPEC void dtSelectObject(DtObjectRef object);
extern FREESOLID_DLL void dtLoadIdentity();
DECLSPEC void dtLoadIdentity();
extern FREESOLID_DLL void dtLoadMatrixf(const float *m);
extern FREESOLID_DLL void dtLoadMatrixd(const double *m);
DECLSPEC void dtLoadMatrixf(const float *m);
DECLSPEC void dtLoadMatrixd(const double *m);
extern FREESOLID_DLL void dtMultMatrixf(const float *m);
extern FREESOLID_DLL void dtMultMatrixd(const double *m);
DECLSPEC void dtMultMatrixf(const float *m);
DECLSPEC void dtMultMatrixd(const double *m);
extern FREESOLID_DLL void dtTranslate(DT_Scalar x, DT_Scalar y, DT_Scalar z);
extern FREESOLID_DLL void dtRotate(DT_Scalar x, DT_Scalar y, DT_Scalar z, DT_Scalar w);
extern FREESOLID_DLL void dtScale(DT_Scalar x, DT_Scalar y, DT_Scalar z);
DECLSPEC void dtTranslate(DT_Scalar x, DT_Scalar y, DT_Scalar z);
DECLSPEC void dtRotate(DT_Scalar x, DT_Scalar y, DT_Scalar z, DT_Scalar w);
DECLSPEC void dtScale(DT_Scalar x, DT_Scalar y, DT_Scalar z);
/* Response */
extern FREESOLID_DLL void dtSetDefaultResponse(DtResponse response, DtResponseType type,
DECLSPEC void dtSetDefaultResponse(DtResponse response, DtResponseType type,
void *client_data);
extern FREESOLID_DLL void dtClearDefaultResponse();
DECLSPEC void dtClearDefaultResponse();
extern FREESOLID_DLL void dtSetObjectResponse(DtObjectRef object, DtResponse response,
DECLSPEC void dtSetObjectResponse(DtObjectRef object, DtResponse response,
DtResponseType type, void *client_data);
extern FREESOLID_DLL void dtClearObjectResponse(DtObjectRef object);
extern FREESOLID_DLL void dtResetObjectResponse(DtObjectRef object);
DECLSPEC void dtClearObjectResponse(DtObjectRef object);
DECLSPEC void dtResetObjectResponse(DtObjectRef object);
extern FREESOLID_DLL void dtSetPairResponse(DtObjectRef object1, DtObjectRef object2,
DtResponse response, DtResponseType type,
DECLSPEC void dtSetPairResponse(DtObjectRef object1, DtObjectRef object2,
DtResponse response, DtResponseType type,
void *client_data);
extern FREESOLID_DLL void dtClearPairResponse(DtObjectRef object1, DtObjectRef object2);
extern FREESOLID_DLL void dtResetPairResponse(DtObjectRef object1, DtObjectRef object2);
DECLSPEC void dtClearPairResponse(DtObjectRef object1, DtObjectRef object2);
DECLSPEC void dtResetPairResponse(DtObjectRef object1, DtObjectRef object2);
/* Global */
extern FREESOLID_DLL DT_Count dtTest();
extern FREESOLID_DLL void dtTestObjects(DtObjectRef object1, DtObjectRef object2);
extern FREESOLID_DLL void dtProceed();
DECLSPEC DT_Count dtTest();
DECLSPEC void dtTestObjects(DtObjectRef object1, DtObjectRef object2);
DECLSPEC void dtProceed();
extern FREESOLID_DLL void dtEnableCaching();
extern FREESOLID_DLL void dtDisableCaching();
DECLSPEC void dtEnableCaching();
DECLSPEC void dtDisableCaching();
extern FREESOLID_DLL void dtSetTolerance(DT_Scalar tol);
DECLSPEC void dtSetTolerance(DT_Scalar tol);
#ifdef __cplusplus
}

View file

@ -8,31 +8,31 @@
#ifndef SOLID_TYPES_H
#define SOLID_TYPES_H
#if defined(DLL_EXPORT) && defined(WIN32)
#define FREESOLID_DLL __declspec( dllexport )
#else
#if defined(WIN32)
#define FREESOLID_DLL __declspec( dllimport )
#if defined(_WIN32)
# if defined(SOLID_STATIC)
# define DECLSPEC extern
# elif defined(DLL_EXPORT)
# define DECLSPEC __declspec(dllexport)
# else
# define DECLSPEC __declspec(dllimport)
# endif
#else
#define FREESOLID_DLL
# define DECLSPEC extern
#endif
#endif
#define DT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
typedef unsigned int DT_Index;
typedef unsigned int DT_Count;
typedef unsigned int DT_Size;
typedef float DT_Scalar;
typedef float DT_Scalar;
typedef int DT_Bool;
#define DT_FALSE 0
#define DT_TRUE 1
typedef DT_Scalar DT_Vector3[3];
typedef DT_Scalar DT_Quaternion[4];
typedef DT_Scalar DT_Vector3[3];
typedef DT_Scalar DT_Quaternion[4];
#endif

View file

@ -15,17 +15,17 @@ BP_SceneHandle BP_CreateScene(void *client_data,
BP_Callback beginOverlap,
BP_Callback endOverlap)
{
return (BP_SceneHandle)new BP_Scene(client_data,
beginOverlap,
return (BP_SceneHandle)new BP_Scene(client_data,
beginOverlap,
endOverlap);
}
void BP_DeleteScene(BP_SceneHandle scene)
{
delete (BP_Scene *)scene;
}
BP_ProxyHandle BP_CreateProxy(BP_SceneHandle scene, void *object,
const DT_Vector3 min, const DT_Vector3 max)
@ -35,14 +35,14 @@ BP_ProxyHandle BP_CreateProxy(BP_SceneHandle scene, void *object,
}
void BP_DeleteProxy(BP_SceneHandle scene, BP_ProxyHandle proxy)
void BP_DeleteProxy(BP_SceneHandle scene, BP_ProxyHandle proxy)
{
((BP_Scene *)scene)->deleteProxy((BP_Proxy *)proxy);
}
void BP_SetBBox(BP_ProxyHandle proxy, const DT_Vector3 min, const DT_Vector3 max)
void BP_SetBBox(BP_ProxyHandle proxy, const DT_Vector3 min, const DT_Vector3 max)
{
((BP_Proxy *)proxy)->setBBox(MT_Point3(min), MT_Point3(max));
}

View file

@ -12,20 +12,20 @@
#include "BP_Scene.h"
BP_Endpoint::BP_Endpoint(MT_Scalar pos, Type type, BP_Proxy *proxy,
BP_Endpoint::BP_Endpoint(MT_Scalar pos, Type type, BP_Proxy *proxy,
GEN_List& endpointList) :
m_pos(pos), m_type(type), m_proxy(proxy)
{
GEN_Link *next = endpointList.getHead();
while (!next->isTail() && (*(BP_Endpoint *)next < *this)) {
next = next->getNext();
}
insertBefore(next);
insertBefore(next);
}
BP_Endpoint::~BP_Endpoint()
{
{
if (m_proxy != 0) {
remove();
}
@ -35,14 +35,14 @@ void encounters(const BP_Endpoint& a, const BP_Endpoint& b,
BP_Scene& scene, T_Overlap overlap)
{
assert(a.m_proxy != b.m_proxy);
if ((a.m_type != b.m_type) && overlap(*a.m_proxy, *b.m_proxy)) {
if (a.m_type == BP_Endpoint::MAXIMUM) {
scene.callBeginOverlap(a.m_proxy->getObject(),
scene.callBeginOverlap(a.m_proxy->getObject(),
b.m_proxy->getObject());
}
else {
scene.callEndOverlap(a.m_proxy->getObject(),
scene.callEndOverlap(a.m_proxy->getObject(),
b.m_proxy->getObject());
}
}
@ -53,7 +53,7 @@ void BP_Endpoint::move(MT_Scalar x, BP_Scene& scene, T_Overlap overlap)
int sign = MT_sign(x - m_pos);
m_pos = x;
switch (sign) {
case -1: {
GEN_Link *prev = getPrev();
@ -77,21 +77,14 @@ void BP_Endpoint::move(MT_Scalar x, BP_Scene& scene, T_Overlap overlap)
next = next->getNext();
}
while (!next->isTail() && (*(BP_Endpoint *)next < *this));
insertBefore(next);
insertBefore(next);
}
break;
}
case 0:
// nothing to do
// nothing to do
break;
default:
assert(false);
}
}

View file

@ -21,7 +21,7 @@ public:
enum Type { MINIMUM, MAXIMUM };
BP_Endpoint() : m_proxy(0) {}
BP_Endpoint(MT_Scalar pos, Type type, BP_Proxy *proxy,
BP_Endpoint(MT_Scalar pos, Type type, BP_Proxy *proxy,
GEN_List& endpointList);
~BP_Endpoint();
@ -34,8 +34,8 @@ public:
BP_Scene& scene, T_Overlap overlap);
friend bool operator<(const BP_Endpoint& a, const BP_Endpoint& b);
private:
private:
MT_Scalar m_pos;
Type m_type;
BP_Proxy *m_proxy;
@ -46,13 +46,3 @@ inline bool operator<(const BP_Endpoint& a, const BP_Endpoint& b) {
}
#endif

View file

@ -11,15 +11,15 @@
#include "BP_Scene.h"
#include "MT_Point3.h"
BP_Proxy::BP_Proxy(void *object, BP_Scene& scene,
BP_Proxy::BP_Proxy(void *object, BP_Scene& scene,
const MT_Point3& min,
const MT_Point3& max) :
const MT_Point3& max) :
m_object(object),
m_scene(scene)
{
int i;
for (i = 0; i < 3; ++i) {
new (&m_min[i]) BP_Endpoint(min[i], BP_Endpoint::MINIMUM,
new (&m_min[i]) BP_Endpoint(min[i], BP_Endpoint::MINIMUM,
this, scene.getLists()[i]);
new (&m_max[i]) BP_Endpoint(max[i], BP_Endpoint::MAXIMUM,
this, scene.getLists()[i]);
@ -28,24 +28,24 @@ BP_Proxy::BP_Proxy(void *object, BP_Scene& scene,
bool overlapXY(const BP_Proxy& a, const BP_Proxy& b)
{
return a.getMin(0) <= b.getMax(0) && b.getMin(0) <= a.getMax(0) &&
return a.getMin(0) <= b.getMax(0) && b.getMin(0) <= a.getMax(0) &&
a.getMin(1) <= b.getMax(1) && b.getMin(1) <= a.getMax(1);
}
bool overlapXZ(const BP_Proxy& a, const BP_Proxy& b)
{
return a.getMin(0) <= b.getMax(0) && b.getMin(0) <= a.getMax(0) &&
a.getMin(2) <= b.getMax(2) && b.getMin(2) <= a.getMax(2);
return a.getMin(0) <= b.getMax(0) && b.getMin(0) <= a.getMax(0) &&
a.getMin(2) <= b.getMax(2) && b.getMin(2) <= a.getMax(2);
}
bool overlapYZ(const BP_Proxy& a, const BP_Proxy& b)
{
return a.getMin(1) <= b.getMax(1) && b.getMin(1) <= a.getMax(1) &&
a.getMin(2) <= b.getMax(2) && b.getMin(2) <= a.getMax(2);
return a.getMin(1) <= b.getMax(1) && b.getMin(1) <= a.getMax(1) &&
a.getMin(2) <= b.getMax(2) && b.getMin(2) <= a.getMax(2);
}
void BP_Proxy::setBBox(const MT_Point3& min, const MT_Point3& max)
{
{
static T_Overlap overlap[3] = { overlapYZ, overlapXZ, overlapXY };
int i;
@ -60,7 +60,3 @@ void BP_Proxy::setBBox(const MT_Point3& min, const MT_Point3& max)
}
}
}

View file

@ -15,13 +15,13 @@ class MT_Point3;
class BP_Proxy {
public:
BP_Proxy(void *object,
BP_Scene& scene,
BP_Proxy(void *object,
BP_Scene& scene,
const MT_Point3& min,
const MT_Point3& max);
void setBBox(const MT_Point3& min, const MT_Point3& max);
void *getObject() { return m_object; }
MT_Scalar getMin(int i) const { return m_min[i].getPos(); }
@ -36,13 +36,9 @@ private:
inline bool BP_overlap(const BP_Proxy& a, const BP_Proxy& b)
{
return a.getMin(0) <= b.getMax(0) && b.getMin(0) <= a.getMax(0) &&
return a.getMin(0) <= b.getMax(0) && b.getMin(0) <= a.getMax(0) &&
a.getMin(1) <= b.getMax(1) && b.getMin(1) <= a.getMax(1) &&
a.getMin(2) <= b.getMax(2) && b.getMin(2) <= a.getMax(2);
}
#endif

View file

@ -20,64 +20,41 @@ BP_Scene::~BP_Scene()
}
BP_Proxy *BP_Scene::createProxy(void *object,
BP_Proxy *BP_Scene::createProxy(void *object,
const MT_Point3& min,
const MT_Point3& max)
{
BP_Proxy *proxy = new BP_Proxy(object, *this, min, max);
T_ProxyList::iterator i;
for (i = m_proxyList.begin(); !(i == m_proxyList.end()); ++i) {
if (BP_overlap(*proxy, *(*i))) {
callBeginOverlap(proxy->getObject(), (*i)->getObject());
}
}
m_proxyList.push_back(proxy);
return proxy;
}
void BP_Scene::deleteProxy(BP_Proxy *proxy)
{
T_ProxyList::iterator i =
T_ProxyList::iterator i =
std::find(m_proxyList.begin(), m_proxyList.end(), proxy);
if (i != m_proxyList.end()) {
m_proxyList.erase(i);
T_ProxyList::iterator j;
for (j = m_proxyList.begin(); !(j == m_proxyList.end()); ++j) {
if (BP_overlap(*proxy, *(*j))) {
callEndOverlap(proxy->getObject(), (*j)->getObject());
}
}
delete proxy;
}
}

View file

@ -27,7 +27,7 @@ public:
~BP_Scene();
BP_Proxy *createProxy(void *object,
BP_Proxy *createProxy(void *object,
const MT_Point3& min,
const MT_Point3& max);
@ -47,17 +47,10 @@ private:
typedef std::vector<BP_Proxy *> T_ProxyList;
void *m_client_data;
BP_Callback m_beginOverlap;
BP_Callback m_endOverlap;
BP_Callback m_beginOverlap;
BP_Callback m_endOverlap;
T_ProxyList m_proxyList;
GEN_List m_endpointList[3];
};
#endif

View file

@ -1,11 +1 @@
noinst_LTLIBRARIES = libbroad.la
libbroad_la_CPPFLAGS = -I@TOPDIR@/include -I@TOPDIR@/libmoto
libbroad_la_SOURCES = BP_C-api.cpp \
BP_Endpoint.cpp \
BP_Proxy.cpp \
BP_Scene.cpp
pkginclude_HEADERS = \
BP_Endpoint.h \
BP_Proxy.h \
BP_Scene.h
EXTRA_DIST = broad.dsp
EXTRA_DIST = broad.dsp

View file

@ -31,9 +31,9 @@ class GEN_Link {
public:
GEN_Link() : m_next(0), m_prev(0) {}
GEN_Link(GEN_Link *next, GEN_Link *prev) : m_next(next), m_prev(prev) {}
GEN_Link *getNext() const { return m_next; }
GEN_Link *getPrev() const { return m_prev; }
GEN_Link *getNext() const { return m_next; }
GEN_Link *getPrev() const { return m_prev; }
bool isHead() const { return m_prev == 0; }
bool isTail() const { return m_next == 0; }
@ -51,20 +51,20 @@ public:
void insertBefore(GEN_Link *link) {
attachAfter(link->m_prev);
attachBefore(link);
}
}
void insertAfter(GEN_Link *link) {
attachBefore(link->m_next);
attachAfter(link);
}
}
void remove() {
m_next->m_prev = m_prev;
void remove() {
m_next->m_prev = m_prev;
m_prev->m_next = m_next;
m_next = m_prev = 0;
}
private:
private:
GEN_Link *m_next;
GEN_Link *m_prev;
};
@ -74,14 +74,14 @@ class GEN_List {
public:
GEN_List() : m_head(&m_tail, 0), m_tail(0, &m_head) {}
GEN_Link *getHead() const { return m_head.getNext(); }
GEN_Link *getTail() const { return m_tail.getPrev(); }
GEN_Link *getHead() const { return m_head.getNext(); }
GEN_Link *getTail() const { return m_tail.getPrev(); }
void clear() { m_head.attachBefore(&m_tail); }
void addHead(GEN_Link *link) { link->insertAfter(&m_head); }
void addTail(GEN_Link *link) { link->insertBefore(&m_tail); }
void appendHead(GEN_List& list) {
list.getTail()->attachBefore(getHead());
list.getHead()->attachAfter(&m_head);
@ -102,6 +102,3 @@ private:
};
#endif

View file

@ -6,7 +6,7 @@
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dtecta makes no representations about
* the suitability of this software for any purpose. It is provided
* the suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
*/
@ -35,7 +35,7 @@ inline void GEN_set_max(T& a, const T& b) {
template <class T>
inline void GEN_clamp(T& a, const T& b, const T& c) {
if (a < b) a = b;
if (a < b) a = b;
else if (a > c) a = c;
}

View file

@ -5,6 +5,6 @@
#define GEN_INLINE inline
#else
#define GEN_INLINE
#endif
#endif
#endif

View file

@ -19,7 +19,7 @@
/* See the GNU Library General Public License for more details. */
/* You should have received a copy of the GNU Library General */
/* Public License along with this library; if not, write to the */
/* Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */
/* Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */
/* 02111-1307 USA */
/* Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. */
@ -28,14 +28,14 @@
#include "GEN_random.h"
/* Period parameters */
/* Period parameters */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0df /* constant vector a */
#define UPPER_MASK 0x80000000 /* most significant w-r bits */
#define LOWER_MASK 0x7fffffff /* least significant r bits */
/* Tempering parameters */
/* Tempering parameters */
#define TEMPERING_MASK_B 0x9d2c5680
#define TEMPERING_MASK_C 0xefc60000
#define TEMPERING_SHIFT_U(y) (y >> 11)
@ -67,10 +67,10 @@ unsigned long GEN_rand()
if (mti >= N) { /* generate N words at one time */
int kk;
if (mti == N+1) /* if sgenrand() has not been called, */
GEN_srand(4357); /* a default initial seed is used */
for (kk = 0; kk < N - M; kk++) {
y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
@ -84,7 +84,7 @@ unsigned long GEN_rand()
mti = 0;
}
y = mt[mti++];
y ^= TEMPERING_SHIFT_U(y);
y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;

View file

@ -9,4 +9,3 @@ extern void GEN_srand(unsigned long);
extern unsigned long GEN_rand();