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


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

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


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

示例1: Project

Vector2 OpenGLRenderer::Project(const Matrix4 &cameraMatrix, const Matrix4 &projectionMatrix, const Polycode::Rectangle &viewport, const Vector3 &coordiante) const {
    
	GLdouble mv[16];
	Matrix4 camInverse = cameraMatrix.Inverse();	
	Matrix4 cmv;
	cmv.identity();
	cmv = cmv * camInverse;
    
	for(int i=0; i < 16; i++) {
		mv[i] = cmv.ml[i];
	}
    
	GLint vp[4] = {viewport.x, viewport.y, viewport.w, viewport.h};

	GLdouble _sceneProjectionMatrix[16];
	for(int i=0; i < 16; i++) {
		_sceneProjectionMatrix[i] = projectionMatrix.ml[i];
	}	

	GLdouble coords[3];
	
	gluProject(coordiante.x, coordiante.y, coordiante.z, mv, _sceneProjectionMatrix, vp, &coords[0], &coords[1], &coords[2]);
	
    return Vector2(coords[0] / backingResolutionScaleX, (viewport.h-coords[1]) / backingResolutionScaleY);
}
开发者ID:HeadClot,项目名称:Polycode,代码行数:25,代码来源:PolyGLRenderer.cpp

示例2: nearVec

Vector3 OpenGLRenderer::projectRayFrom2DCoordinate(Number x, Number y, const Matrix4 &cameraMatrix, const Matrix4 &projectionMatrix, const Polycode::Rectangle &viewport) {
	GLdouble nearPlane[3],farPlane[3];

	GLdouble mv[16];
	Matrix4 camInverse = cameraMatrix.Inverse();	
	Matrix4 cmv;
	cmv.identity();
	cmv = cmv * camInverse;

	for(int i=0; i < 16; i++) {
		mv[i] = cmv.ml[i];
	}

	GLint vp[4] = {viewport.x, viewport.y, viewport.w, viewport.h};

	GLdouble _sceneProjectionMatrix[16];
	for(int i=0; i < 16; i++) {
		_sceneProjectionMatrix[i] = projectionMatrix.ml[i];
	}

	gluUnProject(x, (yRes*backingResolutionScaleY) - y, 0.0, mv, _sceneProjectionMatrix, vp, &nearPlane[0], &nearPlane[1], &nearPlane[2]);
	gluUnProject(x, (yRes*backingResolutionScaleY) - y, 1.0, mv, _sceneProjectionMatrix, vp, &farPlane[0], &farPlane[1], &farPlane[2]);

	Vector3 nearVec(nearPlane[0], nearPlane[1], nearPlane[2]);
	Vector3 farVec(farPlane[0], farPlane[1], farPlane[2]);

	Vector3 dirVec = (farVec) - (nearVec);	
	dirVec.Normalize();

	return dirVec;
}
开发者ID:HeadClot,项目名称:Polycode,代码行数:31,代码来源:PolyGLRenderer.cpp

示例3: Unproject

Vector3 OpenGLRenderer::Unproject(Number x, Number y, const Matrix4 &cameraMatrix, const Matrix4 &projectionMatrix, const Polycode::Rectangle &viewport) {
	Vector3 coords;
	GLfloat wx, wy, wz;
	GLdouble cx, cy, cz;

	GLdouble mv[16];
	Matrix4 camInverse = cameraMatrix.Inverse();
	Matrix4 cmv;
	cmv.identity();
	cmv = cmv * camInverse;
    
	for(int i=0; i < 16; i++) {
		mv[i] = cmv.ml[i];
	}
    
	GLint vp[4] = {viewport.x, viewport.y, viewport.w, viewport.h};
    
	GLdouble _sceneProjectionMatrix[16];
	for(int i=0; i < 16; i++) {
		_sceneProjectionMatrix[i] = projectionMatrix.ml[i];
	}	
	
	wx = ( Number ) x;
	wy = ( Number ) vp[3] - ( Number ) y;
	glReadPixels( x * backingResolutionScaleX, wy * backingResolutionScaleY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &wz );
	
	gluUnProject( wx, wy, wz, mv, _sceneProjectionMatrix, vp, &cx, &cy, &cz );
	
	coords = Vector3( cx, cy, cz );
	
	return coords;	
}
开发者ID:HeadClot,项目名称:Polycode,代码行数:32,代码来源:PolyGLRenderer.cpp

