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


C++ Mat4f类代码示例

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


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

示例1: xformMouseToUser

Mat4f GLContext::xformMouseToUser(const Mat4f& userToClip) const
{
    return
        userToClip.inverted() *
        Mat4f::scale(Vec3f(1.0f, -1.0f, 1.0f)) *
        Mat4f::translate(Vec3f(-1.0f, -1.0f, 0.0f)) *
        Mat4f::scale(Vec3f(m_viewScale, 1.0f)) *
        Mat4f::translate(Vec3f(0.5f, 0.5f, 0.0f));
}
开发者ID:cerendikmen,项目名称:CG-Assignment-6,代码行数:9,代码来源:GLContext.cpp

示例2: cullAll

	void ForwardRenderer::renderWithZPrePass(IRenderContext* rc)
	{
		cullAll();
		Mat4f VP = m_pCamera->getProjectionMatrix() * m_pCamera->getViewMatrix();

		// Do Z Pre-Pass
		rc->enableColorBuffer(false, false, false, false);
		rc->enableDepthBuffer(true);
		rc->clear(IRenderContext::DEPTH);
		rc->setDepthTest(IRenderContext::DepthTestValue::Less);
		rc->setDrawMode(IRenderContext::DrawMode::Fill);
		m_pZPrePassShader->use();
		for (auto& e : m_entitiesCulled) // TODO: front-to-back order
		{
			Mat4f MVP = VP * e->getModelMatrix();
			Platform::get()->curShaderProgram()->setUniformFloatMatrix4Array(m_prePassMVPHandle, 1, false,
					MVP.getDataPointer());
			rc->drawMesh(e->getMesh());
		}

		// Do color pass
		rc->enableColorBuffer(true, true, true, true);
		rc->enableDepthBuffer(false);
		rc->clear(IRenderContext::COLOR);
		rc->setDepthTest(IRenderContext::DepthTestValue::LessEqual);
		rc->setDrawMode(IRenderContext::DrawMode::Fill);
		for (auto& e : m_entitiesCulled) // TODO: ordered by material
		{
			e->setupUnique();
			e->setupMaterial();
			rc->drawMesh(e->getMesh());
		}

		// Render translucent objects in back-to-front order
		rc->enableDepthBuffer(true);
		for (auto& e : m_translucentEntitiesCulled) // TODO: order
		{
			e->setupUnique();
			e->setupMaterial();
			rc->drawMesh(e->getMesh());
		}
	}
开发者ID:Drag-On,项目名称:Dragon-Blaze-Game-Library,代码行数:42,代码来源:ForwardRenderer.cpp

示例3: glMatrixMode

void cameraProto::setGl() {
  //// Set up a perspective view, with square aspect ratio
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
  // extern void gluPerspective (GLdouble fov_y, GLdouble aspect, GLdouble zNear, GLdouble zFar);
    gluPerspective((GLdouble)fov_, (GLdouble)1.0, (GLdouble)near_clip_, (GLdouble)far_clip_);
    // Rotate the image
    glMatrixMode( GL_MODELVIEW );  // Current matrix affects objects position_s
    glLoadIdentity();              // Initialize to the identity
    
  Mat4f modelView;
  current_quat_.get(modelView);

  gluLookAt(0,  0,  current_dist_,
            0,  0,  0,
            0,  1,  0);
  
  glMultMatrixf(modelView.getPtr());
  glTranslatef(this->look_at_.x, this->look_at_.y,this->look_at_.z);
}
开发者ID:Ur-Ideas-LabS,项目名称:ParallelFDTD,代码行数:20,代码来源:cameraProto.cpp

示例4: Primitive

Cube::Cube(const Vec3f &pos, const Vec3f &scale, const Mat4f &rot,
        const std::string &name, std::shared_ptr<Bsdf> bsdf)
: Primitive(name),
  _rot(rot),
  _invRot(rot.transpose()),
  _pos(pos),
  _scale(scale*0.5f),
  _bsdf(std::move(bsdf))
{
    _transform = Mat4f::translate(_pos)*rot*Mat4f::scale(Vec3f(scale));
}
开发者ID:1510649869,项目名称:tungsten,代码行数:11,代码来源:Cube.cpp

示例5: update_euler

void Options::update_euler()
{
	Mat4f matrix = quaternion.to_matrix();

	Vec3f euler = matrix.get_euler(order_YXZ);
	rotation_x.set_radians(euler.x);
	rotation_y.set_radians(euler.y);
	rotation_z.set_radians(euler.z);

	// Make 0 to 360 degrees
	rotation_x.normalize();
	rotation_y.normalize();
	rotation_z.normalize();

	set_value(slider_rotation_x, rotation_x.to_degrees(), 0, max_angle_value);
	set_value(slider_rotation_y, rotation_y.to_degrees(), 0, max_angle_value);
	set_value(slider_rotation_z, rotation_z.to_degrees(), 0, max_angle_value);

	update_all_slider_text();
}
开发者ID:Cassie90,项目名称:ClanLib,代码行数:20,代码来源:options.cpp

示例6: calculateViewingTransformParameters

void Camera::applyViewingTransform() {
	if( mDirtyTransform )
		calculateViewingTransformParameters();

	ModelerDrawState *mds = ModelerDrawState::Instance();

	if(mds->m_rayFile)
	{
		fprintf( mds->m_rayFile, "camera {\n\tposition = (%f, %f, %f);\n\tlook_at = (%f, %f, %f);\n\taspectratio = 1\n\tfov = 30; }\n\n",
			mPosition[0], mPosition[1], mPosition[2],
			mLookAt[0], mLookAt[1], mLookAt[2]);

		
	}

	// Place the camera at mPosition, aim the camera at
	// mLookAt, and twist the camera such that mUpVector is up
    /*gluLookAt(	mPosition[0], mPosition[1], mPosition[2],
				mLookAt[0],   mLookAt[1],   mLookAt[2],
				mUpVector[0], mUpVector[1], mUpVector[2]);*/

    // You Will Have to implement this (gluLookAt() ) yourself!
	// what fun that will be!
    Vec3f n = mPosition - mLookAt;
    Vec3f v = mUpVector - ((mUpVector * n) / (n * n)) * n;
    Vec3f u = v ^ n;
    u.normalize();
    v.normalize();
    n.normalize();

    Mat4f mat;
    mat[0][0] = u[0]; mat[0][1] = v[0]; mat[0][2] = n[0];
    mat[1][0] = u[1]; mat[1][1] = v[1]; mat[1][2] = n[1];
    mat[2][0] = u[2]; mat[2][1] = v[2]; mat[2][2] = n[2];
    mat = mat.transpose();
    mat = mat * mat.createTranslation(-mPosition[0], -mPosition[1], -mPosition[2]);
    
    // Transpose the final matrix so that n is in column-major order to match OpenGL.
    mat = mat.transpose();
    glMultMatrixf(mat.n);
}
开发者ID:aerieworks,项目名称:csep_557_modeler,代码行数:41,代码来源:camera.cpp

示例7: axis

void m3dTest::eulerAnglesTest()
{
	using namespace m3d;
	Vec3f axis(frand(), frand(), frand());
	float angle = frand(0, 2.0f*PI);
	Mat4f input = Mat4f::rotAxis(axis, angle);

	Vec3f euler = input.eulerAngles();

	Mat4f output = Mat4f::rotZ(euler.z) * Mat4f::rotX(euler.x) * Mat4f::rotY(euler.y);

	for (int x = 0; x < 4; ++x) {
		for (int y = 0; y < 4; ++y) {
			// check if equal
			CPPUNIT_ASSERT(fabs(input[x][y] - output[x][y]) < EPSILON);

			// check for NaN
			CPPUNIT_ASSERT(output[x][y] == output[x][y]);
		}
	}
}
开发者ID:Huebn0r,项目名称:dominator,代码行数:21,代码来源:m3dtest.cpp

示例8: dir

void m3dTest::orthonormalInverseTest()
{
	using namespace m3d;
	Vec3f dir(frand(), frand(), frand());
	Vec3f pos(frand(), frand(), frand());
	Mat4f matrix = Mat4f::gramSchmidt(dir, pos);

	Mat4f inverse = matrix.inverse();
	Mat4f orth_inverse = matrix.orthonormalInverse();

	for (int x = 0; x < 4; ++x) {
		for (int y = 0; y < 4; ++y) {
			// check if equal
			CPPUNIT_ASSERT(fabs(inverse[x][y] - orth_inverse[x][y]) < EPSILON);

			// check for NaN
			CPPUNIT_ASSERT(inverse[x][y] == inverse[x][y]);
			CPPUNIT_ASSERT(orth_inverse[x][y] == orth_inverse[x][y]);
		}
	}
}
开发者ID:Huebn0r,项目名称:dominator,代码行数:21,代码来源:m3dtest.cpp

示例9: evalBspline

Curve evalBspline( const vector< Vec3f >& P, unsigned steps )
{
    // Check
    if( P.size() < 4 )
    {
        cerr << "evalBspline must be called with 4 or more control points." << endl;
        exit( 0 );
    }

    cerr << "\t>>> evalBSpline has been called with the following input:" << endl;

    cerr << "\t>>> Control points (type vector< Vec3f >): "<< endl;
    for( unsigned i = 0; i < P.size(); ++i )
    {
        cerr << "\t>>> "; printTranspose(P[i]); cerr << endl;
    }

	
    cerr << "\t>>> Steps (type steps): " << steps << endl;

	// Use your evalBezier function to evaluate the B-spline.
    // Convert the input control points to suitable coordinate system.
    // See lecture notes for further instructions.
    vector<Vec3f> Pbz;

	for (int i = 0; i < P.size()-3; i++) {

		// Create the G matrix for conversion
		Mat4f G;

		for (int j = 0; j < 4; j++) {
			G.setCol(j, Vec4f(P[i+j].x, P[i+j].y, P[i+j].z, 0.0));
		}

		// Calculate the conversion matrix: G_2 = G_1 * B_1 * (B_2)^-1
		G = G * Base::bsplineBase * Base::bezierBase.inverted();

		// Detach the converted control points from the G matrix
		for (int j = 0; j < 3; j++) {
			Pbz.push_back(Vec3f(G.getCol(j)[0], G.getCol(j)[1], G.getCol(j)[2]));
		}

		// Only add the last column for the very last index
		if (i+3 == P.size()-1) {
			Pbz.push_back(Vec3f(G.getCol(3)[0], G.getCol(3)[1], G.getCol(3)[2]));
		}
	}

    return evalBezier(Pbz, steps);
}
开发者ID:Zerphed,项目名称:computer-graphics-course,代码行数:50,代码来源:curve.cpp

示例10: vin

void m3dTest::saveLoadTest()
{
	using namespace m3d;
	Vec4f vin(frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f),
			frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f));

	Mat4f min(frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f),
			frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f),
			frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f),
			frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f),
			frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f),
			frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f),
			frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f),
			frand(-10000.0f, 10000.0f), frand(-10000.0f, 10000.0f));

	Vec4f vout;
	Mat4f mout;

	vout.assign(vin.str());
	mout.assign(min.str());

	for (int x = 0; x < 4; ++x) {
		// check if equal, allow a reasonable deviation
		CPPUNIT_ASSERT(fabs(vin[x] - vout[x]) < 0.005f);

		// check for NaN
		CPPUNIT_ASSERT(vout[x] == vout[x]);
	}

	for (int x = 0; x < 4; ++x) {
		for (int y = 0; y < 4; ++y) {
			// check if equal, allow a reasonable deviation
			CPPUNIT_ASSERT(fabs(min[x][y] - mout[x][y]) < 0.005f);

			// check for NaN
			CPPUNIT_ASSERT(mout[x][y] == mout[x][y]);
		}
	}
}
开发者ID:Huebn0r,项目名称:dominator,代码行数:39,代码来源:m3dtest.cpp

示例11: dir

void m3dTest::gramSchmidtTest()
{
	using namespace m3d;
	Vec3f dir(frand(), frand(), frand());
	Vec3f pos(frand(), frand(), frand());
	Mat4f matrix = Mat4f::gramSchmidt(dir, pos);

	// check if all axes are perpendicular
	CPPUNIT_ASSERT(fabs(matrix.getX() * matrix.getY()) < EPSILON);
	CPPUNIT_ASSERT(fabs(matrix.getY() * matrix.getZ()) < EPSILON);
	CPPUNIT_ASSERT(fabs(matrix.getX() * matrix.getZ()) < EPSILON);

	for (int x = 0; x < 4; ++x) {
		for (int y = 0; y < 4; ++y) {

			// check for NaN
			CPPUNIT_ASSERT(matrix[x][y] == matrix[x][y]);
		}
	}

	// check if position is correct
	CPPUNIT_ASSERT(matrix.getW() == pos);
}
开发者ID:s090444,项目名称:dominator,代码行数:23,代码来源:m3dtest.cpp

示例12: if

 void                setUniform      (int loc, const Mat4f& v) { if (loc >= 0) glUniformMatrix4fv(loc, 1, false, v.getPtr()); }
开发者ID:jtyot,项目名称:morse-pc,代码行数:1,代码来源:GLContext.hpp

示例13: switch

bool App::handleEvent(const Window::Event& ev)
{
    if (ev.type == Window::EventType_Close)
    {
        m_window.showModalMessage("Exiting...");
        delete this;
        return true;
    }

    Action action = m_action;
    m_action = Action_None;
    String name;
    Mat4f mat;

    switch (action)
    {
    case Action_None:
        break;

    case Action_LoadMesh:
        name = m_window.showFileLoadDialog("Load mesh", getMeshImportFilter());
        if (name.getLength()) {
			Bvh::setBvhMode((Bvh::BvhMode)m_bvhMode);
            loadMesh(name);
		}
        break;

    case Action_ReloadMesh:
        if (m_meshFileName.getLength()) {
			Bvh::setBvhMode((Bvh::BvhMode)m_bvhMode);
            loadMesh(m_meshFileName);
		}
        break;

    case Action_SaveMesh:
        name = m_window.showFileSaveDialog("Save mesh", getMeshExportFilter());
        if (name.getLength())
            saveMesh(name);
        break;

    case Action_ResetCamera:
        if (m_mesh)
        {
            m_cameraCtrl.initForMesh(m_mesh);
            m_commonCtrl.message("Camera reset");
        }
        break;

    case Action_EncodeCameraSignature:
        m_window.setVisible(false);
        printf("\nCamera signature:\n");
        printf("%s\n", m_cameraCtrl.encodeSignature().getPtr());
        waitKey();
        break;

    case Action_DecodeCameraSignature:
        {
            m_window.setVisible(false);
            printf("\nEnter camera signature:\n");

            char buf[1024];
            if (scanf_s("%s", buf, FW_ARRAY_SIZE(buf)))
                m_cameraCtrl.decodeSignature(buf);
            else
                setError("Signature too long!");

            if (!hasError())
                printf("Done.\n\n");
            else
            {
                printf("Error: %s\n", getError().getPtr());
                clearError();
                waitKey();
            }
        }
        break;

    case Action_NormalizeScale:
        if (m_mesh)
        {
            Vec3f lo, hi;
            m_mesh->getBBox(lo, hi);
            m_mesh->xform(Mat4f::scale(Vec3f(2.0f / (hi - lo).max())) * Mat4f::translate((lo + hi) * -0.5f));
        }
        break;

    case Action_FlipXY:
        nvswap(mat.col(0), mat.col(1));
        if (m_mesh)
        {
            m_mesh->xform(mat);
            m_mesh->flipTriangles();
        }
        break;

    case Action_FlipYZ:
        nvswap(mat.col(1), mat.col(2));
        if (m_mesh)
        {
            m_mesh->xform(mat);
//.........这里部分代码省略.........
开发者ID:Zerphed,项目名称:advanced-computer-graphics-course,代码行数:101,代码来源:App.cpp

示例14: centBot


//.........这里部分代码省略.........

    // Create vertices
    uint zPoly;
    for (zPoly = 0; zPoly <= numPolysZDir; zPoly++)
    {
        float fT = static_cast<float>((1.0/numPolysZDir)*(zPoly));
        float radius = bottomRadius + fT*(topRadius - bottomRadius);
        Vec3f center(fT*topOffsetX, fT*topOffsetY, fT*height);

        Vec3fArray verts;
        verts.reserve(numSlices);
        Vec3f point = Vec3f::ZERO;

        double da = 2*PI_D/numSlices;
        uint i;
        for (i = 0; i < numSlices; i++) 
        {
            // Precompute this one (A = i*da;)
            double sinA = Math::sin(i*da);
            double cosA = Math::cos(i*da);

            point.x() = static_cast<float>(-sinA*radius);
            point.y() = static_cast<float>( cosA*radius);
            point.z() = 0;

            point += center;

            verts.add(point);
        }

        uint baseNodeIdx = builder->addVertices(verts);

        // First time we only create the sourceNodes
        if (zPoly != 0)
        {
            uint offset = baseNodeIdx - numSlices;
            uint piConn[4] = { 0, 0, 0, 0 };

            // Normals facing outwards
            if (normalsOutwards)
            {
                uint i;
                for (i = 0; i < numSlices; i++) 
                {
                    piConn[0] = offset + i;
                    piConn[1] = offset + i + 1;
                    piConn[2] = offset + i + numSlices + 1;
                    piConn[3] = offset + i + numSlices;

                    if (i == numSlices - 1) 
                    {
                        piConn[1] = offset;
                        piConn[2] = offset + numSlices;
                    }

                    builder->addQuad(piConn[0], piConn[1], piConn[2], piConn[3]);
                }
            }

            // Normals facing inwards
            else
            {
                uint i;
                for (i = 0; i < numSlices; i++) 
                {
                    piConn[0] = offset + i + 1;
                    piConn[1] = offset + i;
                    piConn[2] = offset + i + numSlices;
                    piConn[3] = offset + i + numSlices + 1;

                    if (i == numSlices - 1) 
                    {
                        piConn[0] = offset;
                        piConn[3] = offset + numSlices;
                    }

                    builder->addQuad(piConn[0], piConn[1], piConn[2], piConn[3]);
                }
            }
        }
    }

    if (closedBot)
    {
        createDisc(bottomRadius, numSlices, builder);
    }

    if (closedTop)
    {
        uint startIdx = builder->vertexCount();
        createDisc(topRadius, numSlices, builder);
        uint endIdx = builder->vertexCount() - 1;

        // Translate the top disc sourceNodes, also flip it to get the normals the right way
        Mat4f mat = Mat4f::fromRotation(Vec3f(1.0f, 0.0f, 0.0f), Math::toRadians(180.0f));
        mat.translatePreMultiply(Vec3f(topOffsetX, topOffsetY, height));

        builder->transformVertexRange(startIdx, endIdx, mat);
    }
}
开发者ID:akva2,项目名称:ResInsight,代码行数:101,代码来源:cvfGeometryUtils.cpp

示例15: xformPositions

 void                xform               (const Mat4f& mat)              { xformPositions(mat); xformNormals(mat.getXYZ().transposed().inverted()); }
开发者ID:marekvinkler,项目名称:NTrace,代码行数:1,代码来源:Mesh.hpp


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