当前位置: 首页>>代码示例>>C++>>正文


C++ Vec3::CrossN方法代码示例

本文整理汇总了C++中Vec3::CrossN方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec3::CrossN方法的具体用法?C++ Vec3::CrossN怎么用?C++ Vec3::CrossN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vec3的用法示例。


在下文中一共展示了Vec3::CrossN方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _updateCamera

	void Shadow::_updateCamera()
	{
		Camera * worldCam = World::Instance()->MainCamera();

		mInverseWorldCameraVP = World::Instance()->MainCamera()->GetViewProjMatrix().Inverse();

		float nearClip = worldCam->GetNearClip();
		float farClip = mDist[K_NumShadowLayers - 1];

		Vec3 xAixs = worldCam->GetDirection();
		Vec3 yAixs = worldCam->GetUp();
		Vec3 zAixs = Environment::Instance()->GetEvParam()->LightDir;

		if (Math::Abs(zAixs.Dot(yAixs)) > 0.99f)
		{
			yAixs = zAixs.CrossN(xAixs);
			xAixs = yAixs.CrossN(zAixs);
		}
		else
		{
			xAixs = yAixs.CrossN(zAixs);
			yAixs = zAixs.CrossN(xAixs);
		}

		if (xAixs.Dot(worldCam->GetDirection()) < 0)
			xAixs = -xAixs;

		yAixs = zAixs.CrossN(xAixs);

		Mat4 matView;
		Quat qOrient = Quat::S_FromAxis(xAixs, yAixs, zAixs);

		matView.MakeViewLH(worldCam->GetPosition(), qOrient);

		Vec3 corner[8], t_corner[8];

		worldCam->GetWorldCorner(t_corner, nearClip, farClip);

		float dist = t_corner[4].Distance(t_corner[5]);

		for (int i = 0; i < 8; ++i)
		{
			corner[i] = t_corner[i] * matView;
		}

		Aabb aabb = Aabb::Invalid;

		for (int i = 0; i < 8; ++i)
		{
			aabb.minimum = aabb.minimum.Minimum(corner[i]);
			aabb.maximum = aabb.maximum.Maximum(corner[i]);
		}

		Vec3 center = aabb.GetCenter();
		float width = aabb.GetWidth();
		float height = aabb.GetHeight();
		float depth = aabb.GetDepth();

		center *= matView.Inverse();

		Vec3 lightPos = center - zAixs * mOffset;

		mLightCamera->SetPosition(lightPos);
		mLightCamera->SetOrientation(qOrient);
		mLightCamera->SetOrthoWidth(width);
		mLightCamera->SetOrthoHeight(height);
		mLightCamera->SetNearClip(nearClip);
		mLightCamera->SetFarClip(mOffset + depth);
		mLightCamera->SetProjectionType(PROJTYPE_ORTHO);
	}
开发者ID:ak4hige,项目名称:myway3d,代码行数:70,代码来源:MWShadow.cpp

示例2: _calcuCascadedMatrix

	void Shadow::_calcuCascadedMatrix(int layer)
	{
		Camera * worldCam = World::Instance()->MainCamera();

		mInverseWorldCameraVP = World::Instance()->MainCamera()->GetViewProjMatrix().Inverse();

		float nearClip, farClip = mDist[layer];

		if (layer == 0)
			nearClip = worldCam->GetNearClip();
		else
			nearClip = mDist[layer - 1];

		Vec3 xAixs = worldCam->GetDirection();
		Vec3 yAixs = worldCam->GetUp();
		Vec3 zAixs = Environment::Instance()->GetEvParam()->LightDir;

		if (Math::Abs(zAixs.Dot(yAixs)) > 0.99f)
		{
			yAixs = zAixs.CrossN(xAixs);
			xAixs = yAixs.CrossN(zAixs);
		}
		else
		{
			xAixs = yAixs.CrossN(zAixs);
			yAixs = zAixs.CrossN(xAixs);
		}

		if (xAixs.Dot(worldCam->GetDirection()) < 0)
			xAixs = -xAixs;

		yAixs = zAixs.CrossN(xAixs);

		Mat4 matView, matProj;
		Quat qOrient = Quat::S_FromAxis(xAixs, yAixs, zAixs);

		matView.MakeViewLH(worldCam->GetPosition(), qOrient);

		Vec3 corner[8], t_corner[8];

		worldCam->GetWorldCorner(t_corner, nearClip, farClip);

		float dist = t_corner[4].Distance(t_corner[5]);

		for (int i = 0; i < 8; ++i)
		{
			corner[i] = t_corner[i] * matView;
		}

		Aabb aabb = Aabb::Invalid;

		for (int i = 0; i < 8; ++i)
		{
			aabb.minimum = aabb.minimum.Minimum(corner[i]);
			aabb.maximum = aabb.maximum.Maximum(corner[i]);
		}

		Vec3 center = aabb.GetCenter();
		float width = aabb.GetWidth();
		float height = aabb.GetHeight();
		float depth = aabb.GetDepth();

		center *= matView.Inverse();

		Vec3 lightPos = center - zAixs * mOffset;

		matView.MakeViewLH(lightPos, qOrient);
		matProj.MakeOrthoLH(width, height, nearClip, mOffset + depth);

		mCascadedMatrix[layer].mView = matView;
		mCascadedMatrix[layer].mProj = matProj;
		mCascadedMatrix[layer].mViewProj = matView * matProj;
	}
开发者ID:ak4hige,项目名称:myway3d,代码行数:73,代码来源:MWShadow.cpp


注:本文中的Vec3::CrossN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。