Starting to clean up a bit of Kal's mess

I still don't know why Git reacts so strangely to the new files' line breaks...
This commit is contained in:
RedEnchilada 2015-04-25 22:22:50 -05:00
parent bac34d783e
commit 5070a964b9
3 changed files with 135 additions and 434 deletions

View file

@ -357,28 +357,6 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FixedRound(fixed_t x)
return INT32_MAX;
}
/*!
\brief convert a fixed_t number into double floating number
*/
#define FIXED_TO_DOUBLE(f) ((double)((f) / FRACUNIT))
/*!
\brief convert a double floating number into fixed_t number
*/
#define DOUBLE_TO_FIXED(f) ((fixed_t)((f) * FRACUNIT))
/*!
\brief convert a integer into fixed_t number
*/
#define INT_TO_FIXED(x) ((int)((x) * FRACUNIT))
/*!
\brief convert a fixed_t number into integer
*/
#define FIXED_TO_INT(x) (((int)(x)) / (FRACUNIT))
static inline int DivScale32 (fixed_t a, fixed_t b) { return (fixed_t)(((INT64)a << 32) / b); }
#ifdef NEED_FIXED_VECTOR

View file

@ -1,4 +1,4 @@
// Emacs style mode select -*- C++ -*-
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// Copyright(C) 2004 Stephen McGranahan
@ -7,12 +7,12 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -87,32 +87,32 @@ v3float_t *M_MakeVec3f(const v3float_t *point1, const v3float_t *point2, v3float
return a_o;
}
//
//
// M_TranslateVec3
//
// Translates the given vector (in the game's coordinate system) to the camera
// space (in right-handed coordinate system) This function is used for slopes.
//
//
void M_TranslateVec3(v3fixed_t *vec)
{
fixed_t tx, ty, tz;
tx = vec->x - viewx;
ty = viewz - vec->y;
tz = vec->z - viewy;
// Just like wall projection.
vec->x = (tx * viewcos) - (tz * viewsin);
vec->z = (tz * viewcos) + (tx * viewsin);
vec->y = ty;
}
//
//
// M_TranslateVec3f
//
// Translates the given vector (in the game's coordinate system) to the camera
// space (in right-handed coordinate system) This function is used for slopes.
//
//
void M_TranslateVec3f(v3float_t *vec)
{
float tx, ty, tz;
@ -128,20 +128,20 @@ void M_TranslateVec3f(v3float_t *vec)
}
#ifdef SESLOPE
//
//
// M_TranslateVec3d
//
// Translates the given vector (in the game's coordinate system) to the camera
// space (in right-handed coordinate system) This function is used for slopes.
//
//
void M_TranslateVec3d(v3double_t *vec)
{
double tx, ty, tz;
tx = vec->x - viewx; // SRB2CBTODO: This may need float viewxyz
ty = viewz - vec->y;
tz = vec->z - viewy;
// Just like wall projection.
vec->x = (tx * viewcos) - (tz * viewsin);
vec->z = (tz * viewcos) + (tx * viewsin);
@ -185,7 +185,7 @@ void M_SubVec3(v3fixed_t *dest, const v3fixed_t *v1, const v3fixed_t *v2) // SRB
dest->z = v1->z - v2->z;
}
//
//
// M_SubVec3f
//
// Subtracts v2 from v1 stores in dest
@ -197,7 +197,7 @@ void M_SubVec3f(v3float_t *dest, const v3float_t *v1, const v3float_t *v2)
dest->z = v1->z - v2->z;
}
//
//
// M_DotVec3
//
// Returns the dot product of v1 and v2
@ -207,7 +207,7 @@ fixed_t M_DotVec3(const v3fixed_t *v1, const v3fixed_t *v2)
return FixedMul(v1->x, v2->x) + FixedMul(v1->y, v2->y) + FixedMul(v1->z, v2->z);
}
//
//
// M_DotVec3f
//
// Returns the dot product of v1 and v2
@ -216,13 +216,11 @@ float M_DotVec3f(const v3float_t *v1, const v3float_t *v2)
{
if (!v1 || !v2)
I_Error("M_DotVec3f: No vertexes!");
if (!(v1 || v2 || v1->x || v1->y || v1->z || v2->x || v2->y || v2->z))
I_Error("M_DotVec3f: No vertexes!");
return (v1->x * v2->x) + (v1->y * v2->y) + (v1->z * v2->z);
return (v1->x * v2->x) + (v1->y * v2->y) + (v1->z * v2->z);
}
#ifdef SESLOPE
//
//
// M_DotVec3d
//
// Returns the dot product of v1 and v2
@ -236,7 +234,7 @@ double M_DotVec3d(const v3double_t *v1, const v3double_t *v2)
//
// M_CrossProduct3
//
// Gets the cross product of v1 and v2 and stores in dest
// Gets the cross product of v1 and v2 and stores in dest
//
void M_CrossProduct3(v3fixed_t *dest, const v3fixed_t *v1, const v3fixed_t *v2)
{
@ -250,7 +248,7 @@ void M_CrossProduct3(v3fixed_t *dest, const v3fixed_t *v1, const v3fixed_t *v2)
//
// M_CrossProduct3f
//
// Gets the cross product of v1 and v2 and stores in dest
// Gets the cross product of v1 and v2 and stores in dest
//
void M_CrossProduct3f(v3float_t *dest, const v3float_t *v1, const v3float_t *v2)
{
@ -316,7 +314,7 @@ v3float_t *FV_Midpointf(const v3float_t *a_1, const v3float_t *a_2, v3float_t *a
// This checks to see if a point is inside the ranges of a polygon
//
angle_t FV_AngleBetweenVectors(const v3fixed_t *Vector1, const v3fixed_t *Vector2)
{
{
// Remember, above we said that the Dot Product of returns the cosine of the angle
// between 2 vectors? Well, that is assuming they are unit vectors (normalize vectors).
// So, if we don't have a unit vector, then instead of just saying arcCos(DotProduct(A, B))
@ -324,19 +322,19 @@ angle_t FV_AngleBetweenVectors(const v3fixed_t *Vector1, const v3fixed_t *Vector
// Here is the equation: arc cosine of (V . W / || V || * || W || )
// the || V || means the magnitude of V. This then cancels out the magnitudes dot product magnitudes.
// But basically, if you have normalize vectors already, you can forget about the magnitude part.
// Get the dot product of the vectors
fixed_t dotProduct = M_DotVec3(Vector1, Vector2);
// Get the product of both of the vectors magnitudes
fixed_t vectorsMagnitude = FixedMul(FV_Magnitude(Vector1), FV_Magnitude(Vector2));
// Return the arc cosine of the (dotProduct / vectorsMagnitude) which is the angle in RADIANS.
return FixedAcos(FixedDiv(dotProduct, vectorsMagnitude));
}
float FV_AngleBetweenVectorsf(const v3float_t *Vector1, const v3float_t *Vector2)
{
{
// Remember, above we said that the Dot Product of returns the cosine of the angle
// between 2 vectors? Well, that is assuming they are unit vectors (normalize vectors).
// So, if we don't have a unit vector, then instead of just saying arcCos(DotProduct(A, B))
@ -344,13 +342,13 @@ float FV_AngleBetweenVectorsf(const v3float_t *Vector1, const v3float_t *Vector2
// Here is the equation: arc cosine of (V . W / || V || * || W || )
// the || V || means the magnitude of V. This then cancels out the magnitudes dot product magnitudes.
// But basically, if you have normalize vectors already, you can forget about the magnitude part.
// Get the dot product of the vectors
float dotProduct = M_DotVec3f(Vector1, Vector2);
// Get the product of both of the vectors magnitudes
float vectorsMagnitude = FV_Magnitudef(Vector1)*FV_Magnitudef(Vector2);
// Return the arc cosine of the (dotProduct / vectorsMagnitude) which is the angle in RADIANS.
return acos(dotProduct/vectorsMagnitude);
}
@ -370,7 +368,7 @@ float M_VectorPitch(v3float_t v)
#include "z_zone.h"
// Returns pitch roll and yaw values, allows objects to align to a slope
// Returns pitch roll and yaw values, allows objects to align to a slope
angles3d_t *M_VectorAlignTo(float Pitch, float Yaw, float Roll, v3float_t v, byte AngleAxis, float Rate)
{
CONS_Printf("P %f\n", Pitch);
@ -380,7 +378,7 @@ angles3d_t *M_VectorAlignTo(float Pitch, float Yaw, float Roll, v3float_t v, byt
{
float DestYaw = (atan2(v.z,v.x)* 180 / M_PI);
float DestRoll = (atan2(v.y,v.x)* 180 / M_PI);
Yaw = Yaw+(DestYaw-Yaw)*Rate;
Roll = Roll+(DestRoll-Roll)*Rate;
}
@ -388,7 +386,7 @@ angles3d_t *M_VectorAlignTo(float Pitch, float Yaw, float Roll, v3float_t v, byt
{
float DestPitch = (atan2(v.z,v.y)* 180 / M_PI);
float DestRoll = (-atan2(v.x,v.y)* 180 / M_PI);
Pitch = Pitch+(DestPitch-Pitch)*Rate;
Roll = Roll+(DestRoll-Roll)*Rate;
}
@ -396,19 +394,19 @@ angles3d_t *M_VectorAlignTo(float Pitch, float Yaw, float Roll, v3float_t v, byt
{
float DestPitch = (-atan2(v.y,v.z)* 180 / M_PI);
float DestYaw = (-atan2(v.x,v.z)* 180 / M_PI);
Pitch = Pitch+(DestPitch-Pitch)*Rate;
Yaw = Yaw+(DestYaw-Yaw)*Rate;
}
angles3d_t *returnangles = Z_Malloc(sizeof(angles3d_t), PU_LEVEL, NULL);
memset(returnangles, 0, sizeof(*returnangles));
returnangles->yaw = Yaw;
returnangles->pitch = Pitch;
returnangles->roll = Roll;
return returnangles;
}
@ -427,28 +425,28 @@ v3fixed_t *FV_SubO(const v3fixed_t *a_i, const v3fixed_t *a_c, v3fixed_t *a_o)
boolean FV_Equal(const v3fixed_t *a_1, const v3fixed_t *a_2)
{
fixed_t Epsilon = FRACUNIT/FRACUNIT;
if ((abs(a_2->x - a_1->x) > Epsilon) ||
(abs(a_2->y - a_1->y) > Epsilon) ||
(abs(a_2->z - a_1->z) > Epsilon))
{
return true;
}
return false;
}
boolean FV_Equalf(const v3float_t *a_1, const v3float_t *a_2)
{
float Epsilon = 1.0f/1.0f;
if ((abs(a_2->x - a_1->x) > Epsilon) ||
(abs(a_2->y - a_1->y) > Epsilon) ||
(abs(a_2->z - a_1->z) > Epsilon))
{
return true;
}
return false;
}
@ -461,12 +459,12 @@ void FV_Normal (const v3fixed_t *a_triangle, v3fixed_t *a_normal)
{
v3fixed_t a_1;
v3fixed_t a_2;
FV_Point2Vec(&a_triangle[2], &a_triangle[0], &a_1);
FV_Point2Vec(&a_triangle[1], &a_triangle[0], &a_2);
FV_Cross(&a_1, &a_2, a_normal);
FV_NormalizeO(a_normal, a_normal);
}
@ -474,30 +472,30 @@ void FV_Normal (const v3fixed_t *a_triangle, v3fixed_t *a_normal)
// PlaneDistance
//
// Calculates distance between a plane and the origin.
//
//
fixed_t FV_PlaneDistance(const v3fixed_t *a_normal, const v3fixed_t *a_point)
{
{
return -(FixedMul(a_normal->x, a_point->x) + FixedMul(a_normal->y, a_point->y) + FixedMul(a_normal->z, a_point->z));
}
boolean FV_IntersectedPlane(const v3fixed_t *a_triangle, const v3fixed_t *a_line, v3fixed_t *a_normal, fixed_t *originDistance)
{
fixed_t distance1 = 0, distance2 = 0;
FV_Normal(a_triangle, a_normal);
*originDistance = FV_PlaneDistance(a_normal, &a_triangle[0]);
distance1 = (FixedMul(a_normal->x, a_line[0].x) + FixedMul(a_normal->y, a_line[0].y)
+ FixedMul(a_normal->z, a_line[0].z)) + *originDistance;
distance2 = (FixedMul(a_normal->x, a_line[1].x) + FixedMul(a_normal->y, a_line[1].y)
+ FixedMul(a_normal->z, a_line[1].z)) + *originDistance;
// Positive or zero number means no intersection
if (FixedMul(distance1, distance2) >= 0)
return false;
return true;
}
@ -522,7 +520,7 @@ fixed_t FV_PlaneIntersection(const v3fixed_t *pOrigin, const v3fixed_t *pNormal,
// IntersectRaySphere
// Input : rO - origin of ray in world space
// rV - vector describing direction of ray in world space
// sO - Origin of sphere
// sO - Origin of sphere
// sR - radius of sphere
// Notes : Normalized directional vectors expected
// Return: distance to sphere in world units, -1 if no intersection.
@ -532,15 +530,15 @@ fixed_t FV_IntersectRaySphere(const v3fixed_t *rO, const v3fixed_t *rV, const v3
v3fixed_t Q;
fixed_t c, v, d;
FV_SubO(sO, rO, &Q);
c = FV_Magnitude(&Q);
v = FV_Dot(&Q, rV);
d = FixedMul(sR, sR) - (FixedMul(c,c) - FixedMul(v,v));
// If there was no intersection, return -1
if (d < 0*FRACUNIT)
return (-1*FRACUNIT);
// Return the distance to the [first] intersecting point
return (v - FixedSqrt(d));
}
@ -554,15 +552,15 @@ v3fixed_t *FV_IntersectionPoint(const v3fixed_t *vNormal, const v3fixed_t *vLine
{
v3fixed_t vLineDir; // Variables to hold the point and the line's direction
fixed_t Numerator = 0, Denominator = 0, dist = 0;
// Here comes the confusing part. We need to find the 3D point that is actually
// on the plane. Here are some steps to do that:
// 1) First we need to get the vector of our line, Then normalize it so it's a length of 1
FV_Point2Vec(&vLine[1], &vLine[0], &vLineDir); // Get the Vector of the line
FV_NormalizeO(&vLineDir, &vLineDir); // Normalize the lines vector
// 2) Use the plane equation (distance = Ax + By + Cz + D) to find the distance from one of our points to the plane.
// Here I just chose a arbitrary point as the point to find that distance. You notice we negate that
// distance. We negate the distance because we want to eventually go BACKWARDS from our point to the plane.
@ -570,17 +568,17 @@ v3fixed_t *FV_IntersectionPoint(const v3fixed_t *vNormal, const v3fixed_t *vLine
Numerator = - (FixedMul(vNormal->x, vLine[0].x) + // Use the plane equation with the normal and the line
FixedMul(vNormal->y, vLine[0].y) +
FixedMul(vNormal->z, vLine[0].z) + distance);
// 3) If we take the dot product between our line vector and the normal of the polygon,
// this will give us the cosine of the angle between the 2 (since they are both normalized - length 1).
// We will then divide our Numerator by this value to find the offset towards the plane from our arbitrary point.
Denominator = FV_Dot(vNormal, &vLineDir); // Get the dot product of the line's vector and the normal of the plane
// Since we are using division, we need to make sure we don't get a divide by zero error
// If we do get a 0, that means that there are INFINITE points because the the line is
// on the plane (the normal is perpendicular to the line - (Normal.Vector = 0)).
// on the plane (the normal is perpendicular to the line - (Normal.Vector = 0)).
// In this case, we should just return any point on the line.
if( Denominator == 0*FRACUNIT) // Check so we don't divide by zero
{
ReturnVec->x = vLine[0].x;
@ -588,7 +586,7 @@ v3fixed_t *FV_IntersectionPoint(const v3fixed_t *vNormal, const v3fixed_t *vLine
ReturnVec->z = vLine[0].z;
return ReturnVec; // Return an arbitrary point on the line
}
// We divide the (distance from the point to the plane) by (the dot product)
// to get the distance (dist) that we need to move from our arbitrary point. We need
// to then times this distance (dist) by our line's vector (direction). When you times
@ -601,13 +599,13 @@ v3fixed_t *FV_IntersectionPoint(const v3fixed_t *vNormal, const v3fixed_t *vLine
// way down the line's length. The distance from the plane is short, but the distance from
// the actual intersection point is pretty long. If we divide the distance by the dot product
// of our line vector and the normal of the plane, we get the correct length. Cool huh?
dist = FixedDiv(Numerator, Denominator); // Divide to get the multiplying (percentage) factor
// Now, like we said above, we times the dist by the vector, then add our arbitrary point.
// This essentially moves the point along the vector to a certain distance. This now gives
// us the intersection point. Yay!
// Return the intersection point
ReturnVec->x = vLine[0].x + FixedMul(vLineDir.x, dist);
ReturnVec->y = vLine[0].y + FixedMul(vLineDir.y, dist);
@ -639,16 +637,16 @@ unsigned int FV_PointOnLineSide(const v3fixed_t *point, const v3fixed_t *line)
boolean FV_PointInsideBox(const v3fixed_t *point, const v3fixed_t *box)
{
v3fixed_t lastLine[2];
FV_Load(&lastLine[0], box[3].x, box[3].y, box[3].z);
FV_Load(&lastLine[1], box[0].x, box[0].y, box[0].z);
if (FV_PointOnLineSide(point, &box[0])
|| FV_PointOnLineSide(point, &box[1])
|| FV_PointOnLineSide(point, &box[2])
|| FV_PointOnLineSide(point, lastLine))
return false;
return true;
}
//
@ -660,7 +658,7 @@ void FM_LoadIdentity(fmatrix_t* matrix)
{
#define M(row,col) matrix->m[col * 4 + row]
memset(matrix, 0x00, sizeof(fmatrix_t));
M(0, 0) = FRACUNIT;
M(1, 1) = FRACUNIT;
M(2, 2) = FRACUNIT;
@ -679,29 +677,29 @@ void FM_CreateObjectMatrix(fmatrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, f
v3fixed_t upcross;
v3fixed_t upvec;
v3fixed_t basevec;
FV_Load(&upvec, upx, upy, upz);
FV_Load(&basevec, anglex, angley, anglez);
FV_Cross(&upvec, &basevec, &upcross);
FV_Normalize(&upcross);
FM_LoadIdentity(matrix);
matrix->m[0] = upcross.x;
matrix->m[1] = upcross.y;
matrix->m[2] = upcross.z;
matrix->m[3] = 0*FRACUNIT;
matrix->m[4] = upx;
matrix->m[5] = upy;
matrix->m[6] = upz;
matrix->m[7] = 0;
matrix->m[8] = anglex;
matrix->m[9] = angley;
matrix->m[10] = anglez;
matrix->m[11] = 0;
matrix->m[12] = x - FixedMul(upx,radius);
matrix->m[13] = y - FixedMul(upy,radius);
matrix->m[14] = z - FixedMul(upz,radius);
@ -720,12 +718,12 @@ void FM_MultMatrixVec(const fmatrix_t *matrix, const v3fixed_t *vec, v3fixed_t *
+ FixedMul(vec->y,M(0, 1))
+ FixedMul(vec->z,M(0, 2))
+ M(0, 3);
out->y = FixedMul(vec->x,M(1, 0))
+ FixedMul(vec->y,M(1, 1))
+ FixedMul(vec->z,M(1, 2))
+ M(1, 3);
out->z = FixedMul(vec->x,M(2, 0))
+ FixedMul(vec->y,M(2, 1))
+ FixedMul(vec->z,M(2, 2))
@ -745,15 +743,15 @@ void FM_MultMatrix(fmatrix_t *dest, const fmatrix_t *multme)
#define M(row,col) multme->m[col * 4 + row]
#define D(row,col) dest->m[col * 4 + row]
#define R(row,col) result.m[col * 4 + row]
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
R(i, j) = FixedMul(D(i, 0),M(0, j)) + FixedMul(D(i, 1),M(1, j)) + FixedMul(D(i, 2),M(2, j)) + FixedMul(D(i, 3),M(3, j));
}
M_Memcpy(dest, &result, sizeof(fmatrix_t));
#undef R
#undef D
#undef M
@ -768,14 +766,14 @@ void FM_Translate(fmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
{
fmatrix_t trans;
#define M(row,col) trans.m[col * 4 + row]
memset(&trans, 0x00, sizeof(fmatrix_t));
M(0, 0) = M(1, 1) = M(2, 2) = M(3, 3) = FRACUNIT;
M(0, 3) = x;
M(1, 3) = y;
M(2, 3) = z;
FM_MultMatrix(dest, &trans);
#undef M
}
@ -789,14 +787,14 @@ void FM_Scale(fmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
{
fmatrix_t scale;
#define M(row,col) scale.m[col * 4 + row]
memset(&scale, 0x00, sizeof(fmatrix_t));
M(3, 3) = FRACUNIT;
M(0, 0) = x;
M(1, 1) = y;
M(2, 2) = z;
FM_MultMatrix(dest, &scale);
#undef M
}
@ -824,10 +822,10 @@ v3fixed_t *FV_ClosestPointOnLine(const v3fixed_t *Line, const v3fixed_t *p, v3fi
FV_SubO(p, &Line[0], &c);
FV_SubO(&Line[1], &Line[0], &V);
FV_NormalizeO(&V, &V);
d = FV_Distance(&Line[0], &Line[1]);
t = FV_Dot(&V, &c);
// Check to see if ëtí is beyond the extents of the line segment
if (t < 0)
{
@ -837,10 +835,10 @@ v3fixed_t *FV_ClosestPointOnLine(const v3fixed_t *Line, const v3fixed_t *p, v3fi
{
return FV_Copy(out, &Line[1]);
}
// Return the point between ëLine[0]í and ëLine[1]í
FV_Mul(&V, t);
return FV_AddO(&Line[0], &V, out);
}
@ -857,33 +855,33 @@ void FV_ClosestPointOnTriangle (const v3fixed_t *tri, const v3fixed_t *point, v3
fixed_t dist, closestdist;
v3fixed_t EdgePoints[3];
v3fixed_t Line[2];
FV_Copy(&Line[0], (v3fixed_t*)&tri[0]);
FV_Copy(&Line[1], (v3fixed_t*)&tri[1]);
FV_ClosestPointOnLine(Line, point, &EdgePoints[0]);
FV_Copy(&Line[0], (v3fixed_t*)&tri[1]);
FV_Copy(&Line[1], (v3fixed_t*)&tri[2]);
FV_ClosestPointOnLine(Line, point, &EdgePoints[1]);
FV_Copy(&Line[0], (v3fixed_t*)&tri[2]);
FV_Copy(&Line[1], (v3fixed_t*)&tri[0]);
FV_ClosestPointOnLine(Line, point, &EdgePoints[2]);
// Find the closest one of the three
FV_Copy(result, &EdgePoints[0]);
closestdist = FV_Distance(point, &EdgePoints[0]);
for (i = 1; i < 3; i++)
{
dist = FV_Distance(point, &EdgePoints[i]);
if (dist < closestdist)
{
closestdist = dist;
FV_Copy(result, &EdgePoints[i]);
}
}
// We now have the closest point! Whee!
}
@ -897,7 +895,7 @@ boolean FV_InsidePolygon(const fvector_t *vIntersection, const fvector_t *Poly,
int i;
UINT64 Angle = 0; // Initialize the angle
fvector_t vA, vB; // Create temp vectors
// Just because we intersected the plane, doesn't mean we were anywhere near the polygon.
// This functions checks our intersection point to make sure it is inside of the polygon.
// This is another tough function to grasp at first, but let me try and explain.
@ -911,26 +909,26 @@ boolean FV_InsidePolygon(const fvector_t *vIntersection, const fvector_t *Poly,
// all of the angles in a triangle we get 360 right? Well, that is kinda what we are doing,
// but the inverse of that. Say your triangle is an isosceles triangle, so add up the angles
// and you will get 360 degree angles. 90 + 90 + 90 is 360.
for (i = 0; i < vertexCount; i++) // Go in a circle to each vertex and get the angle between
{
{
FV_Point2Vec(&Poly[i], vIntersection, &vA); // Subtract the intersection point from the current vertex
// Subtract the point from the next vertex
FV_Point2Vec(&Poly[(i + 1) % vertexCount], vIntersection, &vB);
Angle += FV_AngleBetweenVectors(&vA, &vB); // Find the angle between the 2 vectors and add them all up as we go along
}
// Now that we have the total angles added up, we need to check if they add up to 360 degrees.
// Since we are using the dot product, we are working in radians, so we check if the angles
// equals 2*PI. We defined PI in 3DMath.h. You will notice that we use a MATCH_FACTOR
// in conjunction with our desired degree. This is because of the inaccuracy when working
// with floating point numbers. It usually won't always be perfectly 2 * PI, so we need
// to use a little twiddling. I use .9999, but you can change this to fit your own desired accuracy.
if(Angle >= ANGLE_MAX) // If the angle is greater than 2 PI, (360 degrees)
return 1; // The point is inside of the polygon
return 0; // If you get here, it obviously wasn't inside the polygon.
}
@ -943,27 +941,27 @@ boolean FV_IntersectedPolygon(const fvector_t *vPoly, const fvector_t *vLine, co
{
fvector_t vNormal, vIntersection;
fixed_t originDistance = 0*FRACUNIT;
// First we check to see if our line intersected the plane. If this isn't true
// there is no need to go on, so return false immediately.
// We pass in address of vNormal and originDistance so we only calculate it once
if(!FV_IntersectedPlane(vPoly, vLine, &vNormal, &originDistance))
return false;
// Now that we have our normal and distance passed back from IntersectedPlane(),
// Now that we have our normal and distance passed back from IntersectedPlane(),
// we can use it to calculate the intersection point. The intersection point
// is the point that actually is ON the plane. It is between the line. We need
// this point test next, if we are inside the polygon. To get the I-Point, we
// give our function the normal of the plane, the points of the line, and the originDistance.
FV_IntersectionPoint(&vNormal, vLine, originDistance, &vIntersection);
// Now that we have the intersection point, we need to test if it's inside the polygon.
// To do this, we pass in :
// (our intersection point, the polygon, and the number of vertices our polygon has)
if(FV_InsidePolygon(&vIntersection, vPoly, vertexCount))
{
if (collisionPoint != NULL) // Optional - load the collision point.
@ -974,7 +972,7 @@ boolean FV_IntersectedPolygon(const fvector_t *vPoly, const fvector_t *vLine, co
}
return true; // We collided!
}
// If we get here, we must have NOT collided
return false;
}
@ -1017,7 +1015,7 @@ void FV_Rotate(fvector_t *rotVec, const fvector_t *axisVec, const angle_t angle)
fixed_t ex = FixedMul(vz-wy, sa);
fixed_t ey = FixedMul(wx-uz, sa);
fixed_t ez = FixedMul(uy-vx, sa);
rotVec->x = ax+dx+ex;
rotVec->y = ay+dy+ey;
rotVec->z = az+dz+ez;
@ -1033,41 +1031,41 @@ void FM_Rotate(fmatrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z)
fixed_t xSq, ySq, zSq;
fixed_t sx, sy, sz;
fixed_t sxy, sxz, syz;
FV_Normalize(&nrm);
x = nrm.x;
y = nrm.y;
z = nrm.z;
xSq = FixedMul(x, FixedMul(invCosA,x));
ySq = FixedMul(y, FixedMul(invCosA,y));
zSq = FixedMul(z, FixedMul(invCosA,z));
sx = FixedMul(sinA, x);
sy = FixedMul(sinA, y);
sz = FixedMul(sinA, z);
sxy = FixedMul(x, FixedMul(invCosA,y));
sxz = FixedMul(x, FixedMul(invCosA,z));
syz = FixedMul(y, FixedMul(invCosA,z));
M(0, 0) = xSq + cosA;
M(1, 0) = sxy - sz;
M(2, 0) = sxz + sy;
M(3, 0) = 0;
M(0, 1) = sxy + sz;
M(1, 1) = ySq + cosA;
M(2, 1) = syz - sx;
M(3, 1) = 0;
M(0, 2) = sxz - sy;
M(1, 2) = syz + sx;
M(2, 2) = zSq + cosA;
M(3, 2) = 0;
M(0, 3) = 0;
M(1, 3) = 0;
M(2, 3) = 0;
@ -1127,12 +1125,12 @@ void FV_Normal(const v3fixed_t *a_triangle, v3fixed_t *a_normal)
{
v3fixed_t a_1;
v3fixed_t a_2;
M_MakeVec3(&a_triangle[2], &a_triangle[0], &a_1);
M_MakeVec3(&a_triangle[1], &a_triangle[0], &a_2);
M_CrossProduct3(&a_1, &a_2, a_normal);
FV_NormalizeO(a_normal, a_normal);
}
@ -1145,12 +1143,12 @@ void FV_Normalf(const v3float_t *a_triangle, v3float_t *a_normal)
{
v3float_t a_1;
v3float_t a_2;
M_MakeVec3f(&a_triangle[2], &a_triangle[0], &a_1);
M_MakeVec3f(&a_triangle[1], &a_triangle[0], &a_2);
M_CrossProduct3f(&a_1, &a_2, a_normal);
FV_NormalizeOf(a_normal, a_normal);
}

View file

@ -359,7 +359,7 @@ void P_SpawnSlope_Line(int linenum)
srcplane->a = FLOAT_TO_FIXED (fslope->normalf.x); // cross[0]
srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1]
srcplane->c = FLOAT_TO_FIXED (fslope->normalf.z); // cross[2]
srcplane->ic = DivScale32 (1, srcplane->c); // (1 << 32/srcplane->c) or FLOAT_TO_FIXED(1.0f/cross[2]);
srcplane->ic = FixedDiv(FRACUNIT, srcplane->c); // (1 << 32/srcplane->c) or FLOAT_TO_FIXED(1.0f/cross[2]);
// destheight takes the destination height used in dz
srcplane->d = -TMulScale16 (srcplane->a, line->v1->x, // x
@ -414,7 +414,7 @@ void P_SpawnSlope_Line(int linenum)
srcplane->b = FLOAT_TO_FIXED (cslope->normalf.y); // cross[1]
srcplane->c = FLOAT_TO_FIXED (cslope->normalf.z); // cross[2]
//plane->ic = FLOAT_TO_FIXED (1.f/cross[2]);
srcplane->ic = DivScale32 (1, srcplane->c); // (1 << 32/srcplane->c)
srcplane->ic = FixedDiv(FRACUNIT, srcplane->c); // (1 << 32/srcplane->c)
#ifdef SLOPETHINGS // For setting thing-based slopes
srcplane->d = -TMulScale16 (plane->a, x,
plane->b, y,
@ -523,7 +523,7 @@ void P_SpawnSlope_Line(int linenum)
srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1]
srcplane->c = FLOAT_TO_FIXED (fslope->normalf.z); // cross[2]
//plane->ic = FLOAT_TO_FIXED (1.f/cross[2]);
srcplane->ic = DivScale32 (1, srcplane->c); // (1 << 32/srcplane->c)
srcplane->ic = FixedDiv(FRACUNIT, srcplane->c); // (1 << 32/srcplane->c)
#ifdef SLOPETHINGS // For setting thing-based slopes
srcplane->d = -TMulScale16 (plane->a, x,
plane->b, y,
@ -585,7 +585,7 @@ void P_SpawnSlope_Line(int linenum)
srcplane->b = FLOAT_TO_FIXED (cslope->normalf.y); // cross[1]
srcplane->c = FLOAT_TO_FIXED (cslope->normalf.z); // cross[2]
//plane->ic = FLOAT_TO_FIXED (1.f/cross[2]);
srcplane->ic = DivScale32 (1, srcplane->c); // (1 << 32/srcplane->c)
srcplane->ic = FixedDiv(FRACUNIT, srcplane->c); // (1 << 32/srcplane->c)
#ifdef SLOPETHINGS // For setting thing-based slopes
srcplane->d = -TMulScale16 (plane->a, x,
plane->b, y,
@ -638,13 +638,6 @@ void P_CopySectorSlope(line_t *line)
#include "byteptr.h"
/*
typedef struct
{
fixed_t z1;
fixed_t z2;
} mapvert_t;*/
#include "p_setup.h"
#include "p_local.h"
@ -861,7 +854,7 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
srcplane->a = FLOAT_TO_FIXED (ret->normalf.x);
srcplane->b = FLOAT_TO_FIXED (ret->normalf.y);
srcplane->c = FLOAT_TO_FIXED (ret->normalf.z);
//srcplane->ic = DivScale32 (1, srcplane->c);
//srcplane->ic = FixedDiv(FRACUNIT, srcplane->c);
srcplane->d = -TMulScale16 (srcplane->a, vertexes[vi3].x,
srcplane->b, vertexes[vi3].y,
srcplane->c, z3);
@ -891,279 +884,11 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
}
Z_Free(datastart);
#if 0 // UDMF support
for(i = 0; i < numvertexdatas; i++)
{
if (vertexdatas[i].flags & VERTEXFLAG_ZCeilingEnabled)
{
vt_heights[1][i] = vertexdatas[i].zCeiling;
vt_found = true;
}
if (vertexdatas[i].flags & VERTEXFLAG_ZFloorEnabled)
{
vt_heights[0][i] = vertexdatas[i].zFloor;
vt_found = true;
}
}
// If vertexdata_t is ever extended for non-slope usage, this will obviously have to be deferred or removed.
delete[] vertexdatas;
vertexdatas = NULL;
numvertexdatas = 0;
#endif
}
#include "p_maputl.h"
#if 0
static void P_SlopeLineToPointo (int lineid, fixed_t x, fixed_t y, fixed_t z, boolean slopeCeil)
{
int linenum = -1;
while ((linenum = P_FindLineFromID (lineid, linenum)) != -1)
{
const line_t *line = &lines[linenum];
sector_t *sec;
secplane_t *plane;
if (P_PointOnLineSide (x, y, line) == 0)
{
sec = line->frontsector;
}
else
{
sec = line->backsector;
}
if (sec == NULL)
{
continue;
}
if (slopeCeil)
{
plane = &sec->ceilingplane;
}
else
{
plane = &sec->floorplane;
}
FVector3 p, v1, v2, cross;
p[0] = FIXED2FLOAT (line->v1->x);
p[1] = FIXED2FLOAT (line->v1->y);
p[2] = FIXED2FLOAT (plane->ZatPoint (line->v1->x, line->v1->y));
v1[0] = FIXED2FLOAT (line->dx);
v1[1] = FIXED2FLOAT (line->dy);
v1[2] = FIXED2FLOAT (plane->ZatPoint (line->v2->x, line->v2->y)) - p[2];
v2[0] = FIXED2FLOAT (x - line->v1->x);
v2[1] = FIXED2FLOAT (y - line->v1->y);
v2[2] = FIXED2FLOAT (z) - p[2];
cross = v1 ^ v2;
double len = cross.Length();
if (len == 0)
{
Printf ("Slope thing at (%d,%d) lies directly on its target line.\n", int(x>>16), int(y>>16));
return;
}
cross /= len;
// Fix backward normals
if ((cross.Z < 0 && !slopeCeil) || (cross.Z > 0 && slopeCeil))
{
cross = -cross;
}
plane->a = FLOAT2FIXED (cross[0]);
plane->b = FLOAT2FIXED (cross[1]);
plane->c = FLOAT2FIXED (cross[2]);
//plane->ic = FLOAT2FIXED (1.f/cross[2]);
plane->ic = DivScale32 (1, plane->c);
plane->d = -TMulScale16 (plane->a, x,
plane->b, y,
plane->c, z);
}
}
#else
#if 0
// P_SlopeLineToPoint, start from a specific linedef number(not tag) and slope to a mapthing with the angle of the linedef
static void P_SlopeLineToPoint(int linenum)
{
line_t *line = lines + linenum;
int special = line->special;
pslope_t *fslope = NULL, *cslope = NULL;
v3float_t origin, point;
v2float_t direction;
float dz, extent;
boolean frontfloor = (special == 386 || special == 388 || special == 393);
boolean backfloor = (special == 389 || special == 391 || special == 392);
boolean frontceil = (special == 387 || special == 388 || special == 392);
boolean backceil = (special == 390 || special == 391 || special == 393);
// SoM: We don't need the line to retain its special type
line->special = 0; //SRB2CBTODO: ESLOPE: Maybe we do need it for another to check for a plane slope?
if(!frontfloor && !backfloor && !frontceil && !backceil)
{
CONS_Printf("P_SpawnSlope_Line called with non-slope line special.\n");
return;
}
if(!line->frontsector || !line->backsector)
{
CONS_Printf("P_SpawnSlope_Line used on a line without two sides.\n");
return;
}
origin.x = (FIXED_TO_FLOAT(line->v2->x) + FIXED_TO_FLOAT(line->v1->x)) * 0.5f;
origin.y = (FIXED_TO_FLOAT(line->v2->y) + FIXED_TO_FLOAT(line->v1->y)) * 0.5f;
if(frontfloor || frontceil)
{
// Do the front sector
direction.x = line->nx;
direction.y = line->ny;
extent = P_GetExtent(line->frontsector, line, &origin, &direction);
if(extent < 0.0f)
{
CONS_Printf("P_SpawnSlope_Line failed to get frontsector extent on line number %i\n", linenum);
return;
}
// reposition the origin according to the extent
point.x = origin.x + direction.x * extent;
point.y = origin.y + direction.y * extent;
direction.x = -direction.x;
direction.y = -direction.y;
// CONS_Printf("Test: X: %f, Y: %f\n", origin.x, origin.y);
if(frontfloor)
{
point.z = FIXED_TO_FLOAT(line->frontsector->floorheight); // Startz
dz = (FIXED_TO_FLOAT(line->backsector->floorheight) - point.z) / extent; // Destinationz
fslope = line->frontsector->f_slope =
P_MakeSlope(&point, &direction, dz, false);
// Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
line->frontsector->f_slope->sourceline = line;
// Remember the way the slope is formed
fixed_t highest = line->frontsector->floorheight > line->backsector->floorheight ?
line->frontsector->floorheight : line->backsector->floorheight;
fixed_t lowest = line->frontsector->floorheight < line->backsector->floorheight ?
line->frontsector->floorheight : line->backsector->floorheight;
// This line special sets extra clipping data for the frontsector's slope
fslope->highz = line->frontsector->f_slope->highz = highest;
fslope->lowz = line->frontsector->f_slope->lowz = lowest;
// SRB2CBTODO: Get XY angle of a slope and then awesome physics! // ESLOPE:
//fslope->zangle = line->frontsector->f_slope->zangle = P_GetSlopezangle(line->frontsector, highvert, lowvert);
//100*(ANG45/45);//R_PointToAngle2(direction.x, direction.y, origin.x, origin.y);
// Get slope XY angle with secplane_t
secplane_t *srcplane = Z_Calloc(sizeof(*srcplane), PU_LEVEL, NULL);
// ZDoom secplane port!
// secplane_t! woot!
// ret = f_slope or c_slope
srcplane->a = FLOAT_TO_FIXED (fslope->normalf.x); // cross[0]
srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1]
srcplane->c = FLOAT_TO_FIXED (fslope->normalf.z); // cross[2]
//plane->ic = FLOAT_TO_FIXED (1.f/cross[2]);
srcplane->ic = DivScale32 (1, srcplane->c); // (1 << 32/srcplane->c)
#ifdef SLOPETHINGS // For setting thing-based slopes
srcplane->d = -TMulScale16 (plane->a, x,
plane->b, y,
plane->c, z);
#endif
//srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling);
//destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling);
//P_GetZAtf(ret, v2.x, v2.y)
// destheight takes the destination height used in dz
srcplane->d = -TMulScale16 (srcplane->a, line->v1->x,
srcplane->b, line->v1->y,
srcplane->c, line->backsector->floorheight);
// Sync the secplane!
fslope->secplane = line->frontsector->f_slope->secplane = *srcplane;
}
}
}
#endif
#endif
//===========================================================================
//
// P_SpawnSlopeMakers
//
//===========================================================================
#if 0
void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt)
{
FMapThing *mt;
for (mt = firstmt; mt < lastmt; ++mt)
{
if ((mt->type >= THING_SlopeFloorPointLine &&
mt->type <= THING_SetCeilingSlope) ||
mt->type==THING_VavoomFloor || mt->type==THING_VavoomCeiling)
{
fixed_t x, y, z;
secplane_t *refplane;
sector_t *sec;
x = mt->x;
y = mt->y;
sec = P_PointInSector (x, y);
if (mt->type & 1)
{
refplane = &sec->ceilingplane;
}
else
{
refplane = &sec->floorplane;
}
z = refplane->ZatPoint (x, y) + (mt->z);
if (mt->type==THING_VavoomFloor || mt->type==THING_VavoomCeiling)
{
P_VavoomSlope(sec, mt->thingid, x, y, mt->z, mt->type & 1);
}
else if (mt->type <= THING_SlopeCeilingPointLine)
{
P_SlopeLineToPoint (mt->args[0], x, y, z, mt->type & 1);
}
else
{
P_SetSlope (refplane, mt->type & 1, mt->angle, mt->args[0], x, y, z);
}
mt->type = 0;
}
}
for (mt = firstmt; mt < lastmt; ++mt)
{
if (mt->type == THING_CopyFloorPlane ||
mt->type == THING_CopyCeilingPlane)
{
P_CopyPlane (mt->args[0], mt->x, mt->y, mt->type & 1);
mt->type = 0;
}
}
P_SetSlopesFromVertexHeights(firstmt, lastmt);
}
#endif