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


C++ glm::mat4方法代码示例

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


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

示例1: InitScene

void ParticlesFire::InitScene()
{
    CompileAndLinkShaders();

    GLuint shaderHandle = _shader.GetHandle();
    _renderSub = glGetSubroutineIndex(shaderHandle, GL_VERTEX_SHADER, "render");
    _updateSub = glGetSubroutineIndex(shaderHandle, GL_VERTEX_SHADER, "update");

    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

    glPointSize(50.0f);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    _projection = mat4(1.0);
    _model = mat4(1.0f);
    _angle = glm::half_pi<float>();

    InitBuffers();

    const char* texName = "./media/texture/fire.bmp";
    glActiveTexture(GL_TEXTURE0);
    BMPReader::loadTex(texName);

    _shader.SetUniform("ParticleTex", 0);
    _shader.SetUniform("ParticleLifetime", 4.0f);
    _shader.SetUniform("Accel", vec3(0.0f, 0.1f, 0.0f));
    SetMatrices();
}
开发者ID:nameless323,项目名称:Cookbook,代码行数:29,代码来源:ParticlesFire.cpp

示例2:

glm::mat4 Transform::getTransformationMatrix() const {
	mat4 translationMatrix = glm::translate(mat4(), translation);
	mat4 rotationMatrixX = glm::rotate(mat4(), rotation.x, vec3(1.0f, 0.0f, 0.0f));
	mat4 rotationMatrixY = glm::rotate(mat4(), rotation.y, vec3(0.0f, 1.0f, 0.0f));
	mat4 rotationMatrixZ = glm::rotate(mat4(), rotation.z, vec3(0.0f, 0.0f, 1.0f));
	mat4 scaleMatrix = glm::scale(mat4(), scale);

	return translationMatrix * rotationMatrixX * rotationMatrixY * rotationMatrixZ * scaleMatrix;
}
开发者ID:jaxfrank,项目名称:Voxel-Game,代码行数:9,代码来源:Transform.cpp

示例3: updateMatrices

void OrthoCamera::updateMatrices()
{
	vec3 s = glm::normalize(glm::cross(direction, upVector));
	vec3 u = glm::normalize(glm::cross(s, direction));

	mat4 untranslatedViewMatrix = mat4(vec4(s, 0), vec4(u, 0), vec4(direction, 0), vec4(0, 0, 0, 1.0f));
	untranslatedViewMatrix = glm::transpose(untranslatedViewMatrix);

	viewMatrix = glm::translate(untranslatedViewMatrix, -focus);

	projectionMatrix = mat4(1/width,	0,			0,			0,
							0,			1/height,	0,			0, 
							0,			0,			1/depth,	0,
							0,			0,			0,			1);
}
开发者ID:SimonWallner,项目名称:kocmoc-core,代码行数:15,代码来源:OrthoCamera.cpp

示例4: glClearColor

void Scene::draw()
{
   glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
   glm::mat4 mv;

   // Draw the particle system
   mv = _view * _modelTrans * _modelRot;
   glEnable(GL_BLEND);
   glBlendFunc(GL_ONE, GL_ONE);
   _psProg->bind();
   _psProg->setUniform("mv", mv);
   _psProg->setUniform("proj", _proj);
   _particleSystemView->draw();
   glDisable(GL_BLEND);
   
#if 0
   // Draw the settings icon
   _tqProg->bind();
   _tqProg->setUniform("mv", _settingsIconModel);
   _tqProg->setUniform("proj", mat4());
   _settingsIcon->draw();
   _tqProg->release();
#endif
}
开发者ID:riskybacon,项目名称:simulation,代码行数:26,代码来源:Scene.cpp

示例5: mouseMoveEvent

