UE5 宏翻译

1 篇文章 0 订阅
  • UE5 精度提高后,以前项目迁移,处理一下double->float 问题;
  • 结构对应;
  • 接口对应;

目录

参考文件

宏定义

宏应用

解析示例

UE4<->UE5

UE4<->DX       


参考文件

Engine\Source\Runtime\Core\Public\CoreFwd.h

Engine\Source\Runtime\Core\Public\Misc\LargeWorldCoordinates.h

Engine\Source\Runtime\Core\Public\Math\*

Engine\Source\Runtime\Core\Public\Math\TransformVectorized.h

Engine\Source\Runtime\Core\Public\Math\Rotator.h

Engine\Source\Runtime\Core\Public\Math\Plane.h

宏定义

// Args - TYPE, DIMENSION, [UE_TYPENAME], [COMPONENT_TYPE]. e.g. Vector, 3, FVector, double		// LWC_TODO: Remove COMPONENT_TYPE
#define UE_DECLARE_LWC_TYPE(...)								FORCE_EXPAND(UE_DECLARE_LWC_TYPE_SELECT(__VA_ARGS__)(__VA_ARGS__))

// Necessary to convince the MSVC preprocessor to play ball with variadic args - https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly
#define FORCE_EXPAND(X) X

#define UE_DECLARE_LWC_TYPE_SELECT(...)							FORCE_EXPAND(UE_LWC_MACRO_SELECT(__VA_ARGS__, UE_DECLARE_LWC_TYPE_EX, UE_DECLARE_LWC_TYPE_3, UE_DECLARE_LWC_TYPE_2, UE_DECLARE_LWC_TYPE_1 ))

#define UE_LWC_MACRO_SELECT(PAD1, PAD2, PAD3, PAD4, MACRO, ...)	MACRO

#define UE_DECLARE_LWC_TYPE_2(TYPE, DIM)						UE_DECLARE_LWC_TYPE_3(TYPE, DIM, F##TYPE)

#define UE_DECLARE_LWC_TYPE_3(TYPE, DIM, UE_TYPENAME)			UE_DECLARE_LWC_TYPE_EX(TYPE, DIM, UE_TYPENAME, double)

