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


C++ Mat4::Inverse方法代码示例

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


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

示例1: GetViewportRay

	Ray Camera::GetViewportRay(float x, float y)
	{
		Ray result;

		x = Math::Clamp(x, 0.0f, 1.0f);
		y = Math::Clamp(y, 0.0f, 1.0f);

		Mat4 matInvViewProj = GetViewProjTM();
		matInvViewProj.Inverse();

		x = x * 2.0f - 1.0f;
		y = y * -2.0f + 1.0f;

		Float3 p1(x, y, 0.0f);
		Float3 p2(x, y, 0.5f);

		p1.Transform(matInvViewProj);
		p2.Transform(matInvViewProj);

		result.orig = p1;
		result.dir = p2 - p1;

		result.dir.Normalize();

		return result;
	}
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:26,代码来源:MCamera.cpp

示例2: GetWorldCorner

	void Camera::GetWorldCorner(Float3 * corner, float nearClip, float farClip)
	{
		Float3 nearPos = Float3(0, 0, nearClip);
		Float3 farPos = Float3(0, 0, farClip);

		nearPos *= GetProjTM();
		farPos *= GetProjTM();

		Float3 t_corner[8] = { 
			Float3(-1, 1, 0), Float3(1, 1, 0), Float3(-1, -1, 0), Float3(1, -1, 0), 
			Float3(-1, 1, 1), Float3(1, 1, 1), Float3(-1, -1, 1), Float3(1, -1, 1)
		};

		for (int i = 0; i < 4; ++i)
		{
			t_corner[i].z = nearPos.z;
			t_corner[i + 4].z = farPos.z;
		}

		Mat4 matInverseVP = GetViewProjTM();
		matInverseVP.Inverse();

		for (int i = 0; i < 8; ++i)
		{
			corner[i] = t_corner[i] * matInverseVP;
		}
	}
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:27,代码来源:MCamera.cpp

示例3: RenderSprite

void RenderSprite(float size, Vec3 *eyePos, Mat4 matModelView)
{
	if(size == 0)
		return;

	size /= 2;

	glPushMatrix();
    matModelView.Translate(*eyePos);
	matModelView = matModelView.Inverse();
	glMultMatrixf(matModelView.m);

	glDisable(GL_CULL_FACE);

	glBegin(GL_TRIANGLE_STRIP);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f( -size,  size, 0);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f( size,   size, 0);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f( -size, -size, 0);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3f( size,  -size, 0);
	glEnd();

	glEnable(GL_CULL_FACE);

	glPopMatrix();
}
开发者ID:pedroedrasousa,项目名称:opengl-stuff-cpp,代码行数:29,代码来源:Main.cpp

示例4: _updateTM

	void Camera::_updateTM()
	{
		if (mTmChangeFlags == 0)
			return ;

		Node::_updateTM();

		const Float3 & pos = GetWorldPosition();
		const Quat & ort = GetWorldRotation();

		mMatView.MakeViewLH(pos, ort);

		if (GetOrthoEnable())
		{
			mMatProj.MakeOrthoLH(mOrthoWidth, mOrthoHeight, mNear, mFar);
		}
		else
		{
			mMatProj.MakePerspectiveLH(mFovy, mAspect, mNear, mFar);
		}

		mMatViewProj = mMatView * mMatProj;

		mFrustum.FromMatrix(mMatViewProj);

		// update corner
		Float3 corner[8] = { 
			Float3(-1, 1, 0), Float3(1, 1, 0), Float3(-1, -1, 0), Float3(1, -1, 0), 
			Float3(-1, 1, 1), Float3(1, 1, 1), Float3(-1, -1, 1), Float3(1, -1, 1)
		};

		Mat4 matInvProj = mMatProj, matInvView = mMatView;

		matInvProj.Inverse();
		matInvView.Inverse();

		for (int i = 0; i < 8; ++i)
			mViewCorner[i] = corner[i] * matInvProj;

		for (int i = 0; i < 8; ++i)
			mWorldCorner[i] = mViewCorner[i] * matInvView;
	}
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:42,代码来源:MCamera.cpp