示例4: CreateViewPlane

void BaseMesh::CreateViewPlane(float EyeDist, UINT slices, MatrixController &MC)
{
    Matrix4 Perspective = MC.Perspective, PInverse;

    PInverse = Perspective.Inverse();

    Vec3f PerspectiveCoord(0.0f, 0.0f, EyeDist);
    PerspectiveCoord = Perspective.TransformPoint(PerspectiveCoord);    //get the top-left coord in persp. space

    PerspectiveCoord.x = 1.0f;
    PerspectiveCoord.y = -1.0f;
    PerspectiveCoord = PInverse.TransformPoint(PerspectiveCoord);        //get the bottom-right coord in persp. space

    CreatePlane(2.0f, slices, slices);    //create the X-Y plane

    Matrix4 Scale = Matrix4::Scaling(Vec3f(PerspectiveCoord.x, PerspectiveCoord.y, 1.0f));    //scale it appropriately,
    Matrix4 Translate = Matrix4::Translation(Vec3f(0.0f,0.0f,PerspectiveCoord.z));            //translate it away from the eye,

    Matrix4 VInverse = MC.View.Inverse();    //we need to transform our mesh and we want to fact the view and world transforms in
    Matrix4 WInverse = MC.World.Inverse();

    //
    // Translate and scale, then go into object space by multiplying through the inverse of view/world.
    //
    ApplyMatrix(Translate * Scale * VInverse * WInverse);
}
开发者ID:ghsoftco,项目名称:basecode14,代码行数:26,代码来源:BaseMeshShapes.cpp

示例5: FindHits

void Picker::FindHits(const D3D9Mesh &M, const Matrix4 &WorldViewProjectionTransform, const Vec3f &VecEye, const Vec2f &MousePoint,
                      Vector<float> &Hits, DWORD &FirstHitFaceIndex, float &u, float &v)
{
    Vec3f LookPtProjection(Math::LinearMap(0.0f, 1.0f, -1.0f, 1.0f, MousePoint.x),
                           Math::LinearMap(0.0f, 1.0f, 1.0f, -1.0f, MousePoint.y),
                           0.5f);
    Vec3f LookPtObject = WorldViewProjectionTransform.Inverse().TransformPoint(LookPtProjection);
    M.QueryHits(VecEye, LookPtObject - VecEye, Hits, FirstHitFaceIndex, u, v);
}
开发者ID:ghsoftco,项目名称:basecode14,代码行数:9,代码来源:Picker.cpp

示例6: UnProject

Vector3 Camera::UnProject(float32 winx, float32 winy, float32 winz, const Rect & viewport)
{
//	Matrix4 finalMatrix = modelMatrix * projMatrix;//RenderManager::Instance()->GetUniformMatrix(RenderManager::UNIFORM_MATRIX_MODELVIEWPROJECTION);
    
    Matrix4 finalMatrix = GetUniformProjModelMatrix();
	finalMatrix.Inverse();		

	Vector4 in(winx, winy, winz, 1.0f);

	/* Map x and y from window coordinates */

	
	switch(RenderManager::Instance()->GetRenderOrientation())
	{
		case Core::SCREEN_ORIENTATION_LANDSCAPE_LEFT:
        {
			float32 xx = (in.y - viewport.y) / viewport.dy;
			float32 yy = (in.x - viewport.x) / viewport.dx;
			
			in.x = xx;
			in.y = yy;
        }
            break;
		case Core::SCREEN_ORIENTATION_LANDSCAPE_RIGHT:
        {
            DVASSERT(false);
        }
			break;
        default:
			in.x = (in.x - viewport.x) / viewport.dx;
			in.y = 1.0f - (in.y - viewport.y) / viewport.dy;
            break;
	}

	/* Map to range -1 to 1 */
	in.x = in.x * 2 - 1;
	in.y = in.y * 2 - 1;
	in.z = in.z * 2 - 1;

	Vector4 out = in * finalMatrix;
	
	Vector3 result(0,0,0);
	if (out.w == 0.0) return result;
	
	result.x = out.x / out.w;
	result.y = out.y / out.w;
	result.z = out.z / out.w;
	return result;
}
开发者ID:dima-belsky,项目名称:dava.framework,代码行数:49,代码来源:Camera.cpp