// Forward declaration of LWC supported core types
#define UE_DECLARE_LWC_TYPE_EX(TYPE, CC, DEFAULT_TYPENAME, COMPONENT_TYPE)				\
namespace UE { namespace Math { template<typename T> struct T##TYPE; } }				\
typedef UE::Math::T##TYPE<float> F##TYPE##CC##f;					/* FVector3f */		\
typedef UE::Math::T##TYPE<double> F##TYPE##CC##d;					/* FVector3d */		\
typedef UE::Math::T##TYPE<COMPONENT_TYPE> DEFAULT_TYPENAME;			/* FVector */		\
namespace ispc { struct DEFAULT_TYPENAME; }							/* ISPC forward declaration */

宏应用

UE_DECLARE_LWC_TYPE(Matrix, 44);
UE_DECLARE_LWC_TYPE(Plane, 4);
UE_DECLARE_LWC_TYPE(Quat, 4);
UE_DECLARE_LWC_TYPE(Rotator, 3);
UE_DECLARE_LWC_TYPE(Transform, 3);
UE_DECLARE_LWC_TYPE(Vector2,, FVector2D);
UE_DECLARE_LWC_TYPE(Vector, 3);
UE_DECLARE_LWC_TYPE(Vector4);

解析示例

//解析UE_DECLARE_LWC_TYPE(Vector, 3);
FORCE_EXPAND(UE_DECLARE_LWC_TYPE_SELECT(Vector, 3)(Vector, 3))
UE_DECLARE_LWC_TYPE_SELECT(Vector, 3)(Vector, 3)
FORCE_EXPAND(UE_LWC_MACRO_SELECT(Vector, 3, UE_DECLARE_LWC_TYPE_EX,             UE_DECLARE_LWC_TYPE_3, UE_DECLARE_LWC_TYPE_2, UE_DECLARE_LWC_TYPE_1 ))(Vector, 3)
UE_LWC_MACRO_SELECT(Vector, 3, UE_DECLARE_LWC_TYPE_EX, UE_DECLARE_LWC_TYPE_3, UE_DECLARE_LWC_TYPE_2, UE_DECLARE_LWC_TYPE_1 )(Vector, 3)
UE_DECLARE_LWC_TYPE_2(Vector, 3)
UE_DECLARE_LWC_TYPE_3(Vector, 3, F##Vector)
UE_DECLARE_LWC_TYPE_EX(Vector, 3, FVector, double)

namespace UE 
{ 
	namespace Math 
	{ 
		template<typename T> struct TVector; 
	} 
}
typedef UE::Math::TVector<float> FVector3f;			/* FVector3f */		\
typedef UE::Math::TVector<double> FVector3d;		/* FVector3d */		\
typedef UE::Math::TVector<double> FVector;			/* FVector */		\
namespace ispc { struct FVector; }					/* ISPC forward declaration */

UE4<->UE5

#

UE4

UE5

1

FVector2D

UE::Math::TVector2<float>

或者

FVector2f

2

FVector

UE::Math::TVector<float>

或者

FVector3f

3

FTransform

UE::Math::TTransform<float>

或者

FTransform3f

4

FQuat

UE::Math::TQuat<float>

或者

FQuat4f

5

FVector4

UE::Math::TVector4<float>

或者

FVector4f

6

FMatrix

UE::Math::TMatrix<float>

或者

FMatrix44f

7

FRotator

FRotator3f

8

FLookAtMatrix

UE::Math::TLookAtMatrix<float>

9

FPlane

FPlane4f

10

FRotationMatrix

FRotationMatrix44f

11

FQuatRotationMatrix

FQuatRotationMatrix44f

UE4<->DX        

DX->UE4
#

DX

UE4

1

D3DXMatrixRotationAxis

FVector .RotateAngleAxis

vecTarget = BaseDir.RotateAngleAxis (AngleDeg, Axis.GetSafeNormal ());

绕轴旋转(假设Axis. Size() == 1)。

FQuat.RotateVector

//旋转后的向量

FVector vecTarget;

FQuat RotatorQuat = FQuat(Axis, fAngleRad);

vecTarget=RotatorQuat.RotateVector (vecSrc);

D3DXMatrixRotationX

FTransform RotX(FRotator(0.0f, 0.0f, -90.0f));//Pitch-X轴,转-90度

matRotX = RotX.ToMatrixNoScale();

待确定

D3DXMatrixRotationY

FMatrix RMatrix;

FTransform RotY(FRotator(90.0f, 0.0f, 0.0f));//Pitch-Y轴,转90度

RMatrix = RotY.ToMatrixNoScale();

待确定

D3DXVec3Cross

FVector::CrossProduct

叉乘

D3DXVec3Dot

D3DXVec2Dot

FVector::DotProduct

FVector2D::DotProduct

点乘

D3DXVec3Normalize

D3DXVec2Normalize

FVector.GetSafeNormal()

GetUnsafeNormal()

GetSafeNormal2D

GetUnsafeNormal2D()

规范化

KINDA_SMALL_NUMBER

D3DXVec3TransformNormal

FPlane TransformBy(const FMatrix& M) const;

TransformByUsingAdjointT

FQuat RotatorQuat = FQuat(任意旋转轴, 旋转的弧度);

retVec = RotatorQuat.RotateVector(基础方向);

任意轴旋转

FQuat RotatorQuat = FQuat(AxisZ, 0.1745329);

FMatrix RandomOrientation = FRotationMatrix::Make(RotatorQuat);

FVector Rvec1 = RandomOrientation.TransformPosition(vec);

D3DXVec3Length

FVector .Size()

长度

D3DXVec3LengthSq

FVector .SizeSquared()

长度平方

FVector .Size2D()

2D长度

FVector .SizeSquared2D()

2D长度平方

FVector .GetComponentForAxis

获取指定轴分量

IsNearlyZero/IsZero()

接近0 / ==0

IsUnit/IsNormalized()

接近1

ToDirectionAndLength(FVector &OutDir, float &OutLength)

转换为单位方向向量及其原长度。

FVector::PointsAreSame

两点相同

FVector::Dist/ Distance/ DistXY/ Dist2D

距离/2D距离

FVector::DistSquared/DistSquaredXY/DistSquared2D

距离^2

FVector::Parallel/ Coincident/ Orthogonal

两个法向量,平行/重合/垂直判断

FVector::Coplanar

共面判断(法线几乎平行,且这些平面包含相同的点集)

D3DXVECTOR4

FVector4

D3DXCOLOR

FLinearColor

D3DXVec3Lerp

FMath::Lerp

D3DXVec3TransformCoord

vec4 = matrix.TransformVector(vec);

vec41 = matrix.TransformPosition(vec);

||

vec5 = transf.TransformVector(vec);

vec51 = transf.TransformPosition(vec);

D3DXMatrixScaling

FMatrix ScaleMatrix(

FPlane(sx, 0.0f, 0.0f, 0.0f),

FPlane(0.0f, sy, 0.0f, 0.0f),

FPlane(0.0f, 0.0f, sz, 0.0f),

FPlane(0.0f, 0.0f, 0.0f, 1.0f)

);

||

FMatrix .ApplyScale

D3DXQUATERNION

FQuat

D3DXQuaternionSlerp

FQuat::SLerp

D3DXQuaternionNormalize

FQuat.GetNormalized()

D3DXQuaternionRotationYawPitchRoll (
_Inout_ D3DXQUATERNION *pOut,

  _In_    FLOAT          Yaw,

  _In_    FLOAT          Pitch,

  _In_    FLOAT          Roll

);

pOut = FQuat(Roll, Pitch, Yaw);

待确定============

D3DXQuaternionIdentity

FQuat::Identity

D3DXMATRIX

FMatrix

D3DXMatrixIdentity

FMatrix.SetIdentity();

D3DXMatrixMultiply

FMatrix.operator*

D3DXMatrixRotationQuaternion

FQuatRotationMatrix::Make

四元数,需标准化Normalize()

D3DXMatrixDecompose

将一般的三维变换矩阵分解成标量、旋转和平移分量。

FMatrix.GetScaleVector();

返回3D scale vector

FMatrix.ToQuat();

将旋转矩阵转换为四元数。warning rotation part will need to be unit length for this to be right!

FVector(m_Transform.M[3][0], m_Transform.M[3][1], m_Transform.M[3][2])

D3DXMatrixTranslation

FMatrix.ConcatTranslation ();

D3DXMatrixLookAtLH

FLookAtMatrix

D3DXMatrixOrthoLH

2/w  0    0           0

0    2/h  0           0

0    0    1/(zf-zn)   0

0    0    zn/(zn-zf)  1

FMatrix( FPlane(2.0f/(Right-Left), 0, 0,  0 ),

FPlane(0, 2.0f/(Top-Bottom), 0,  0 ),

FPlane(0, 0,     1/(ZNear-ZFar), 0 ),

FPlane(0, 0, ZNear/(ZNear-ZFar), 1 )

);

Note:Math

FMath

atan2f

FMath::Atan2()

acosf

FMath::Acos

tanf

FMath::Tan

fabsf

FMath::Abs()

问题

(1)"GenericDivide_FloatFloat": 不是 "UKismetMathLibrary" 的成员    

        处理:删除对 GeneratedCodeHelpers.h 文件的包含;

(2)byte

//S1.Windows引用前加
#ifdef _HAS_STD_BYTE
#undef _HAS_STD_BYTE
#endif
#define _HAS_STD_BYTE 0

//S2.除去对using namespace std;的使用;改为具体应用,如:
using std::string;
using std::stringstream;
using std::vector;
using std::map;
using std::make_pair;
using std::list;
using std::iterator;

(3)法线

	//法线
	T GetNormal()
	{
		T tNormal;
		ZeroMemory(&tNormal, sizeof(T));
		//float* pfDirection = (float*)&getDirection(), * pfNormal = (float*)&tNormal;
		double* pfDirection = (double*)&getDirection(), * pfNormal = (double*)&tNormal;
		int ubtSize = sizeof(T);
		//int ubtCount = ubtSize / sizeof(float);
		int ubtCount = ubtSize / sizeof(double);
		pfNormal[0] = -1.0f * pfDirection[ubtCount - 1];
		pfNormal[ubtCount - 1] = pfDirection[0];
		return *(T*)pfNormal;
	}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值