示例5: up

void GraphicsGL2::SetupScene(
	float fov, float new_view_distance,
	const Vec3 cam_position,
	const Quat & cam_rotation,
	const Vec3 & dynamic_reflection_sample_pos)
{
	// setup the default camera from the passed-in parameters
	{
		GraphicsCamera & cam = cameras["default"];
		cam.fov = fov;
		cam.pos = cam_position;
		cam.orient = cam_rotation;
		cam.view_distance = new_view_distance;
		cam.w = w;
		cam.h = h;
	}

	// create a camera for the skybox with a long view distance
	{
		GraphicsCamera & cam = cameras["skybox"];
		cam = cameras["default"];
		cam.view_distance = 10000;
		cam.pos = Vec3(0);
	}

	// create a camera for the dynamic reflections
	{
		GraphicsCamera & cam = cameras["dynamic_reflection"];
		cam.pos = dynamic_reflection_sample_pos;
		cam.fov = 90; // this gets automatically overridden with the correct fov (which is 90 anyway)
		cam.orient.LoadIdentity(); // this gets automatically rotated for each cube side
		cam.view_distance = 100;
		cam.w = 1; // this gets automatically overridden with the cubemap dimensions
		cam.h = 1; // this gets automatically overridden with the cubemap dimensions
	}

	// create a camera for the dynamic reflection skybox
	{
		GraphicsCamera & cam = cameras["dynamic_reflection_skybox"];
		cam = cameras["dynamic_reflection"];
		cam.view_distance = 10000;
		cam.pos = Vec3(0);
	}

	// create an ortho camera for 2d drawing
	{
		GraphicsCamera & cam = cameras["2d"];

		// this is the glOrtho call we want: glOrtho( 0, 1, 1, 0, -1, 1 );
		cam.orthomode = true;
		cam.orthomin = Vec3(0, 1, -1);
		cam.orthomax = Vec3(1, 0, 1);
	}

	// put the default camera transform into texture3, needed by shaders only
	Mat4 viewMatrix;
	cam_rotation.GetMatrix4(viewMatrix);
	float translate[4] = {-cam_position[0], -cam_position[1], -cam_position[2], 0};
	viewMatrix.MultiplyVector4(translate);
	viewMatrix.Translate(translate[0], translate[1], translate[2]);

	glMatrixMode(GL_TEXTURE);

	glActiveTexture(GL_TEXTURE3);
	glLoadMatrixf(viewMatrix.GetArray());

	// create cameras for shadow passes
	if (shadows)
	{
		Mat4 viewMatrixInv = viewMatrix.Inverse();

		// derive light rotation quaternion from light direction vector
		Quat light_rotation;
		Vec3 up(0, 0, 1);
		float cosa = up.dot(light_direction);
		if (cosa * cosa < 1.0f)
		{
			float a = -acosf(cosa);
			Vec3 x = up.cross(light_direction).Normalize();
			light_rotation.SetAxisAngle(a, x[0], x[1], x[2]);
		}

		std::vector <std::string> shadow_names;
		shadow_names.push_back("near");
		shadow_names.push_back("medium");
		shadow_names.push_back("far");

		for (int i = 0; i < 3; i++)
		{
			float shadow_radius = (1<<i)*closeshadow+(i)*20.0; //5,30,60

			Vec3 shadowbox(1,1,1);
			shadowbox = shadowbox * (shadow_radius*sqrt(2.0));
			Vec3 shadowoffset(0,0,-1);
			shadowoffset = shadowoffset * shadow_radius;
			(-cam_rotation).RotateVector(shadowoffset);
			shadowbox[2] += 60.0;

			GraphicsCamera & cam = cameras["shadows_"+shadow_names[i]];
			cam = cameras["default"];
//.........这里部分代码省略.........
开发者ID:lwllovewf2010,项目名称:vdrift,代码行数:101,代码来源:graphics_gl2.cpp

示例6: _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


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