示例7: Define

void Frustum::Define(const Matrix4& projection)
{
    Matrix4 projInverse = projection.Inverse();

    vertices_[0] = projInverse * Vector3(1.0f, 1.0f, 0.0f);
    vertices_[1] = projInverse * Vector3(1.0f, -1.0f, 0.0f);
    vertices_[2] = projInverse * Vector3(-1.0f, -1.0f, 0.0f);
    vertices_[3] = projInverse * Vector3(-1.0f, 1.0f, 0.0f);
    vertices_[4] = projInverse * Vector3(1.0f, 1.0f, 1.0f);
    vertices_[5] = projInverse * Vector3(1.0f, -1.0f, 1.0f);
    vertices_[6] = projInverse * Vector3(-1.0f, -1.0f, 1.0f);
    vertices_[7] = projInverse * Vector3(-1.0f, 1.0f, 1.0f);

    UpdatePlanes();
}
开发者ID:BlueMagnificent,项目名称:Urho3D,代码行数:15,代码来源:Frustum.cpp

示例8: doCameraTransform

void Camera::doCameraTransform() {

	if(fovSet)
			CoreServices::getInstance()->getRenderer()->setFOV(fov);
	CoreServices::getInstance()->getRenderer()->setExposureLevel(exposureLevel);

	if(matrixDirty) {
		rebuildTransformMatrix();
	}

	Matrix4 camMatrix = getConcatenatedMatrix();
	CoreServices::getInstance()->getRenderer()->setCameraMatrix(camMatrix);	
	camMatrix = camMatrix.Inverse();
	CoreServices::getInstance()->getRenderer()->multModelviewMatrix(camMatrix);		
}
开发者ID:CIB,项目名称:Polycode,代码行数:15,代码来源:PolyCamera.cpp

示例9: doCameraTransform

void Camera::doCameraTransform() {
	
    viewport = renderer->getViewport();

	switch (projectionMode) {
		case PERSPECTIVE_FOV:
			renderer->setViewportShift(cameraShift.x, cameraShift.y);
			renderer->setProjectionFromFoV(fov, nearClipPlane, farClipPlane);
			renderer->setPerspectiveDefaults();
		break;
		case PERSPECTIVE_FRUSTUM:
			renderer->setProjectionFromFrustum(leftFrustum, rightFrustum, bottomFrustum, topFrustum, nearClipPlane, farClipPlane);
			renderer->setPerspectiveDefaults();
		break;
		case ORTHO_SIZE_MANUAL:
			renderer->setProjectionOrtho(orthoSizeX, orthoSizeY, nearClipPlane, farClipPlane, !topLeftOrtho);
		break;
		case ORTHO_SIZE_LOCK_HEIGHT:
			renderer->setProjectionOrtho(orthoSizeY * (viewport.w/viewport.h), orthoSizeY, nearClipPlane, farClipPlane, !topLeftOrtho);
		break;
		case ORTHO_SIZE_LOCK_WIDTH:
			renderer->setProjectionOrtho(orthoSizeX, orthoSizeX * (viewport.h/viewport.w), nearClipPlane, farClipPlane, !topLeftOrtho);
		break;
		case ORTHO_SIZE_VIEWPORT:
			renderer->setProjectionOrtho(viewport.w / renderer->getBackingResolutionScaleX(), viewport.h / renderer->getBackingResolutionScaleY(), !topLeftOrtho);
		break;
		case MANUAL_MATRIX:
            renderer->setProjectionMatrix(projectionMatrix);
        break;
	}
	renderer->setExposureLevel(exposureLevel);

    if(projectionMode != MANUAL_MATRIX) {
        projectionMatrix = renderer->getProjectionMatrix();
    }

	if(matrixDirty) {
		rebuildTransformMatrix();
	}

	Matrix4 camMatrix = getConcatenatedMatrix();
	renderer->setCameraMatrix(camMatrix);	
	camMatrix = camMatrix.Inverse();
	renderer->multModelviewMatrix(camMatrix);		
}
开发者ID:BOZii,项目名称:Polycode,代码行数:45,代码来源:PolyCamera.cpp

示例10: boxIntersect

Number Ray::boxIntersect(const Vector3 &box, const Matrix4 &transformMatrix, float near, float far) const {

	if(box.x == 0 || box.y == 0 || box.z == 0)
		return -1.0;

	Ray r  = tranformByMatrix(transformMatrix.Inverse());

	Vector3 bounds[2];
	bounds[0] = Vector3(-box.x * 0.5, -box.y * 0.5, -box.z * 0.5);
	bounds[1] = Vector3(box.x * 0.5, box.y * 0.5, box.z * 0.5);	
	
	float tmin, tmax, tymin, tymax, tzmin, tzmax;
	tmin = (bounds[r.sign[0]].x - r.origin.x) * r.inv_direction.x;
	tmax = (bounds[1-r.sign[0]].x - r.origin.x) * r.inv_direction.x;
	tymin = (bounds[r.sign[1]].y - r.origin.y) * r.inv_direction.y;
	tymax = (bounds[1-r.sign[1]].y - r.origin.y) * r.inv_direction.y;

	if ( (tmin > tymax) || (tymin > tmax) )
		return -1.0;

	if (tymin > tmin)
		tmin = tymin;

	if (tymax < tmax)
		tmax = tymax;

	tzmin = (bounds[r.sign[2]].z - r.origin.z) * r.inv_direction.z;
	tzmax = (bounds[1-r.sign[2]].z - r.origin.z) * r.inv_direction.z;
	
	if ( (tmin > tzmax) || (tzmin > tmax) )
		return -1.0;

	if (tzmin > tmin)
		tmin = tzmin;

	if (tzmax < tmax)
		tmax = tzmax;
		
	if( (tmin < far) && (tmax > near) ) {
        return fabs(tmin);
    } else {
        return -1.0;
    }
}
开发者ID:Catenstein,项目名称:Polycode,代码行数:44,代码来源:PolyRay.cpp

示例11: doCameraTransform

void Camera::doCameraTransform() {
	Renderer *renderer = CoreServices::getInstance()->getRenderer();
	if(!orthoMode) {
		renderer->setViewportShift(cameraShift.x, cameraShift.y);
		renderer->setFOV(fov);
	}	
	renderer->setExposureLevel(exposureLevel);	
	
	projectionMatrix = renderer->getProjectionMatrix();
	
	if(matrixDirty) {
		rebuildTransformMatrix();
	}

	Matrix4 camMatrix = getConcatenatedMatrix();
	renderer->setCameraMatrix(camMatrix);	
	camMatrix = camMatrix.Inverse();
	renderer->multModelviewMatrix(camMatrix);		
}
开发者ID:AmeliaMesdag,项目名称:Polycode,代码行数:19,代码来源:PolyCamera.cpp

示例12: DefineSplit

void Frustum::DefineSplit(const Matrix4& projection, float near, float far)
{
    Matrix4 projInverse = projection.Inverse();

    // Figure out depth values for near & far
    Vector4 nearTemp = projection * Vector4(0.0f, 0.0f, near, 1.0f);
    Vector4 farTemp = projection * Vector4(0.0f, 0.0f, far, 1.0f);
    float nearZ = nearTemp.z_ / nearTemp.w_;
    float farZ = farTemp.z_ / farTemp.w_;

    vertices_[0] = projInverse * Vector3(1.0f, 1.0f, nearZ);
    vertices_[1] = projInverse * Vector3(1.0f, -1.0f, nearZ);
    vertices_[2] = projInverse * Vector3(-1.0f, -1.0f, nearZ);
    vertices_[3] = projInverse * Vector3(-1.0f, 1.0f, nearZ);
    vertices_[4] = projInverse * Vector3(1.0f, 1.0f, farZ);
    vertices_[5] = projInverse * Vector3(1.0f, -1.0f, farZ);
    vertices_[6] = projInverse * Vector3(-1.0f, -1.0f, farZ);
    vertices_[7] = projInverse * Vector3(-1.0f, 1.0f, farZ);

    UpdatePlanes();
}
开发者ID:BlueMagnificent,项目名称:Urho3D,代码行数:21,代码来源:Frustum.cpp

示例13: preprocessing

