redeyerabbit

博客园 首页 新随笔 联系 订阅 管理

一、平面的描述使用Ax+By+Cz=W的形式。因此在手动计算时要注意不要使用现成的结论:Ax+By+Cz+D=0的形式:

/**
 * Structure for three dimensional planes.
 *
 * Stores the coeffecients as Xx+Yy+Zz=W.
 * Note that this is different from many other Plane classes that use Xx+Yy+Zz+W=0.
 */
MS_ALIGN(16) struct FPlane
	: public FVector
{
public:

	/** The w-component. */
	float W;

二从观察点和朝向定义View矩阵

void FViewMatrices::UpdateViewMatrix(const FVector& ViewLocation, const FRotator& ViewRotation)
{
	ViewOrigin = ViewLocation;

	FMatrix ViewPlanesMatrix = FMatrix(
		FPlane(0, 0, 1, 0), //X平面
		FPlane(1, 0, 0, 0), //Y平面
		FPlane(0, 1, 0, 0), //Z平面
		FPlane(0, 0, 0, 1)); //W平面,这个其实就是单纯的满足矩阵的要求,表示是一个点。

	ViewMatrix = FTranslationMatrix(-ViewLocation);
	ViewMatrix = ViewMatrix * FInverseRotationMatrix(ViewRotation);
     //世界坐标到观察坐标的变换:V=World的逆变换 = (旋转矩阵*平移矩阵)的逆变换=平移的逆变换*旋转的逆变换
ViewMatrix = ViewMatrix * ViewPlanesMatrix; InvViewMatrix = FTranslationMatrix(-ViewMatrix.GetOrigin()) * ViewMatrix.RemoveTranslation().GetTransposed(); // Duplicate HMD rotation matrix with roll removed FRotator HMDViewRotation = ViewRotation; HMDViewRotation.Roll = 0.f; HMDViewMatrixNoRoll = FInverseRotationMatrix(HMDViewRotation) * ViewPlanesMatrix; PreViewTranslation = -ViewOrigin; //using mathematical equality rule for matrix inverse: (A*B)^-1 == B^-1 * A^-1 OverriddenTranslatedViewMatrix = TranslatedViewMatrix = FTranslationMatrix(-PreViewTranslation) * ViewMatrix; OverriddenInvTranslatedViewMatrix = InvTranslatedViewMatrix = InvViewMatrix * FTranslationMatrix(PreViewTranslation); // Compute a transform from view origin centered world-space to clip space. TranslatedViewProjectionMatrix = GetTranslatedViewMatrix() * GetProjectionMatrix(); InvTranslatedViewProjectionMatrix = GetInvProjectionMatrix() * GetInvTranslatedViewMatrix(); ViewProjectionMatrix = GetViewMatrix() * GetProjectionMatrix(); InvViewProjectionMatrix = GetInvProjectionMatrix() * GetInvViewMatrix(); }

  

posted on 2017-04-06 17:35  redeyerabbit  阅读(645)  评论(0编辑  收藏  举报