转发链接
常用MakeRotFrom...
在这里想说一下关系Make Rot From 系列函数的用法。
UCLASS(meta=(BlueprintThreadSafe, ScriptName = "MathLibrary"))
class ENGINE_API UKismetMathLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
/** Builds a rotator given only a XAxis. Y and Z are unspecified but will be orthonormal. XAxis need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromX(const FVector& X);
/** Builds a rotation matrix given only a YAxis. X and Z are unspecified but will be orthonormal. YAxis need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromY(const FVector& Y);
/** Builds a rotation matrix given only a ZAxis. X and Y are unspecified but will be orthonormal. ZAxis need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromZ(const FVector& Z);
/** Builds a matrix with given X and Y axes. X will remain fixed, Y may be changed minimally to enforce orthogonality. Z will be computed. Inputs need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromXY(const FVector& X, const FVector& Y);
/** Builds a matrix with given X and Z axes. X will remain fixed, Z may be changed minimally to enforce orthogonality. Y will be computed. Inputs need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromXZ(const FVector& X, const FVector& Z);
/** Builds a matrix with given Y and X axes. Y will remain fixed, X may be changed minimally to enforce orthogonality. Z will be computed. Inputs need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromYX(const FVector& Y, const FVector& X);
/** Builds a matrix with given Y and Z axes. Y will remain fixed, Z may be changed minimally to enforce orthogonality. X will be computed. Inputs need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromYZ(const FVector& Y, const FVector& Z);
/** Builds a matrix with given Z and X axes. Z will remain fixed, X may be changed minimally to enforce orthogonality. Y will be computed. Inputs need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromZX(const FVector& Z, const FVector& X);
/** Builds a matrix with given Z and Y axes. Z will remain fixed, Y may be changed minimally to enforce orthogonality. X will be computed. Inputs need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromZY(const FVector& Z, const FVector& Y);
// Build a reference frame from three axes
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate"))
static FRotator MakeRotationFromAxes(FVector Forward, FVector Right, FVector Up);
/** Find a rotation for an object at Start location to point at Target location. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="rotation rotate"))
static FRotator FindLookAtRotation(const FVector& Start, const FVector& Target);
}
作用:这些函数通常用来制作一些特殊的旋转效果。比如模型的X轴朝向某个固定的目标,同时又必须让Y朝向某个目标,可以定制化旋转。
方框内这些函数的功能大同小异,均可由箭头所指的最后一个函数演化而来。
设定
要移动的模型设为O;
红色模型设为R;
绿色模型设为G;
Make Rot from X
这里使用 Make Rot from X和Make Rot from XY两个函数做演示。其他的可以以此类推
通过给定的X轴,构建一个rotator,Y和Z不需要指定(其实引擎会指定一个隐式的Z轴(0,0,1),用来保证XYZ三个轴向的平面正交)。
无论怎么移动R模型,O模型始终指向R; 其实Find Look at Rotation 内部也是这样实现的
这种旋转一般来说没什么问题,能够模型始终朝向角色,但是有一个缺陷就是,无法调整模型Y轴的朝向(也可以看做X轴的旋转)。
有可能造成两种结果,一种是Z轴朝上,还有一种是Z轴朝下。
想要精准旋转量,就需要用到下面的函数,make rot from xy
Make Rot from XY
如果想要X轴指向某一个目标,Y轴也指向某个地方(会有偏差,因为X轴朝向是固定的),就需要用到Make Rot from XY
函数实现原理:
OR cross OG=>z轴
z轴 cross OR=>y轴
所以,此函数是保证X轴朝向不变的情况下,计算Z轴,修正Y轴,以达到使Y朝向指定方向的目的。
Y朝向的方向为:OR cross y轴
Make Rotation from Axes
其实Make Rot from x 等同于下面的操作。