mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-16 17:21:10 +00:00
- some angle cleanup
* clean out the angle conversion helpers from basics.h. * use degrees instead of radians in TMatrix3x3.
This commit is contained in:
parent
0c9b652583
commit
16cefb7528
5 changed files with 18 additions and 74 deletions
|
@ -68,7 +68,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DShape2DTransform, Clear, Shape2DTransform_Clear)
|
|||
|
||||
static void Shape2DTransform_Rotate(DShape2DTransform* self, double angle)
|
||||
{
|
||||
self->transform = DMatrix3x3::Rotate2D(DEG2RAD(angle)) * self->transform;
|
||||
self->transform = DMatrix3x3::Rotate2D(angle) * self->transform;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DShape2DTransform, Rotate, Shape2DTransform_Rotate)
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
**
|
||||
*/
|
||||
|
||||
#include "vectors.h" // RAD2DEG
|
||||
#include "vectors.h"
|
||||
#include "hw_cvars.h"
|
||||
#include "hw_vrmodes.h"
|
||||
#include "v_video.h"
|
||||
|
@ -67,6 +67,16 @@ static VRMode vrmi_righteye = { 1, 1.f, 1.f, 1.f,{ { .5f, 1.f },{ 0.f, 0.f } } }
|
|||
static VRMode vrmi_topbottom = { 2, 1.f, .5f, 1.f,{ { -.5f, 1.f },{ .5f, 1.f } } };
|
||||
static VRMode vrmi_checker = { 2, isqrt2, isqrt2, 1.f,{ { -.5f, 1.f },{ .5f, 1.f } } };
|
||||
|
||||
static float DEG2RAD(float deg)
|
||||
{
|
||||
return deg * float(M_PI / 180.0);
|
||||
}
|
||||
|
||||
static float RAD2DEG(float rad)
|
||||
{
|
||||
return rad * float(180. / M_PI);
|
||||
}
|
||||
|
||||
const VRMode *VRMode::GetVRMode(bool toscreen)
|
||||
{
|
||||
int mode = !toscreen || (sysCallbacks.DisableTextureFilter && sysCallbacks.DisableTextureFilter()) ? 0 : vr_mode;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
#include "xs_Float.h"
|
||||
|
||||
#define MAXWIDTH 12000
|
||||
#define MAXHEIGHT 5000
|
||||
|
@ -22,7 +21,6 @@ typedef int32_t fixed_t;
|
|||
// the last remnants of tables.h
|
||||
#define ANGLE_90 (0x40000000)
|
||||
#define ANGLE_180 (0x80000000)
|
||||
#define ANGLE_270 (0xc0000000)
|
||||
#define ANGLE_MAX (0xffffffff)
|
||||
|
||||
typedef uint32_t angle_t;
|
||||
|
@ -39,14 +37,6 @@ typedef uint32_t angle_t;
|
|||
#define FORCE_PACKED
|
||||
#endif
|
||||
|
||||
// Todo: get rid of this. Static file name buffers suck.
|
||||
#ifndef PATH_MAX
|
||||
#define BMAX_PATH 256
|
||||
#else
|
||||
#define BMAX_PATH PATH_MAX
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define GCCPRINTF(stri,firstargi) __attribute__((format(printf,stri,firstargi)))
|
||||
#define GCCFORMAT(stri) __attribute__((format(printf,stri,0)))
|
||||
|
@ -76,27 +66,6 @@ using BITFIELD = uint32_t;
|
|||
|
||||
const double M_PI = 3.14159265358979323846; // matches value in gcc v2 math.h
|
||||
|
||||
inline float DEG2RAD(float deg)
|
||||
{
|
||||
return deg * float(M_PI / 180.0);
|
||||
}
|
||||
|
||||
inline double DEG2RAD(double deg)
|
||||
{
|
||||
return deg * (M_PI / 180.0);
|
||||
}
|
||||
|
||||
inline float RAD2DEG(float rad)
|
||||
{
|
||||
return rad * float(180. / M_PI);
|
||||
}
|
||||
|
||||
inline double RAD2DEG(double rad)
|
||||
{
|
||||
return rad * (180. / M_PI);
|
||||
}
|
||||
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
using std::clamp;
|
||||
|
|
|
@ -1043,44 +1043,9 @@ struct TMatrix3x3
|
|||
|
||||
// Construct a rotation matrix about an arbitrary axis.
|
||||
// (The axis vector must be normalized.)
|
||||
TMatrix3x3(const Vector3 &axis, double radians)
|
||||
TMatrix3x3(const Vector3 &axis, double degrees)
|
||||
: TMatrix3x3(axis, g_sindeg(degrees), g_cosdeg(degrees))
|
||||
{
|
||||
double c = g_cos(radians), s = g_sin(radians), t = 1 - c;
|
||||
/* In comments: A more readable version of the matrix setup.
|
||||
This was found in Diana Gruber's article "The Mathematics of the
|
||||
3D Rotation Matrix" at <http://www.makegames.com/3drotation/> and is
|
||||
attributed to Graphics Gems (Glassner, Academic Press, 1990).
|
||||
|
||||
Cells[0][0] = t*axis.X*axis.X + c;
|
||||
Cells[0][1] = t*axis.X*axis.Y - s*axis.Z;
|
||||
Cells[0][2] = t*axis.X*axis.Z + s*axis.Y;
|
||||
|
||||
Cells[1][0] = t*axis.Y*axis.X + s*axis.Z;
|
||||
Cells[1][1] = t*axis.Y*axis.Y + c;
|
||||
Cells[1][2] = t*axis.Y*axis.Z - s*axis.X;
|
||||
|
||||
Cells[2][0] = t*axis.Z*axis.X - s*axis.Y;
|
||||
Cells[2][1] = t*axis.Z*axis.Y + s*axis.X;
|
||||
Cells[2][2] = t*axis.Z*axis.Z + c;
|
||||
|
||||
Outside comments: A faster version with only 10 (not 24) multiplies.
|
||||
*/
|
||||
double sx = s*axis.X, sy = s*axis.Y, sz = s*axis.Z;
|
||||
double tx, ty, txx, tyy, u, v;
|
||||
|
||||
tx = t*axis.X;
|
||||
Cells[0][0] = vec_t( (txx=tx*axis.X) + c );
|
||||
Cells[0][1] = vec_t( (u=tx*axis.Y) - sz);
|
||||
Cells[0][2] = vec_t( (v=tx*axis.Z) + sy);
|
||||
|
||||
ty = t*axis.Y;
|
||||
Cells[1][0] = vec_t( u + sz);
|
||||
Cells[1][1] = vec_t( (tyy=ty*axis.Y) + c );
|
||||
Cells[1][2] = vec_t( (u=ty*axis.Z) - sx);
|
||||
|
||||
Cells[2][0] = vec_t( v - sy);
|
||||
Cells[2][1] = vec_t( u + sx);
|
||||
Cells[2][2] = vec_t( (t-txx-tyy) + c );
|
||||
}
|
||||
|
||||
TMatrix3x3(const Vector3 &axis, double c/*cosine*/, double s/*sine*/)
|
||||
|
@ -1106,10 +1071,10 @@ Outside comments: A faster version with only 10 (not 24) multiplies.
|
|||
|
||||
TMatrix3x3(const Vector3 &axis, TAngle<vec_t> degrees);
|
||||
|
||||
static TMatrix3x3 Rotate2D(double radians)
|
||||
static TMatrix3x3 Rotate2D(double degrees)
|
||||
{
|
||||
double c = g_cos(radians);
|
||||
double s = g_sin(radians);
|
||||
double c = g_cosdeg(degrees);
|
||||
double s = g_sindeg(degrees);
|
||||
TMatrix3x3 ret;
|
||||
ret.Cells[0][0] = c; ret.Cells[0][1] = -s; ret.Cells[0][2] = 0;
|
||||
ret.Cells[1][0] = s; ret.Cells[1][1] = c; ret.Cells[1][2] = 0;
|
||||
|
|
|
@ -423,7 +423,7 @@ bool HWSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp)
|
|||
// which is nicer in VR
|
||||
float xrel = xcenter - vp->X;
|
||||
float yrel = ycenter - vp->Y;
|
||||
float absAngleDeg = RAD2DEG(atan2(-yrel, xrel));
|
||||
float absAngleDeg = atan2(-yrel, xrel) * (180 / M_PI);
|
||||
float counterRotationDeg = 270. - HWAngles.Yaw.Degrees(); // counteracts existing sprite rotation
|
||||
float relAngleDeg = counterRotationDeg + absAngleDeg;
|
||||
|
||||
|
|
Loading…
Reference in a new issue