void GLWidget::mouseMoveEvent(QMouseEvent *event) {
    last.x = event->x();
    last.y = event->y();

    vec3 begin = pointOnVirtualTrackball(first);
    vec3 end = pointOnVirtualTrackball(last);

    float dotProduct = dot(normalize(begin), normalize(end));
    float angle = acos(dotProduct);
    vec3 crossP = cross(begin, end);

    if(length(crossP) > .00001f)
    {
        rotationMatrix = rotate(mat4(1.0), angle, normalize(crossP)) * rotationMatrix;
        glUseProgram(cubeProg);
        glUniformMatrix4fv(cubeRotationMatrixLoc, 1, false, value_ptr(rotationMatrix));
        glUseProgram(gridProg);
        glUniformMatrix4fv(gridRotationMatrixLoc, 1, false, value_ptr(rotationMatrix));
        update();
    }


    first.x = last.x;
    first.y = last.y;
}
开发者ID:joshatron,项目名称:CSCI-441-Labs,代码行数:25,代码来源:glwidget.cpp

示例6: getChildToParentMatrix

mat4 getChildToParentMatrix(const Joint &joint) {
	mat4 rotM(glm::mat4_cast(joint.orientation));
	mat4 transM = glm::translate(mat4(1.0f), joint.position);
	
	return transM * rotM;
	//return rotM * transM;
}
开发者ID:pcapp,项目名称:bones,代码行数:7,代码来源:skeleton_test.cpp

示例7: jointToWorldTest

void jointToWorldTest() {
	Joint j0, j1, j2;

	// J0 Setup
	j0.name = "J0";
	j0.parentIndex = -1;
	j0.position = vec3(0, 0, 0);
	j0.orientation = quat(1, 0, 0, 0); // Identity quaternion

	// J1 Setup
	j1.name = "J1";
	j1.parentIndex = 0;
	j1.position.x = 70.1f;
	j1.position.y = 70.1f;
	j1.orientation = glm::quat_cast(glm::rotate(mat4(), 45.0f, vec3(0, 0, 1)));
	
	j2.name = "J2";
	j2.parentIndex = 1;
	//j2.position.x = 70.1f;
	j2.position.x = 0;
	j2.position.y = 100.0f;
	//j2.orientation = glm::quat_cast(glm::rotate(mat4(), 45.0f, vec3(0, 0, 1)));


	Skeleton skeleton;
	skeleton.joints.push_back(j0);
	skeleton.joints.push_back(j1);
	skeleton.joints.push_back(j2);

	buildJointToWorldMatrices(skeleton);
	//mat4 worldM = jointToWorld(skeleton, j2);

	//cout << "World coordinate: " << worldM[3][0] << ", " << worldM[3][1] << ", " << worldM[3][2] << endl;
}
开发者ID:pcapp,项目名称:bones,代码行数:34,代码来源:skeleton_test.cpp

示例8: eye

//----------------------------------------------------------------------------------------
TEST_F(Camera_Test, test_lookAt_forward) {
    vec3 eye(0.0f, 0.0f, 0.0f);
    vec3 center(0.0f, 0.0f, -1.0f);
    vec3 up(0.0f, 1.0f, 0.0f);
    camera.lookAt(eye, center, up);

    EXPECT_PRED2(mat4_eq, mat4(), camera.getViewMatrix());
}
开发者ID:admiralnlson,项目名称:Rigid3D,代码行数:9,代码来源:Camera_Test.cpp

示例9: rotate

mat4 const& Model::getModelMatrix() const
{
	if (!validModelMatrix)
	{
		mat4 scaleMatrix = glm::scale(mat4(), scale);

		mat4 rotateX = rotate(mat4(), rotation.x, vec3(1, 0, 0));
		mat4 rotateY = rotate(mat4(), rotation.y, vec3(0, 1, 0));
		mat4 rotateZ = rotate(mat4(), rotation.z, vec3(0, 0, 1));

		mat4 translateMatrix = translate(mat4(), position);

		modelMatrix = translateMatrix * rotateZ * rotateY * rotateX * scaleMatrix;

		validModelMatrix = true;
		validInverseModelMatrix = false;
	}

	return modelMatrix;
}
开发者ID:Jereq,项目名称:March-of-the-Bombs,代码行数:20,代码来源:Model.cpp

示例10: renderScene

