mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-28 13:21:10 +00:00
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:
parent
bac34d783e
commit
5070a964b9
3 changed files with 135 additions and 434 deletions
|
@ -357,28 +357,6 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FixedRound(fixed_t x)
|
||||||
return INT32_MAX;
|
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
|
#ifdef NEED_FIXED_VECTOR
|
||||||
|
|
||||||
|
|
262
src/m_vector.c
262
src/m_vector.c
|
@ -1,4 +1,4 @@
|
||||||
// Emacs style mode select -*- C++ -*-
|
// Emacs style mode select -*- C++ -*-
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Copyright(C) 2004 Stephen McGranahan
|
// Copyright(C) 2004 Stephen McGranahan
|
||||||
|
@ -7,12 +7,12 @@
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
// 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;
|
return a_o;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// M_TranslateVec3
|
// M_TranslateVec3
|
||||||
//
|
//
|
||||||
// Translates the given vector (in the game's coordinate system) to the camera
|
// 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.
|
// space (in right-handed coordinate system) This function is used for slopes.
|
||||||
//
|
//
|
||||||
void M_TranslateVec3(v3fixed_t *vec)
|
void M_TranslateVec3(v3fixed_t *vec)
|
||||||
{
|
{
|
||||||
fixed_t tx, ty, tz;
|
fixed_t tx, ty, tz;
|
||||||
|
|
||||||
tx = vec->x - viewx;
|
tx = vec->x - viewx;
|
||||||
ty = viewz - vec->y;
|
ty = viewz - vec->y;
|
||||||
tz = vec->z - viewy;
|
tz = vec->z - viewy;
|
||||||
|
|
||||||
// Just like wall projection.
|
// Just like wall projection.
|
||||||
vec->x = (tx * viewcos) - (tz * viewsin);
|
vec->x = (tx * viewcos) - (tz * viewsin);
|
||||||
vec->z = (tz * viewcos) + (tx * viewsin);
|
vec->z = (tz * viewcos) + (tx * viewsin);
|
||||||
vec->y = ty;
|
vec->y = ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// M_TranslateVec3f
|
// M_TranslateVec3f
|
||||||
//
|
//
|
||||||
// Translates the given vector (in the game's coordinate system) to the camera
|
// 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.
|
// space (in right-handed coordinate system) This function is used for slopes.
|
||||||
//
|
//
|
||||||
void M_TranslateVec3f(v3float_t *vec)
|
void M_TranslateVec3f(v3float_t *vec)
|
||||||
{
|
{
|
||||||
float tx, ty, tz;
|
float tx, ty, tz;
|
||||||
|
@ -128,20 +128,20 @@ void M_TranslateVec3f(v3float_t *vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SESLOPE
|
#ifdef SESLOPE
|
||||||
//
|
//
|
||||||
// M_TranslateVec3d
|
// M_TranslateVec3d
|
||||||
//
|
//
|
||||||
// Translates the given vector (in the game's coordinate system) to the camera
|
// 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.
|
// space (in right-handed coordinate system) This function is used for slopes.
|
||||||
//
|
//
|
||||||
void M_TranslateVec3d(v3double_t *vec)
|
void M_TranslateVec3d(v3double_t *vec)
|
||||||
{
|
{
|
||||||
double tx, ty, tz;
|
double tx, ty, tz;
|
||||||
|
|
||||||
tx = vec->x - viewx; // SRB2CBTODO: This may need float viewxyz
|
tx = vec->x - viewx; // SRB2CBTODO: This may need float viewxyz
|
||||||
ty = viewz - vec->y;
|
ty = viewz - vec->y;
|
||||||
tz = vec->z - viewy;
|
tz = vec->z - viewy;
|
||||||
|
|
||||||
// Just like wall projection.
|
// Just like wall projection.
|
||||||
vec->x = (tx * viewcos) - (tz * viewsin);
|
vec->x = (tx * viewcos) - (tz * viewsin);
|
||||||
vec->z = (tz * viewcos) + (tx * 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;
|
dest->z = v1->z - v2->z;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// M_SubVec3f
|
// M_SubVec3f
|
||||||
//
|
//
|
||||||
// Subtracts v2 from v1 stores in dest
|
// 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;
|
dest->z = v1->z - v2->z;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// M_DotVec3
|
// M_DotVec3
|
||||||
//
|
//
|
||||||
// Returns the dot product of v1 and v2
|
// 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);
|
return FixedMul(v1->x, v2->x) + FixedMul(v1->y, v2->y) + FixedMul(v1->z, v2->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// M_DotVec3f
|
// M_DotVec3f
|
||||||
//
|
//
|
||||||
// Returns the dot product of v1 and v2
|
// 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)
|
if (!v1 || !v2)
|
||||||
I_Error("M_DotVec3f: No vertexes!");
|
I_Error("M_DotVec3f: No vertexes!");
|
||||||
if (!(v1 || v2 || v1->x || v1->y || v1->z || v2->x || v2->y || v2->z))
|
return (v1->x * v2->x) + (v1->y * v2->y) + (v1->z * v2->z);
|
||||||
I_Error("M_DotVec3f: No vertexes!");
|
|
||||||
return (v1->x * v2->x) + (v1->y * v2->y) + (v1->z * v2->z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SESLOPE
|
#ifdef SESLOPE
|
||||||
//
|
//
|
||||||
// M_DotVec3d
|
// M_DotVec3d
|
||||||
//
|
//
|
||||||
// Returns the dot product of v1 and v2
|
// 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
|
// 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)
|
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
|
// 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)
|
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
|
// 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)
|
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
|
// 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).
|
// 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))
|
// 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 || )
|
// 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.
|
// 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.
|
// But basically, if you have normalize vectors already, you can forget about the magnitude part.
|
||||||
|
|
||||||
// Get the dot product of the vectors
|
// Get the dot product of the vectors
|
||||||
fixed_t dotProduct = M_DotVec3(Vector1, Vector2);
|
fixed_t dotProduct = M_DotVec3(Vector1, Vector2);
|
||||||
|
|
||||||
// Get the product of both of the vectors magnitudes
|
// Get the product of both of the vectors magnitudes
|
||||||
fixed_t vectorsMagnitude = FixedMul(FV_Magnitude(Vector1), FV_Magnitude(Vector2));
|
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 the arc cosine of the (dotProduct / vectorsMagnitude) which is the angle in RADIANS.
|
||||||
return FixedAcos(FixedDiv(dotProduct, vectorsMagnitude));
|
return FixedAcos(FixedDiv(dotProduct, vectorsMagnitude));
|
||||||
}
|
}
|
||||||
|
|
||||||
float FV_AngleBetweenVectorsf(const v3float_t *Vector1, const v3float_t *Vector2)
|
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
|
// 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).
|
// 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))
|
// 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 || )
|
// 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.
|
// 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.
|
// But basically, if you have normalize vectors already, you can forget about the magnitude part.
|
||||||
|
|
||||||
// Get the dot product of the vectors
|
// Get the dot product of the vectors
|
||||||
float dotProduct = M_DotVec3f(Vector1, Vector2);
|
float dotProduct = M_DotVec3f(Vector1, Vector2);
|
||||||
|
|
||||||
// Get the product of both of the vectors magnitudes
|
// Get the product of both of the vectors magnitudes
|
||||||
float vectorsMagnitude = FV_Magnitudef(Vector1)*FV_Magnitudef(Vector2);
|
float vectorsMagnitude = FV_Magnitudef(Vector1)*FV_Magnitudef(Vector2);
|
||||||
|
|
||||||
// Return the arc cosine of the (dotProduct / vectorsMagnitude) which is the angle in RADIANS.
|
// Return the arc cosine of the (dotProduct / vectorsMagnitude) which is the angle in RADIANS.
|
||||||
return acos(dotProduct/vectorsMagnitude);
|
return acos(dotProduct/vectorsMagnitude);
|
||||||
}
|
}
|
||||||
|
@ -370,7 +368,7 @@ float M_VectorPitch(v3float_t v)
|
||||||
|
|
||||||
#include "z_zone.h"
|
#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)
|
angles3d_t *M_VectorAlignTo(float Pitch, float Yaw, float Roll, v3float_t v, byte AngleAxis, float Rate)
|
||||||
{
|
{
|
||||||
CONS_Printf("P %f\n", Pitch);
|
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 DestYaw = (atan2(v.z,v.x)* 180 / M_PI);
|
||||||
float DestRoll = (atan2(v.y,v.x)* 180 / M_PI);
|
float DestRoll = (atan2(v.y,v.x)* 180 / M_PI);
|
||||||
|
|
||||||
Yaw = Yaw+(DestYaw-Yaw)*Rate;
|
Yaw = Yaw+(DestYaw-Yaw)*Rate;
|
||||||
Roll = Roll+(DestRoll-Roll)*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 DestPitch = (atan2(v.z,v.y)* 180 / M_PI);
|
||||||
float DestRoll = (-atan2(v.x,v.y)* 180 / M_PI);
|
float DestRoll = (-atan2(v.x,v.y)* 180 / M_PI);
|
||||||
|
|
||||||
Pitch = Pitch+(DestPitch-Pitch)*Rate;
|
Pitch = Pitch+(DestPitch-Pitch)*Rate;
|
||||||
Roll = Roll+(DestRoll-Roll)*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 DestPitch = (-atan2(v.y,v.z)* 180 / M_PI);
|
||||||
float DestYaw = (-atan2(v.x,v.z)* 180 / M_PI);
|
float DestYaw = (-atan2(v.x,v.z)* 180 / M_PI);
|
||||||
|
|
||||||
Pitch = Pitch+(DestPitch-Pitch)*Rate;
|
Pitch = Pitch+(DestPitch-Pitch)*Rate;
|
||||||
Yaw = Yaw+(DestYaw-Yaw)*Rate;
|
Yaw = Yaw+(DestYaw-Yaw)*Rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
angles3d_t *returnangles = Z_Malloc(sizeof(angles3d_t), PU_LEVEL, NULL);
|
angles3d_t *returnangles = Z_Malloc(sizeof(angles3d_t), PU_LEVEL, NULL);
|
||||||
memset(returnangles, 0, sizeof(*returnangles));
|
memset(returnangles, 0, sizeof(*returnangles));
|
||||||
returnangles->yaw = Yaw;
|
returnangles->yaw = Yaw;
|
||||||
returnangles->pitch = Pitch;
|
returnangles->pitch = Pitch;
|
||||||
returnangles->roll = Roll;
|
returnangles->roll = Roll;
|
||||||
|
|
||||||
return returnangles;
|
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)
|
boolean FV_Equal(const v3fixed_t *a_1, const v3fixed_t *a_2)
|
||||||
{
|
{
|
||||||
fixed_t Epsilon = FRACUNIT/FRACUNIT;
|
fixed_t Epsilon = FRACUNIT/FRACUNIT;
|
||||||
|
|
||||||
if ((abs(a_2->x - a_1->x) > Epsilon) ||
|
if ((abs(a_2->x - a_1->x) > Epsilon) ||
|
||||||
(abs(a_2->y - a_1->y) > Epsilon) ||
|
(abs(a_2->y - a_1->y) > Epsilon) ||
|
||||||
(abs(a_2->z - a_1->z) > Epsilon))
|
(abs(a_2->z - a_1->z) > Epsilon))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean FV_Equalf(const v3float_t *a_1, const v3float_t *a_2)
|
boolean FV_Equalf(const v3float_t *a_1, const v3float_t *a_2)
|
||||||
{
|
{
|
||||||
float Epsilon = 1.0f/1.0f;
|
float Epsilon = 1.0f/1.0f;
|
||||||
|
|
||||||
if ((abs(a_2->x - a_1->x) > Epsilon) ||
|
if ((abs(a_2->x - a_1->x) > Epsilon) ||
|
||||||
(abs(a_2->y - a_1->y) > Epsilon) ||
|
(abs(a_2->y - a_1->y) > Epsilon) ||
|
||||||
(abs(a_2->z - a_1->z) > Epsilon))
|
(abs(a_2->z - a_1->z) > Epsilon))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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_1;
|
||||||
v3fixed_t a_2;
|
v3fixed_t a_2;
|
||||||
|
|
||||||
FV_Point2Vec(&a_triangle[2], &a_triangle[0], &a_1);
|
FV_Point2Vec(&a_triangle[2], &a_triangle[0], &a_1);
|
||||||
FV_Point2Vec(&a_triangle[1], &a_triangle[0], &a_2);
|
FV_Point2Vec(&a_triangle[1], &a_triangle[0], &a_2);
|
||||||
|
|
||||||
FV_Cross(&a_1, &a_2, a_normal);
|
FV_Cross(&a_1, &a_2, a_normal);
|
||||||
|
|
||||||
FV_NormalizeO(a_normal, 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
|
// PlaneDistance
|
||||||
//
|
//
|
||||||
// Calculates distance between a plane and the origin.
|
// Calculates distance between a plane and the origin.
|
||||||
//
|
//
|
||||||
fixed_t FV_PlaneDistance(const v3fixed_t *a_normal, const v3fixed_t *a_point)
|
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));
|
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)
|
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;
|
fixed_t distance1 = 0, distance2 = 0;
|
||||||
|
|
||||||
FV_Normal(a_triangle, a_normal);
|
FV_Normal(a_triangle, a_normal);
|
||||||
|
|
||||||
*originDistance = FV_PlaneDistance(a_normal, &a_triangle[0]);
|
*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)
|
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;
|
+ 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)
|
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;
|
+ FixedMul(a_normal->z, a_line[1].z)) + *originDistance;
|
||||||
|
|
||||||
// Positive or zero number means no intersection
|
// Positive or zero number means no intersection
|
||||||
if (FixedMul(distance1, distance2) >= 0)
|
if (FixedMul(distance1, distance2) >= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,7 +520,7 @@ fixed_t FV_PlaneIntersection(const v3fixed_t *pOrigin, const v3fixed_t *pNormal,
|
||||||
// IntersectRaySphere
|
// IntersectRaySphere
|
||||||
// Input : rO - origin of ray in world space
|
// Input : rO - origin of ray in world space
|
||||||
// rV - vector describing direction 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
|
// sR - radius of sphere
|
||||||
// Notes : Normalized directional vectors expected
|
// Notes : Normalized directional vectors expected
|
||||||
// Return: distance to sphere in world units, -1 if no intersection.
|
// 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;
|
v3fixed_t Q;
|
||||||
fixed_t c, v, d;
|
fixed_t c, v, d;
|
||||||
FV_SubO(sO, rO, &Q);
|
FV_SubO(sO, rO, &Q);
|
||||||
|
|
||||||
c = FV_Magnitude(&Q);
|
c = FV_Magnitude(&Q);
|
||||||
v = FV_Dot(&Q, rV);
|
v = FV_Dot(&Q, rV);
|
||||||
d = FixedMul(sR, sR) - (FixedMul(c,c) - FixedMul(v,v));
|
d = FixedMul(sR, sR) - (FixedMul(c,c) - FixedMul(v,v));
|
||||||
|
|
||||||
// If there was no intersection, return -1
|
// If there was no intersection, return -1
|
||||||
if (d < 0*FRACUNIT)
|
if (d < 0*FRACUNIT)
|
||||||
return (-1*FRACUNIT);
|
return (-1*FRACUNIT);
|
||||||
|
|
||||||
// Return the distance to the [first] intersecting point
|
// Return the distance to the [first] intersecting point
|
||||||
return (v - FixedSqrt(d));
|
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
|
v3fixed_t vLineDir; // Variables to hold the point and the line's direction
|
||||||
fixed_t Numerator = 0, Denominator = 0, dist = 0;
|
fixed_t Numerator = 0, Denominator = 0, dist = 0;
|
||||||
|
|
||||||
// Here comes the confusing part. We need to find the 3D point that is actually
|
// 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:
|
// 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
|
// 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_Point2Vec(&vLine[1], &vLine[0], &vLineDir); // Get the Vector of the line
|
||||||
FV_NormalizeO(&vLineDir, &vLineDir); // Normalize the lines vector
|
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.
|
// 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
|
// 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.
|
// 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
|
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->y, vLine[0].y) +
|
||||||
FixedMul(vNormal->z, vLine[0].z) + distance);
|
FixedMul(vNormal->z, vLine[0].z) + distance);
|
||||||
|
|
||||||
// 3) If we take the dot product between our line vector and the normal of the polygon,
|
// 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).
|
// 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.
|
// 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
|
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
|
// 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
|
// 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.
|
// In this case, we should just return any point on the line.
|
||||||
|
|
||||||
if( Denominator == 0*FRACUNIT) // Check so we don't divide by zero
|
if( Denominator == 0*FRACUNIT) // Check so we don't divide by zero
|
||||||
{
|
{
|
||||||
ReturnVec->x = vLine[0].x;
|
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;
|
ReturnVec->z = vLine[0].z;
|
||||||
return ReturnVec; // Return an arbitrary point on the line
|
return ReturnVec; // Return an arbitrary point on the line
|
||||||
}
|
}
|
||||||
|
|
||||||
// We divide the (distance from the point to the plane) by (the dot product)
|
// 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 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
|
// 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
|
// 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
|
// 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?
|
// 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
|
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.
|
// 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
|
// This essentially moves the point along the vector to a certain distance. This now gives
|
||||||
// us the intersection point. Yay!
|
// us the intersection point. Yay!
|
||||||
|
|
||||||
// Return the intersection point
|
// Return the intersection point
|
||||||
ReturnVec->x = vLine[0].x + FixedMul(vLineDir.x, dist);
|
ReturnVec->x = vLine[0].x + FixedMul(vLineDir.x, dist);
|
||||||
ReturnVec->y = vLine[0].y + FixedMul(vLineDir.y, 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)
|
boolean FV_PointInsideBox(const v3fixed_t *point, const v3fixed_t *box)
|
||||||
{
|
{
|
||||||
v3fixed_t lastLine[2];
|
v3fixed_t lastLine[2];
|
||||||
|
|
||||||
FV_Load(&lastLine[0], box[3].x, box[3].y, box[3].z);
|
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);
|
FV_Load(&lastLine[1], box[0].x, box[0].y, box[0].z);
|
||||||
|
|
||||||
if (FV_PointOnLineSide(point, &box[0])
|
if (FV_PointOnLineSide(point, &box[0])
|
||||||
|| FV_PointOnLineSide(point, &box[1])
|
|| FV_PointOnLineSide(point, &box[1])
|
||||||
|| FV_PointOnLineSide(point, &box[2])
|
|| FV_PointOnLineSide(point, &box[2])
|
||||||
|| FV_PointOnLineSide(point, lastLine))
|
|| FV_PointOnLineSide(point, lastLine))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -660,7 +658,7 @@ void FM_LoadIdentity(fmatrix_t* matrix)
|
||||||
{
|
{
|
||||||
#define M(row,col) matrix->m[col * 4 + row]
|
#define M(row,col) matrix->m[col * 4 + row]
|
||||||
memset(matrix, 0x00, sizeof(fmatrix_t));
|
memset(matrix, 0x00, sizeof(fmatrix_t));
|
||||||
|
|
||||||
M(0, 0) = FRACUNIT;
|
M(0, 0) = FRACUNIT;
|
||||||
M(1, 1) = FRACUNIT;
|
M(1, 1) = FRACUNIT;
|
||||||
M(2, 2) = 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 upcross;
|
||||||
v3fixed_t upvec;
|
v3fixed_t upvec;
|
||||||
v3fixed_t basevec;
|
v3fixed_t basevec;
|
||||||
|
|
||||||
FV_Load(&upvec, upx, upy, upz);
|
FV_Load(&upvec, upx, upy, upz);
|
||||||
FV_Load(&basevec, anglex, angley, anglez);
|
FV_Load(&basevec, anglex, angley, anglez);
|
||||||
FV_Cross(&upvec, &basevec, &upcross);
|
FV_Cross(&upvec, &basevec, &upcross);
|
||||||
FV_Normalize(&upcross);
|
FV_Normalize(&upcross);
|
||||||
|
|
||||||
FM_LoadIdentity(matrix);
|
FM_LoadIdentity(matrix);
|
||||||
|
|
||||||
matrix->m[0] = upcross.x;
|
matrix->m[0] = upcross.x;
|
||||||
matrix->m[1] = upcross.y;
|
matrix->m[1] = upcross.y;
|
||||||
matrix->m[2] = upcross.z;
|
matrix->m[2] = upcross.z;
|
||||||
matrix->m[3] = 0*FRACUNIT;
|
matrix->m[3] = 0*FRACUNIT;
|
||||||
|
|
||||||
matrix->m[4] = upx;
|
matrix->m[4] = upx;
|
||||||
matrix->m[5] = upy;
|
matrix->m[5] = upy;
|
||||||
matrix->m[6] = upz;
|
matrix->m[6] = upz;
|
||||||
matrix->m[7] = 0;
|
matrix->m[7] = 0;
|
||||||
|
|
||||||
matrix->m[8] = anglex;
|
matrix->m[8] = anglex;
|
||||||
matrix->m[9] = angley;
|
matrix->m[9] = angley;
|
||||||
matrix->m[10] = anglez;
|
matrix->m[10] = anglez;
|
||||||
matrix->m[11] = 0;
|
matrix->m[11] = 0;
|
||||||
|
|
||||||
matrix->m[12] = x - FixedMul(upx,radius);
|
matrix->m[12] = x - FixedMul(upx,radius);
|
||||||
matrix->m[13] = y - FixedMul(upy,radius);
|
matrix->m[13] = y - FixedMul(upy,radius);
|
||||||
matrix->m[14] = z - FixedMul(upz,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->y,M(0, 1))
|
||||||
+ FixedMul(vec->z,M(0, 2))
|
+ FixedMul(vec->z,M(0, 2))
|
||||||
+ M(0, 3);
|
+ M(0, 3);
|
||||||
|
|
||||||
out->y = FixedMul(vec->x,M(1, 0))
|
out->y = FixedMul(vec->x,M(1, 0))
|
||||||
+ FixedMul(vec->y,M(1, 1))
|
+ FixedMul(vec->y,M(1, 1))
|
||||||
+ FixedMul(vec->z,M(1, 2))
|
+ FixedMul(vec->z,M(1, 2))
|
||||||
+ M(1, 3);
|
+ M(1, 3);
|
||||||
|
|
||||||
out->z = FixedMul(vec->x,M(2, 0))
|
out->z = FixedMul(vec->x,M(2, 0))
|
||||||
+ FixedMul(vec->y,M(2, 1))
|
+ FixedMul(vec->y,M(2, 1))
|
||||||
+ FixedMul(vec->z,M(2, 2))
|
+ 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 M(row,col) multme->m[col * 4 + row]
|
||||||
#define D(row,col) dest->m[col * 4 + row]
|
#define D(row,col) dest->m[col * 4 + row]
|
||||||
#define R(row,col) result.m[col * 4 + row]
|
#define R(row,col) result.m[col * 4 + row]
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < 4; j++)
|
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));
|
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));
|
M_Memcpy(dest, &result, sizeof(fmatrix_t));
|
||||||
|
|
||||||
#undef R
|
#undef R
|
||||||
#undef D
|
#undef D
|
||||||
#undef M
|
#undef M
|
||||||
|
@ -768,14 +766,14 @@ void FM_Translate(fmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
|
||||||
{
|
{
|
||||||
fmatrix_t trans;
|
fmatrix_t trans;
|
||||||
#define M(row,col) trans.m[col * 4 + row]
|
#define M(row,col) trans.m[col * 4 + row]
|
||||||
|
|
||||||
memset(&trans, 0x00, sizeof(fmatrix_t));
|
memset(&trans, 0x00, sizeof(fmatrix_t));
|
||||||
|
|
||||||
M(0, 0) = M(1, 1) = M(2, 2) = M(3, 3) = FRACUNIT;
|
M(0, 0) = M(1, 1) = M(2, 2) = M(3, 3) = FRACUNIT;
|
||||||
M(0, 3) = x;
|
M(0, 3) = x;
|
||||||
M(1, 3) = y;
|
M(1, 3) = y;
|
||||||
M(2, 3) = z;
|
M(2, 3) = z;
|
||||||
|
|
||||||
FM_MultMatrix(dest, &trans);
|
FM_MultMatrix(dest, &trans);
|
||||||
#undef M
|
#undef M
|
||||||
}
|
}
|
||||||
|
@ -789,14 +787,14 @@ void FM_Scale(fmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
|
||||||
{
|
{
|
||||||
fmatrix_t scale;
|
fmatrix_t scale;
|
||||||
#define M(row,col) scale.m[col * 4 + row]
|
#define M(row,col) scale.m[col * 4 + row]
|
||||||
|
|
||||||
memset(&scale, 0x00, sizeof(fmatrix_t));
|
memset(&scale, 0x00, sizeof(fmatrix_t));
|
||||||
|
|
||||||
M(3, 3) = FRACUNIT;
|
M(3, 3) = FRACUNIT;
|
||||||
M(0, 0) = x;
|
M(0, 0) = x;
|
||||||
M(1, 1) = y;
|
M(1, 1) = y;
|
||||||
M(2, 2) = z;
|
M(2, 2) = z;
|
||||||
|
|
||||||
FM_MultMatrix(dest, &scale);
|
FM_MultMatrix(dest, &scale);
|
||||||
#undef M
|
#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(p, &Line[0], &c);
|
||||||
FV_SubO(&Line[1], &Line[0], &V);
|
FV_SubO(&Line[1], &Line[0], &V);
|
||||||
FV_NormalizeO(&V, &V);
|
FV_NormalizeO(&V, &V);
|
||||||
|
|
||||||
d = FV_Distance(&Line[0], &Line[1]);
|
d = FV_Distance(&Line[0], &Line[1]);
|
||||||
t = FV_Dot(&V, &c);
|
t = FV_Dot(&V, &c);
|
||||||
|
|
||||||
// Check to see if ëtí is beyond the extents of the line segment
|
// Check to see if ëtí is beyond the extents of the line segment
|
||||||
if (t < 0)
|
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 FV_Copy(out, &Line[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the point between ëLine[0]í and ëLine[1]í
|
// Return the point between ëLine[0]í and ëLine[1]í
|
||||||
FV_Mul(&V, t);
|
FV_Mul(&V, t);
|
||||||
|
|
||||||
return FV_AddO(&Line[0], &V, out);
|
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;
|
fixed_t dist, closestdist;
|
||||||
v3fixed_t EdgePoints[3];
|
v3fixed_t EdgePoints[3];
|
||||||
v3fixed_t Line[2];
|
v3fixed_t Line[2];
|
||||||
|
|
||||||
FV_Copy(&Line[0], (v3fixed_t*)&tri[0]);
|
FV_Copy(&Line[0], (v3fixed_t*)&tri[0]);
|
||||||
FV_Copy(&Line[1], (v3fixed_t*)&tri[1]);
|
FV_Copy(&Line[1], (v3fixed_t*)&tri[1]);
|
||||||
FV_ClosestPointOnLine(Line, point, &EdgePoints[0]);
|
FV_ClosestPointOnLine(Line, point, &EdgePoints[0]);
|
||||||
|
|
||||||
FV_Copy(&Line[0], (v3fixed_t*)&tri[1]);
|
FV_Copy(&Line[0], (v3fixed_t*)&tri[1]);
|
||||||
FV_Copy(&Line[1], (v3fixed_t*)&tri[2]);
|
FV_Copy(&Line[1], (v3fixed_t*)&tri[2]);
|
||||||
FV_ClosestPointOnLine(Line, point, &EdgePoints[1]);
|
FV_ClosestPointOnLine(Line, point, &EdgePoints[1]);
|
||||||
|
|
||||||
FV_Copy(&Line[0], (v3fixed_t*)&tri[2]);
|
FV_Copy(&Line[0], (v3fixed_t*)&tri[2]);
|
||||||
FV_Copy(&Line[1], (v3fixed_t*)&tri[0]);
|
FV_Copy(&Line[1], (v3fixed_t*)&tri[0]);
|
||||||
FV_ClosestPointOnLine(Line, point, &EdgePoints[2]);
|
FV_ClosestPointOnLine(Line, point, &EdgePoints[2]);
|
||||||
|
|
||||||
// Find the closest one of the three
|
// Find the closest one of the three
|
||||||
FV_Copy(result, &EdgePoints[0]);
|
FV_Copy(result, &EdgePoints[0]);
|
||||||
closestdist = FV_Distance(point, &EdgePoints[0]);
|
closestdist = FV_Distance(point, &EdgePoints[0]);
|
||||||
for (i = 1; i < 3; i++)
|
for (i = 1; i < 3; i++)
|
||||||
{
|
{
|
||||||
dist = FV_Distance(point, &EdgePoints[i]);
|
dist = FV_Distance(point, &EdgePoints[i]);
|
||||||
|
|
||||||
if (dist < closestdist)
|
if (dist < closestdist)
|
||||||
{
|
{
|
||||||
closestdist = dist;
|
closestdist = dist;
|
||||||
FV_Copy(result, &EdgePoints[i]);
|
FV_Copy(result, &EdgePoints[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We now have the closest point! Whee!
|
// We now have the closest point! Whee!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -897,7 +895,7 @@ boolean FV_InsidePolygon(const fvector_t *vIntersection, const fvector_t *Poly,
|
||||||
int i;
|
int i;
|
||||||
UINT64 Angle = 0; // Initialize the angle
|
UINT64 Angle = 0; // Initialize the angle
|
||||||
fvector_t vA, vB; // Create temp vectors
|
fvector_t vA, vB; // Create temp vectors
|
||||||
|
|
||||||
// Just because we intersected the plane, doesn't mean we were anywhere near the polygon.
|
// 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 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.
|
// 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,
|
// 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
|
// 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.
|
// 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
|
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
|
FV_Point2Vec(&Poly[i], vIntersection, &vA); // Subtract the intersection point from the current vertex
|
||||||
// Subtract the point from the next vertex
|
// Subtract the point from the next vertex
|
||||||
FV_Point2Vec(&Poly[(i + 1) % vertexCount], vIntersection, &vB);
|
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
|
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.
|
// 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
|
// 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
|
// 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
|
// 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
|
// 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.
|
// 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)
|
if(Angle >= ANGLE_MAX) // If the angle is greater than 2 PI, (360 degrees)
|
||||||
return 1; // The point is inside of the polygon
|
return 1; // The point is inside of the polygon
|
||||||
|
|
||||||
return 0; // If you get here, it obviously wasn't inside 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;
|
fvector_t vNormal, vIntersection;
|
||||||
fixed_t originDistance = 0*FRACUNIT;
|
fixed_t originDistance = 0*FRACUNIT;
|
||||||
|
|
||||||
|
|
||||||
// First we check to see if our line intersected the plane. If this isn't true
|
// 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.
|
// 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
|
// We pass in address of vNormal and originDistance so we only calculate it once
|
||||||
|
|
||||||
if(!FV_IntersectedPlane(vPoly, vLine, &vNormal, &originDistance))
|
if(!FV_IntersectedPlane(vPoly, vLine, &vNormal, &originDistance))
|
||||||
return false;
|
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
|
// 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
|
// 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
|
// 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.
|
// give our function the normal of the plane, the points of the line, and the originDistance.
|
||||||
|
|
||||||
FV_IntersectionPoint(&vNormal, vLine, originDistance, &vIntersection);
|
FV_IntersectionPoint(&vNormal, vLine, originDistance, &vIntersection);
|
||||||
|
|
||||||
// Now that we have the intersection point, we need to test if it's inside the polygon.
|
// Now that we have the intersection point, we need to test if it's inside the polygon.
|
||||||
// To do this, we pass in :
|
// To do this, we pass in :
|
||||||
// (our intersection point, the polygon, and the number of vertices our polygon has)
|
// (our intersection point, the polygon, and the number of vertices our polygon has)
|
||||||
|
|
||||||
if(FV_InsidePolygon(&vIntersection, vPoly, vertexCount))
|
if(FV_InsidePolygon(&vIntersection, vPoly, vertexCount))
|
||||||
{
|
{
|
||||||
if (collisionPoint != NULL) // Optional - load the collision point.
|
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!
|
return true; // We collided!
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here, we must have NOT collided
|
// If we get here, we must have NOT collided
|
||||||
return false;
|
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 ex = FixedMul(vz-wy, sa);
|
||||||
fixed_t ey = FixedMul(wx-uz, sa);
|
fixed_t ey = FixedMul(wx-uz, sa);
|
||||||
fixed_t ez = FixedMul(uy-vx, sa);
|
fixed_t ez = FixedMul(uy-vx, sa);
|
||||||
|
|
||||||
rotVec->x = ax+dx+ex;
|
rotVec->x = ax+dx+ex;
|
||||||
rotVec->y = ay+dy+ey;
|
rotVec->y = ay+dy+ey;
|
||||||
rotVec->z = az+dz+ez;
|
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 xSq, ySq, zSq;
|
||||||
fixed_t sx, sy, sz;
|
fixed_t sx, sy, sz;
|
||||||
fixed_t sxy, sxz, syz;
|
fixed_t sxy, sxz, syz;
|
||||||
|
|
||||||
FV_Normalize(&nrm);
|
FV_Normalize(&nrm);
|
||||||
|
|
||||||
x = nrm.x;
|
x = nrm.x;
|
||||||
y = nrm.y;
|
y = nrm.y;
|
||||||
z = nrm.z;
|
z = nrm.z;
|
||||||
|
|
||||||
xSq = FixedMul(x, FixedMul(invCosA,x));
|
xSq = FixedMul(x, FixedMul(invCosA,x));
|
||||||
ySq = FixedMul(y, FixedMul(invCosA,y));
|
ySq = FixedMul(y, FixedMul(invCosA,y));
|
||||||
zSq = FixedMul(z, FixedMul(invCosA,z));
|
zSq = FixedMul(z, FixedMul(invCosA,z));
|
||||||
|
|
||||||
sx = FixedMul(sinA, x);
|
sx = FixedMul(sinA, x);
|
||||||
sy = FixedMul(sinA, y);
|
sy = FixedMul(sinA, y);
|
||||||
sz = FixedMul(sinA, z);
|
sz = FixedMul(sinA, z);
|
||||||
|
|
||||||
sxy = FixedMul(x, FixedMul(invCosA,y));
|
sxy = FixedMul(x, FixedMul(invCosA,y));
|
||||||
sxz = FixedMul(x, FixedMul(invCosA,z));
|
sxz = FixedMul(x, FixedMul(invCosA,z));
|
||||||
syz = FixedMul(y, FixedMul(invCosA,z));
|
syz = FixedMul(y, FixedMul(invCosA,z));
|
||||||
|
|
||||||
|
|
||||||
M(0, 0) = xSq + cosA;
|
M(0, 0) = xSq + cosA;
|
||||||
M(1, 0) = sxy - sz;
|
M(1, 0) = sxy - sz;
|
||||||
M(2, 0) = sxz + sy;
|
M(2, 0) = sxz + sy;
|
||||||
M(3, 0) = 0;
|
M(3, 0) = 0;
|
||||||
|
|
||||||
M(0, 1) = sxy + sz;
|
M(0, 1) = sxy + sz;
|
||||||
M(1, 1) = ySq + cosA;
|
M(1, 1) = ySq + cosA;
|
||||||
M(2, 1) = syz - sx;
|
M(2, 1) = syz - sx;
|
||||||
M(3, 1) = 0;
|
M(3, 1) = 0;
|
||||||
|
|
||||||
M(0, 2) = sxz - sy;
|
M(0, 2) = sxz - sy;
|
||||||
M(1, 2) = syz + sx;
|
M(1, 2) = syz + sx;
|
||||||
M(2, 2) = zSq + cosA;
|
M(2, 2) = zSq + cosA;
|
||||||
M(3, 2) = 0;
|
M(3, 2) = 0;
|
||||||
|
|
||||||
M(0, 3) = 0;
|
M(0, 3) = 0;
|
||||||
M(1, 3) = 0;
|
M(1, 3) = 0;
|
||||||
M(2, 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_1;
|
||||||
v3fixed_t a_2;
|
v3fixed_t a_2;
|
||||||
|
|
||||||
M_MakeVec3(&a_triangle[2], &a_triangle[0], &a_1);
|
M_MakeVec3(&a_triangle[2], &a_triangle[0], &a_1);
|
||||||
M_MakeVec3(&a_triangle[1], &a_triangle[0], &a_2);
|
M_MakeVec3(&a_triangle[1], &a_triangle[0], &a_2);
|
||||||
|
|
||||||
M_CrossProduct3(&a_1, &a_2, a_normal);
|
M_CrossProduct3(&a_1, &a_2, a_normal);
|
||||||
|
|
||||||
FV_NormalizeO(a_normal, 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_1;
|
||||||
v3float_t a_2;
|
v3float_t a_2;
|
||||||
|
|
||||||
M_MakeVec3f(&a_triangle[2], &a_triangle[0], &a_1);
|
M_MakeVec3f(&a_triangle[2], &a_triangle[0], &a_1);
|
||||||
M_MakeVec3f(&a_triangle[1], &a_triangle[0], &a_2);
|
M_MakeVec3f(&a_triangle[1], &a_triangle[0], &a_2);
|
||||||
|
|
||||||
M_CrossProduct3f(&a_1, &a_2, a_normal);
|
M_CrossProduct3f(&a_1, &a_2, a_normal);
|
||||||
|
|
||||||
FV_NormalizeOf(a_normal, a_normal);
|
FV_NormalizeOf(a_normal, a_normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
285
src/p_slopes.c
285
src/p_slopes.c
|
@ -359,7 +359,7 @@ void P_SpawnSlope_Line(int linenum)
|
||||||
srcplane->a = FLOAT_TO_FIXED (fslope->normalf.x); // cross[0]
|
srcplane->a = FLOAT_TO_FIXED (fslope->normalf.x); // cross[0]
|
||||||
srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1]
|
srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1]
|
||||||
srcplane->c = FLOAT_TO_FIXED (fslope->normalf.z); // cross[2]
|
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
|
// destheight takes the destination height used in dz
|
||||||
srcplane->d = -TMulScale16 (srcplane->a, line->v1->x, // x
|
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->b = FLOAT_TO_FIXED (cslope->normalf.y); // cross[1]
|
||||||
srcplane->c = FLOAT_TO_FIXED (cslope->normalf.z); // cross[2]
|
srcplane->c = FLOAT_TO_FIXED (cslope->normalf.z); // cross[2]
|
||||||
//plane->ic = FLOAT_TO_FIXED (1.f/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
|
#ifdef SLOPETHINGS // For setting thing-based slopes
|
||||||
srcplane->d = -TMulScale16 (plane->a, x,
|
srcplane->d = -TMulScale16 (plane->a, x,
|
||||||
plane->b, y,
|
plane->b, y,
|
||||||
|
@ -523,7 +523,7 @@ void P_SpawnSlope_Line(int linenum)
|
||||||
srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1]
|
srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1]
|
||||||
srcplane->c = FLOAT_TO_FIXED (fslope->normalf.z); // cross[2]
|
srcplane->c = FLOAT_TO_FIXED (fslope->normalf.z); // cross[2]
|
||||||
//plane->ic = FLOAT_TO_FIXED (1.f/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
|
#ifdef SLOPETHINGS // For setting thing-based slopes
|
||||||
srcplane->d = -TMulScale16 (plane->a, x,
|
srcplane->d = -TMulScale16 (plane->a, x,
|
||||||
plane->b, y,
|
plane->b, y,
|
||||||
|
@ -585,7 +585,7 @@ void P_SpawnSlope_Line(int linenum)
|
||||||
srcplane->b = FLOAT_TO_FIXED (cslope->normalf.y); // cross[1]
|
srcplane->b = FLOAT_TO_FIXED (cslope->normalf.y); // cross[1]
|
||||||
srcplane->c = FLOAT_TO_FIXED (cslope->normalf.z); // cross[2]
|
srcplane->c = FLOAT_TO_FIXED (cslope->normalf.z); // cross[2]
|
||||||
//plane->ic = FLOAT_TO_FIXED (1.f/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
|
#ifdef SLOPETHINGS // For setting thing-based slopes
|
||||||
srcplane->d = -TMulScale16 (plane->a, x,
|
srcplane->d = -TMulScale16 (plane->a, x,
|
||||||
plane->b, y,
|
plane->b, y,
|
||||||
|
@ -638,13 +638,6 @@ void P_CopySectorSlope(line_t *line)
|
||||||
|
|
||||||
#include "byteptr.h"
|
#include "byteptr.h"
|
||||||
|
|
||||||
/*
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
fixed_t z1;
|
|
||||||
fixed_t z2;
|
|
||||||
} mapvert_t;*/
|
|
||||||
|
|
||||||
#include "p_setup.h"
|
#include "p_setup.h"
|
||||||
#include "p_local.h"
|
#include "p_local.h"
|
||||||
|
|
||||||
|
@ -861,7 +854,7 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
|
||||||
srcplane->a = FLOAT_TO_FIXED (ret->normalf.x);
|
srcplane->a = FLOAT_TO_FIXED (ret->normalf.x);
|
||||||
srcplane->b = FLOAT_TO_FIXED (ret->normalf.y);
|
srcplane->b = FLOAT_TO_FIXED (ret->normalf.y);
|
||||||
srcplane->c = FLOAT_TO_FIXED (ret->normalf.z);
|
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->d = -TMulScale16 (srcplane->a, vertexes[vi3].x,
|
||||||
srcplane->b, vertexes[vi3].y,
|
srcplane->b, vertexes[vi3].y,
|
||||||
srcplane->c, z3);
|
srcplane->c, z3);
|
||||||
|
@ -891,279 +884,11 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
|
||||||
}
|
}
|
||||||
Z_Free(datastart);
|
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue