Serious-Engine/Sources/Engine/Models/Normals.cpp
Ryan C. Gordon 24cb244d43 First attempt to hand-merge Ryan's Linux and Mac OS X port.
This was a _ton_ of changes, made 15 years ago, so there are probably some
problems to work out still.

Among others: Engine/Base/Stream.* was mostly abandoned and will need to be
re-ported.

Still, this is a pretty good start, and probably holds a world record for
lines of changes or something.  :)
2016-03-28 23:46:13 -04:00

288 lines
13 KiB
C++

/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */
#include "Engine/StdH.h"
#include <Engine/Models/Normals.h>
#include <Engine/Math/Vector.h>
FLOAT3D avGouraudNormals[MAX_GOURAUDNORMALS] = {
FLOAT3D( 1.000000f, 0.000000f, 0.000000f),
FLOAT3D( 0.980785f, 0.000000f, 0.195090f),
FLOAT3D( 0.980785f, 0.195090f, 0.000000f),
FLOAT3D( 0.923880f, 0.000000f, 0.382683f),
FLOAT3D( 0.959683f, 0.198757f, 0.198757f),
FLOAT3D( 0.923880f, 0.382683f, 0.000000f),
FLOAT3D( 0.831470f, 0.000000f, 0.555570f),
FLOAT3D( 0.890320f, 0.208847f, 0.404615f),
FLOAT3D( 0.707107f, 0.000000f, 0.707107f),
FLOAT3D( 0.788675f, 0.211325f, 0.577350f),
FLOAT3D( 0.816497f, 0.408248f, 0.408248f),
FLOAT3D( 0.831470f, 0.555570f, 0.000000f),
FLOAT3D( 0.788675f, 0.577350f, 0.211325f),
FLOAT3D( 0.707107f, 0.707107f, 0.000000f),
FLOAT3D( 0.555570f, 0.000000f, 0.831470f),
FLOAT3D( 0.577350f, 0.211325f, 0.788675f),
FLOAT3D( 0.382683f, 0.000000f, 0.923880f),
FLOAT3D( 0.404615f, 0.208847f, 0.890320f),
FLOAT3D( 0.408248f, 0.408248f, 0.816497f),
FLOAT3D( 0.195090f, 0.000000f, 0.980785f),
FLOAT3D( 0.198757f, 0.198757f, 0.959683f),
FLOAT3D( 0.000000f, 0.000000f, 1.000000f),
FLOAT3D( 0.000000f, 0.195090f, 0.980785f),
FLOAT3D( 0.000000f, 0.382683f, 0.923880f),
FLOAT3D( 0.208847f, 0.404615f, 0.890320f),
FLOAT3D( 0.211325f, 0.577350f, 0.788675f),
FLOAT3D( 0.000000f, 0.555570f, 0.831470f),
FLOAT3D( 0.000000f, 0.707107f, 0.707107f),
FLOAT3D( 0.577350f, 0.788675f, 0.211325f),
FLOAT3D( 0.639602f, 0.639602f, 0.426401f),
FLOAT3D( 0.408248f, 0.816497f, 0.408248f),
FLOAT3D( 0.639602f, 0.426401f, 0.639602f),
FLOAT3D( 0.426401f, 0.639602f, 0.639602f),
FLOAT3D( 0.211325f, 0.788675f, 0.577350f),
FLOAT3D( 0.555570f, 0.831470f, 0.000000f),
FLOAT3D( 0.404615f, 0.890320f, 0.208847f),
FLOAT3D( 0.382683f, 0.923880f, 0.000000f),
FLOAT3D( 0.208847f, 0.890320f, 0.404615f),
FLOAT3D( 0.000000f, 0.831470f, 0.555570f),
FLOAT3D( 0.000000f, 0.923880f, 0.382683f),
FLOAT3D( 0.198757f, 0.959683f, 0.198757f),
FLOAT3D( 0.195090f, 0.980785f, 0.000000f),
FLOAT3D( 0.000000f, 0.980785f, 0.195090f),
FLOAT3D( 0.000000f, 1.000000f, 0.000000f),
FLOAT3D( -0.195090f, 0.980785f, 0.000000f),
FLOAT3D( -0.198757f, 0.959683f, 0.198757f),
FLOAT3D( -0.382683f, 0.923880f, 0.000000f),
FLOAT3D( -0.208847f, 0.890320f, 0.404615f),
FLOAT3D( -0.211325f, 0.788675f, 0.577350f),
FLOAT3D( -0.408248f, 0.816497f, 0.408248f),
FLOAT3D( -0.404615f, 0.890320f, 0.208847f),
FLOAT3D( -0.555570f, 0.831470f, 0.000000f),
FLOAT3D( -0.577350f, 0.788675f, 0.211325f),
FLOAT3D( -0.707107f, 0.707107f, 0.000000f),
FLOAT3D( -0.211325f, 0.577350f, 0.788675f),
FLOAT3D( -0.208847f, 0.404615f, 0.890320f),
FLOAT3D( -0.408248f, 0.408248f, 0.816497f),
FLOAT3D( -0.198757f, 0.198757f, 0.959683f),
FLOAT3D( -0.195090f, 0.000000f, 0.980785f),
FLOAT3D( -0.382683f, 0.000000f, 0.923880f),
FLOAT3D( -0.404615f, 0.208847f, 0.890320f),
FLOAT3D( -0.577350f, 0.211325f, 0.788675f),
FLOAT3D( -0.555570f, 0.000000f, 0.831470f),
FLOAT3D( -0.707107f, 0.000000f, 0.707107f),
FLOAT3D( -0.788675f, 0.577350f, 0.211325f),
FLOAT3D( -0.639602f, 0.639602f, 0.426401f),
FLOAT3D( -0.816497f, 0.408248f, 0.408248f),
FLOAT3D( -0.426401f, 0.639602f, 0.639602f),
FLOAT3D( -0.639602f, 0.426401f, 0.639602f),
FLOAT3D( -0.788675f, 0.211325f, 0.577350f),
FLOAT3D( -0.831470f, 0.555570f, 0.000000f),
FLOAT3D( -0.890320f, 0.404615f, 0.208847f),
FLOAT3D( -0.923880f, 0.382683f, 0.000000f),
FLOAT3D( -0.890320f, 0.208847f, 0.404615f),
FLOAT3D( -0.831470f, 0.000000f, 0.555570f),
FLOAT3D( -0.923880f, 0.000000f, 0.382683f),
FLOAT3D( -0.959683f, 0.198757f, 0.198757f),
FLOAT3D( -0.980785f, 0.195090f, 0.000000f),
FLOAT3D( -0.980785f, 0.000000f, 0.195090f),
FLOAT3D( -1.000000f, 0.000000f, 0.000000f),
FLOAT3D( -0.980785f, -0.195090f, 0.000000f),
FLOAT3D( -0.959683f, -0.198757f, 0.198757f),
FLOAT3D( -0.923880f, -0.382683f, 0.000000f),
FLOAT3D( -0.890320f, -0.208847f, 0.404615f),
FLOAT3D( -0.788675f, -0.211325f, 0.577350f),
FLOAT3D( -0.816497f, -0.408248f, 0.408248f),
FLOAT3D( -0.890320f, -0.404615f, 0.208847f),
FLOAT3D( -0.831470f, -0.555570f, 0.000000f),
FLOAT3D( -0.788675f, -0.577350f, 0.211325f),
FLOAT3D( -0.707107f, -0.707107f, 0.000000f),
FLOAT3D( -0.577350f, -0.211325f, 0.788675f),
FLOAT3D( -0.404615f, -0.208847f, 0.890320f),
FLOAT3D( -0.408248f, -0.408248f, 0.816497f),
FLOAT3D( -0.198757f, -0.198757f, 0.959683f),
FLOAT3D( 0.000000f, -0.195090f, 0.980785f),
FLOAT3D( 0.000000f, -0.382683f, 0.923880f),
FLOAT3D( -0.208847f, -0.404615f, 0.890320f),
FLOAT3D( -0.211325f, -0.577350f, 0.788675f),
FLOAT3D( 0.000000f, -0.555570f, 0.831470f),
FLOAT3D( 0.000000f, -0.707107f, 0.707107f),
FLOAT3D( -0.577350f, -0.788675f, 0.211325f),
FLOAT3D( -0.639602f, -0.639602f, 0.426401f),
FLOAT3D( -0.408248f, -0.816497f, 0.408248f),
FLOAT3D( -0.639602f, -0.426401f, 0.639602f),
FLOAT3D( -0.426401f, -0.639602f, 0.639602f),
FLOAT3D( -0.211325f, -0.788675f, 0.577350f),
FLOAT3D( -0.555570f, -0.831470f, 0.000000f),
FLOAT3D( -0.404615f, -0.890320f, 0.208847f),
FLOAT3D( -0.382683f, -0.923880f, 0.000000f),
FLOAT3D( -0.208847f, -0.890320f, 0.404615f),
FLOAT3D( 0.000000f, -0.831470f, 0.555570f),
FLOAT3D( 0.000000f, -0.923880f, 0.382683f),
FLOAT3D( -0.198757f, -0.959683f, 0.198757f),
FLOAT3D( -0.195090f, -0.980785f, 0.000000f),
FLOAT3D( 0.000000f, -0.980785f, 0.195090f),
FLOAT3D( 0.000000f, -1.000000f, 0.000000f),
FLOAT3D( 0.195090f, -0.980785f, 0.000000f),
FLOAT3D( 0.198757f, -0.959683f, 0.198757f),
FLOAT3D( 0.382683f, -0.923880f, 0.000000f),
FLOAT3D( 0.208847f, -0.890320f, 0.404615f),
FLOAT3D( 0.211325f, -0.788675f, 0.577350f),
FLOAT3D( 0.408248f, -0.816497f, 0.408248f),
FLOAT3D( 0.404615f, -0.890320f, 0.208847f),
FLOAT3D( 0.555570f, -0.831470f, 0.000000f),
FLOAT3D( 0.577350f, -0.788675f, 0.211325f),
FLOAT3D( 0.707107f, -0.707107f, 0.000000f),
FLOAT3D( 0.211325f, -0.577350f, 0.788675f),
FLOAT3D( 0.208847f, -0.404615f, 0.890320f),
FLOAT3D( 0.408248f, -0.408248f, 0.816497f),
FLOAT3D( 0.198757f, -0.198757f, 0.959683f),
FLOAT3D( 0.404615f, -0.208847f, 0.890320f),
FLOAT3D( 0.577350f, -0.211325f, 0.788675f),
FLOAT3D( 0.788675f, -0.577350f, 0.211325f),
FLOAT3D( 0.639602f, -0.639602f, 0.426401f),
FLOAT3D( 0.816497f, -0.408248f, 0.408248f),
FLOAT3D( 0.426401f, -0.639602f, 0.639602f),
FLOAT3D( 0.639602f, -0.426401f, 0.639602f),
FLOAT3D( 0.788675f, -0.211325f, 0.577350f),
FLOAT3D( 0.831470f, -0.555570f, 0.000000f),
FLOAT3D( 0.890320f, -0.404615f, 0.208847f),
FLOAT3D( 0.923880f, -0.382683f, 0.000000f),
FLOAT3D( 0.890320f, -0.208847f, 0.404615f),
FLOAT3D( 0.959683f, -0.198757f, 0.198757f),
FLOAT3D( 0.980785f, -0.195090f, 0.000000f),
FLOAT3D( 0.980785f, 0.000000f, -0.195090f),
FLOAT3D( 0.959683f, 0.198757f, -0.198757f),
FLOAT3D( 0.923880f, 0.000000f, -0.382683f),
FLOAT3D( 0.890320f, 0.404615f, -0.208847f),
FLOAT3D( 0.788675f, 0.577350f, -0.211325f),
FLOAT3D( 0.816497f, 0.408248f, -0.408248f),
FLOAT3D( 0.890320f, 0.208847f, -0.404615f),
FLOAT3D( 0.831470f, 0.000000f, -0.555570f),
FLOAT3D( 0.788675f, 0.211325f, -0.577350f),
FLOAT3D( 0.707107f, 0.000000f, -0.707107f),
FLOAT3D( 0.577350f, 0.788675f, -0.211325f),
FLOAT3D( 0.404615f, 0.890320f, -0.208847f),
FLOAT3D( 0.408248f, 0.816497f, -0.408248f),
FLOAT3D( 0.198757f, 0.959683f, -0.198757f),
FLOAT3D( 0.000000f, 0.923880f, -0.382683f),
FLOAT3D( 0.208847f, 0.890320f, -0.404615f),
FLOAT3D( 0.211325f, 0.788675f, -0.577350f),
FLOAT3D( 0.000000f, 0.831470f, -0.555570f),
FLOAT3D( 0.000000f, 0.707107f, -0.707107f),
FLOAT3D( 0.577350f, 0.211325f, -0.788675f),
FLOAT3D( 0.639602f, 0.426401f, -0.639602f),
FLOAT3D( 0.408248f, 0.408248f, -0.816497f),
FLOAT3D( 0.639602f, 0.639602f, -0.426401f),
FLOAT3D( 0.426401f, 0.639602f, -0.639602f),
FLOAT3D( 0.211325f, 0.577350f, -0.788675f),
FLOAT3D( 0.555570f, 0.000000f, -0.831470f),
FLOAT3D( 0.404615f, 0.208847f, -0.890320f),
FLOAT3D( 0.382683f, 0.000000f, -0.923880f),
FLOAT3D( 0.208847f, 0.404615f, -0.890320f),
FLOAT3D( 0.000000f, 0.555570f, -0.831470f),
FLOAT3D( 0.000000f, 0.382683f, -0.923880f),
FLOAT3D( 0.198757f, 0.198757f, -0.959683f),
FLOAT3D( 0.195090f, 0.000000f, -0.980785f),
FLOAT3D( 0.000000f, 0.195090f, -0.980785f),
FLOAT3D( 0.000000f, 0.000000f, -1.000000f),
FLOAT3D( -0.198757f, 0.959683f, -0.198757f),
FLOAT3D( -0.404615f, 0.890320f, -0.208847f),
FLOAT3D( -0.577350f, 0.788675f, -0.211325f),
FLOAT3D( -0.408248f, 0.816497f, -0.408248f),
FLOAT3D( -0.208847f, 0.890320f, -0.404615f),
FLOAT3D( -0.211325f, 0.788675f, -0.577350f),
FLOAT3D( -0.788675f, 0.577350f, -0.211325f),
FLOAT3D( -0.890320f, 0.404615f, -0.208847f),
FLOAT3D( -0.816497f, 0.408248f, -0.408248f),
FLOAT3D( -0.959683f, 0.198757f, -0.198757f),
FLOAT3D( -0.980785f, 0.000000f, -0.195090f),
FLOAT3D( -0.923880f, 0.000000f, -0.382683f),
FLOAT3D( -0.890320f, 0.208847f, -0.404615f),
FLOAT3D( -0.788675f, 0.211325f, -0.577350f),
FLOAT3D( -0.831470f, 0.000000f, -0.555570f),
FLOAT3D( -0.707107f, 0.000000f, -0.707107f),
FLOAT3D( -0.211325f, 0.577350f, -0.788675f),
FLOAT3D( -0.426401f, 0.639602f, -0.639602f),
FLOAT3D( -0.408248f, 0.408248f, -0.816497f),
FLOAT3D( -0.639602f, 0.639602f, -0.426401f),
FLOAT3D( -0.639602f, 0.426401f, -0.639602f),
FLOAT3D( -0.577350f, 0.211325f, -0.788675f),
FLOAT3D( -0.208847f, 0.404615f, -0.890320f),
FLOAT3D( -0.404615f, 0.208847f, -0.890320f),
FLOAT3D( -0.555570f, 0.000000f, -0.831470f),
FLOAT3D( -0.382683f, 0.000000f, -0.923880f),
FLOAT3D( -0.198757f, 0.198757f, -0.959683f),
FLOAT3D( -0.195090f, 0.000000f, -0.980785f),
FLOAT3D( -0.959683f, -0.198757f, -0.198757f),
FLOAT3D( -0.890320f, -0.404615f, -0.208847f),
FLOAT3D( -0.788675f, -0.577350f, -0.211325f),
FLOAT3D( -0.816497f, -0.408248f, -0.408248f),
FLOAT3D( -0.890320f, -0.208847f, -0.404615f),
FLOAT3D( -0.788675f, -0.211325f, -0.577350f),
FLOAT3D( -0.577350f, -0.788675f, -0.211325f),
FLOAT3D( -0.404615f, -0.890320f, -0.208847f),
FLOAT3D( -0.408248f, -0.816497f, -0.408248f),
FLOAT3D( -0.198757f, -0.959683f, -0.198757f),
FLOAT3D( 0.000000f, -0.980785f, -0.195090f),
FLOAT3D( 0.000000f, -0.923880f, -0.382683f),
FLOAT3D( -0.208847f, -0.890320f, -0.404615f),
FLOAT3D( -0.211325f, -0.788675f, -0.577350f),
FLOAT3D( 0.000000f, -0.831470f, -0.555570f),
FLOAT3D( 0.000000f, -0.707107f, -0.707107f),
FLOAT3D( -0.577350f, -0.211325f, -0.788675f),
FLOAT3D( -0.639602f, -0.426401f, -0.639602f),
FLOAT3D( -0.408248f, -0.408248f, -0.816497f),
FLOAT3D( -0.639602f, -0.639602f, -0.426401f),
FLOAT3D( -0.426401f, -0.639602f, -0.639602f),
FLOAT3D( -0.211325f, -0.577350f, -0.788675f),
FLOAT3D( -0.404615f, -0.208847f, -0.890320f),
FLOAT3D( -0.208847f, -0.404615f, -0.890320f),
FLOAT3D( 0.000000f, -0.555570f, -0.831470f),
FLOAT3D( 0.000000f, -0.382683f, -0.923880f),
FLOAT3D( -0.198757f, -0.198757f, -0.959683f),
FLOAT3D( 0.000000f, -0.195090f, -0.980785f),
FLOAT3D( 0.198757f, -0.959683f, -0.198757f),
FLOAT3D( 0.404615f, -0.890320f, -0.208847f),
FLOAT3D( 0.577350f, -0.788675f, -0.211325f),
FLOAT3D( 0.408248f, -0.816497f, -0.408248f),
FLOAT3D( 0.208847f, -0.890320f, -0.404615f),
FLOAT3D( 0.211325f, -0.788675f, -0.577350f),
FLOAT3D( 0.788675f, -0.577350f, -0.211325f),
FLOAT3D( 0.890320f, -0.404615f, -0.208847f),
FLOAT3D( 0.816497f, -0.408248f, -0.408248f),
FLOAT3D( 0.959683f, -0.198757f, -0.198757f),
FLOAT3D( 0.890320f, -0.208847f, -0.404615f),
FLOAT3D( 0.788675f, -0.211325f, -0.577350f),
FLOAT3D( 0.211325f, -0.577350f, -0.788675f),
FLOAT3D( 0.426401f, -0.639602f, -0.639602f),
FLOAT3D( 0.408248f, -0.408248f, -0.816497f),
FLOAT3D( 0.639602f, -0.639602f, -0.426401f),
FLOAT3D( 0.639602f, -0.426401f, -0.639602f),
FLOAT3D( 0.577350f, -0.211325f, -0.788675f),
FLOAT3D( 0.208847f, -0.404615f, -0.890320f),
FLOAT3D( 0.404615f, -0.208847f, -0.890320f),
FLOAT3D( 0.198757f, -0.198757f, -0.959683f),
};
/* Find nearest Gouraud normal for a vector. */
INDEX GouraudNormal( const FLOAT3D &vNormal)
{
INDEX i, besti;
FLOAT p, bestp;
// find the Gouraud normal that makes smallest dot product with given vector
besti = 0;
bestp = 0.0f;
for( i=0; i<MAX_GOURAUDNORMALS; i++) {
p = avGouraudNormals[i] % vNormal;
if( p>bestp) {
bestp = p;
besti = i;
}
}
return besti;
}