void renderScene(void) {

    bool bRet;

    angle+=0.01;
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    // glLightfv(GL_LIGHT0, GL_POSITION, lpos);
    
    vec4 Position = vec4( 0.0f, 0.0f, -1.0f, 1.0f );
    mat4 ViewMatrix = glm::lookAt( vec3(0.0,0.0,-2.0), 
                                   vec3(0.0,0.0,0.0),
                                   vec3(0.0,1.0,0.0) );

    mat4 Model = mat4(1.0f);
    mat4 ModelMatrix = glm::rotate( Model, angle, vec3( 0.0f, 1.0f, 0.7f ) );
    mat4 ModelViewMatrix = ViewMatrix * ModelMatrix;
    mat4 ProjectionMatrix = glm::perspective( 90.0f, 1.0f, 0.1f, 100.0f );
    mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
    mat3 NormalMatrix = glm::inverse( glm::transpose( glm::mat3(ModelViewMatrix) ) );

    bRet = _GLSLProgram->SetUniform( "MVP", (mat4 const) MVP );
    bRet = _GLSLProgram->SetUniform( "ProjectionMatrix", (mat4 const) ProjectionMatrix );
    bRet = _GLSLProgram->SetUniform( "ModelViewMatrix", (mat4 const) ModelViewMatrix );
    bRet = _GLSLProgram->SetUniform( "NormalMatrix", (mat3 const) NormalMatrix );

    vec3 LightLa = vec3( 0.3, 0.3, 0.3 );
    vec3 LightLd = vec3( 0.5, 0.5, 0.5 );
    vec3 LightLs = vec3( 0.2, 0.2, 0.2 );
    bRet = _GLSLProgram->SetUniform( "Light.La", LightLa );
    bRet = _GLSLProgram->SetUniform( "Light.Ld", LightLd );
    bRet = _GLSLProgram->SetUniform( "Light.Ls", LightLs );

    vec3 LightPosition( 1.0f, 1.0f, -1.0f );
    bRet = _GLSLProgram->SetUniform( "Light.Position", LightPosition );

    vec3 MaterialCoeffKa( 1.0f, 1.0f, 1.0f );
    vec3 MaterialCoeffKd( 1.0f, 1.0f, 1.0f );
    vec3 MaterialCoeffKs( 1.0f, 1.0f, 1.0f );
    bRet = _GLSLProgram->SetUniform( "Material.Ka", MaterialCoeffKa );
    bRet = _GLSLProgram->SetUniform( "Material.Kd", MaterialCoeffKd );
    bRet = _GLSLProgram->SetUniform( "Material.Ks", MaterialCoeffKs );
    bRet = _GLSLProgram->SetUniform( "Material.Shininess", 1.0f );

    _GLSLProgram->BindVertexArray();

    glDrawArrays( GL_TRIANGLES, 0, 3 );
    // glFrontFace(GL_CW);
    // glutSolidTeapot( 10 );
    // glFrontFace(GL_CCW);

    _GLSLProgram->UnBindVertexArray();

    glutSwapBuffers();
}
开发者ID:dreamsxin,项目名称:enhance,代码行数:54,代码来源:main.cpp

示例11: DrawScene

void Decay::DrawScene()
{
    _model = mat4(1.0f);
    _model = glm::rotate(_model, glm::radians(-15.0f), vec3(0.0f, 1.0f, 0.0f));
    _model = glm::rotate(_model, glm::radians(-90.0f), vec3(1.0f, 0.0f, 0.0f));
    SetMatrices();

    _shader.SetUniform("Material.Kd", 0.7f, 0.5f, 0.3f);
    _shader.SetUniform("Material.Ks", 1.0f, 1.0f, 1.0f);
    _shader.SetUniform("Material.Shininess", 100.0f);
    _teapot->Render();
}
开发者ID:nameless323,项目名称:Cookbook,代码行数:12,代码来源:Decay.cpp

示例12:

    Camera& Camera::transform() {

        mat4 rM = mat4(
                rightVec.x, upVec.x, viewVec.x, 0,
                rightVec.y, upVec.y, viewVec.y, 0,
                rightVec.z, upVec.z, viewVec.z, 0,
                0,0,0,1);

        mat4 tM = glm::translate( mat4(1.0), vec3(posVec.x, posVec.y, posVec.z) );

        view = rM * tM;

        if (isFrontBack) {
            mat4 rrM = mat4(
                    -rightVec.x, upVec.x, -viewVec.x, 0,
                    -rightVec.y, upVec.y, -viewVec.y, 0,
                    -rightVec.z, upVec.z, -viewVec.z, 0,
                    0,0,0,1);

            backView = rrM * tM;
        }

        if (isStereo) {
            //printf("isStereo = TRUE\n");
            rightView = rightTranslate * view;
            leftView = leftTranslate * view;

            if (isFrontBack) {
                rightBackView = rightTranslate * backView;
                leftBackView = leftTranslate * backView;
            }
        }

        isTransformed = false;

        return *this;
    }
开发者ID:brianherman,项目名称:al2,代码行数:37,代码来源:Camera.cpp

示例13: tan

    Camera& Camera::stereo(float _c, float _e) {

        isStereo = true;

        _convergence = _c;
        _eyeSep = _e;


        float top, bottom, leftL, rightL, leftR, rightR;

        top     = nearPlane * tan(radians(fovy)/2);
        bottom  = -top;

        float a = aspect * tan(radians(fovy)/2) * convergence();

        float b = a - eyeSep()/2;
        float c = a + eyeSep()/2;

        leftR   =  -c * nearPlane/convergence();
        rightR   =   b * nearPlane/convergence();

        leftL   =  -b * nearPlane/convergence();
        rightL   =   c * nearPlane/convergence();

        //rightProjection = Matrix4f::perspective(leftR, rightR, bottom, top, nearPlane, farPlane );
        //rightTranslate = Matrix4f::translate( -eyeSep/2, 0.0f, 0.0f );
        //leftProjection = Matrix4f::perspective(leftL, rightL, bottom, top, nearPlane, farPlane );
        //leftTranslate = Matrix4f::translate( eyeSep/2, 0.0f, 0.0f );
        rightProjection = glm::frustum(leftR, rightR, bottom, top, nearPlane, farPlane );
        rightTranslate = glm::translate(mat4(1.0), vec3(-eyeSep()/2, 0.0f, 0.0f) );
        leftProjection = glm::frustum(leftL, rightL, bottom, top, nearPlane, farPlane );
        leftTranslate = glm::translate(mat4(1.0), vec3(eyeSep()/2, 0.0f, 0.0f) );

        isTransformed = true;

        return *this;
    }
开发者ID:brianherman,项目名称:al2,代码行数:37,代码来源:Camera.cpp

示例14: setProjection

void Scene::setProjection()
{
   _proj = glm::perspective(_fov, float(_width) / float(_height), _depthMin, _depthMax);
   glViewport(0, 0, _width, _height);
   
   // Set the size for the settings quad
   float size = 0.03;
   float qWidth = size;
   float aspectRatio = float(_width) / float(_height);
   float qHeight = size * aspectRatio;
   
   float qTransX = 1.0 - qWidth - size * 0.5;
   float qTransY = -1.0 + qHeight + size * 0.5;
   
   mat4 qScale = glm::scale(mat4(), vec3(qWidth, qHeight, 1.0));
   mat4 qTrans = glm::translate(mat4(), vec3(qTransX, qTransY, 0));

   _settingsIconModel = qTrans * qScale;
   
   qScale = glm::scale(mat4(), vec3(1.0 / qWidth, 1.0 / qHeight, 1.0));
   qTrans = glm::translate(mat4(), vec3(-qTransX, -qTransY, 1.0));
   
   _settingsIconModelInv = qScale * qTrans;
}
开发者ID:riskybacon,项目名称:simulation,代码行数:24,代码来源:Scene.cpp

示例15: childToParentTest

void childToParentTest() {
	Skeleton skeleton;
	Joint j0;

	j0.name = "J0";
	j0.parentIndex = -1;
	j0.position = vec3(70.71, 70.71, 0);
	j0.orientation = glm::quat_cast(glm::rotate(mat4(), 45.0f, vec3(0, 0, 1)));

	skeleton.joints.push_back(j0);

	mat4 P = getChildToParentMatrix(j0)  ;
	printMatrix(P);

	vec4 v(0,100, 0, 1); // Make it homogenous with w = 1
	vec4 v_ = P * v;

	cout << "In world space: " << v_.x << ", " << v_.y << ", " << v_.z << endl;
}
开发者ID:pcapp,项目名称:bones,代码行数:19,代码来源:skeleton_test.cpp


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