void preprocessing(Mesh * _mesh, Vector3 rotate, Vector3 scale, Vector3 translate, 	std::vector<Vector3 * >& normals )
{
	// compute bounding box
		Vector3 minPosition;
		Vector3 maxPosition;
		Vector3 centerPosition;
		double radius=0.0;
		maxPosition[0]=std::numeric_limits<double>::min();
		maxPosition[1]=std::numeric_limits<double>::min();
		maxPosition[2]=std::numeric_limits<double>::min();

		minPosition[0]=std::numeric_limits<double>::max();
		minPosition[1]=std::numeric_limits<double>::max();
		minPosition[2]=std::numeric_limits<double>::max();

		for(unsigned int i=0;i<_mesh->numberOfVertices();i++)
		{
			Vector3 point = *(_mesh->getVertex(i)->getPosition());
			if(point[0] < minPosition[0])
			{
				minPosition[0] = point[0];
			}
			if(point[1] <minPosition[1])
			{
				minPosition[1] = point[1];
			}
			if(point[2] <minPosition[2])
			{
				minPosition[2] = point[2];
			}

			if(point[0] >maxPosition[0])
			{
				maxPosition[0] = point[0];
			}
			if(point[1] >maxPosition[1])
			{
				maxPosition[1] = point[1];
			}
			if(point[2] >maxPosition[2])
			{
				maxPosition[2] = point[2];
			}

		}
	// compute center position
	centerPosition[0] = (maxPosition[0] + minPosition[0])/2.0;
	centerPosition[1] = (maxPosition[1] + minPosition[1])/2.0;
	centerPosition[2] = (maxPosition[2] + minPosition[2])/2.0;

	// compute radius
	//radius =	(maxPosition[0]-centerPosition[0])*(maxPosition[0]-centerPosition[0]) +
	//			(maxPosition[1]-centerPosition[1])*(maxPosition[1]-centerPosition[1])	+
	//			(maxPosition[2]-centerPosition[2])*(maxPosition[2]-centerPosition[2]);

	//bounding box diagonal length:
	double bbdl = (maxPosition-minPosition).length();

	// normalize size and translate to origin
	for (unsigned int i=0; i < _mesh->numberOfVertices(); i++) {
		 Vector3 p = *(_mesh->getVertex(i)->getPosition());
			p = (p-centerPosition)/bbdl;
			
		 _mesh->getVertex(i)->setPosition(p);
	}

	// transform mesh corresponding to rotate, translate and scale
	Matrix4 s;
	s.loadScaling(scale);
	Matrix4 rx;
	rx.loadRotation(Vector3(1.,0.,0.),(M_PI/180.)*rotate.x);
	Matrix4 ry;
	ry.loadRotation(Vector3(0.,1.,0.),(M_PI/180.)*rotate.y);
	Matrix4 rz;
	rz.loadRotation(Vector3(0.,0.,1.),(M_PI/180.)*rotate.z);
	Matrix4 Tf;
	Tf.loadIdentity();
	//Tf *= s*rx*ry*rz*t;

	Tf = s*rx*ry*rz;
	Matrix4 invTft = Tf.Inverse().Transpose();

	//Transform points and normals
	for (unsigned int i=0; i < _mesh->numberOfVertices(); i++) {
		Vector3 p = *(_mesh->getVertex(i)->getPosition());
		p = Tf*p + translate;
		_mesh->getVertex(i)->setPosition(p);
	}

	for( std::vector<Vector3*>::iterator it=normals.begin(); it!=normals.end(); ++it)
	{
		Vector3* n = (*it);
		Vector4 n4 = invTft*Vector4(*n,0.);
		*n = Vector3(n4.x,n4.y,n4.z);
		n->normalize();
		//_mesh->getVertex(i)->setNormal(n);
	}
		
}
开发者ID:javimartin,项目名称:ACGEx1,代码行数:99,代码来源:OBJFileReader.cpp

示例14: Transformed

Plane Plane::Transformed(const Matrix4& transform) const
{
    return Plane(transform.Inverse().Transpose() * ToVector4());
}
开发者ID:LumaDigital,项目名称:AtomicGameEngine,代码行数:4,代码来源:Plane.cpp

示例15: Transform

void Plane::Transform(const Matrix4& transform)
{
    Define(transform.Inverse().Transpose() * ToVector4());
}
开发者ID:LumaDigital,项目名称:AtomicGameEngine,代码行数:4,代码来源:Plane.cpp


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