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


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

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


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

示例1: 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

示例2: 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

示例3: addMirrorBox

/// <summary>
/// Adds a mirror box of a given size, centered at 0, with no back.
/// </summary>
/// <param name="wallSize">Size of the walls.</param>
void Scene::addMirrorBox(const float wallSize)
{
	using glm::translate;
	using glm::scale;
	using glm::rotate;

	int matIdx = materialsVec.size();

	materialsVec.push_back(Material(vec3(1.0f, 1.0f, 0.8f), 0.7f));	//white			(+0)
	materialsVec.push_back(Material(vec3(1.0f, 0.0f, 0.0f), 0.7f));	//red			(+1)
	materialsVec.push_back(Material(vec3(0.0f, 1.0f, 0.0f), 0.7f));	//green			(+2)


	materialsVec.push_back(Material(vec3(1.0f, 1.0f, 1.0f)));			//white light	(+3)
	materialsVec.push_back(Material(vec3(0.0f, 0.0f, 0.0f), 0.0f, vec3(1, 1, 1), INFINITY, .9f, 5.8f));	//mirror		(+4)
	materialsVec[matIdx + 4].flags |= MAT_FLAG_PURE_REFLECTION;
	materialsVec.push_back(Material(vec3(1.0f, 0.6f, 1.0f)));			//violet light

	const float offset = wallSize / 2;

	const mat4 scaleToWall = scale(vec3(wallSize, wallSize, wallSize));

	//floor
	mat4 trans = translate(vec3(0, -offset, -offset)) *
		rotate(-(glm::mediump_float)90, vec3(1, 0, 0)) *
		scaleToWall;
	addRectangularModel(trans, matIdx);

	//ceiling
	trans = translate(vec3(0, offset, -offset)) *
		rotate((glm::mediump_float)90, vec3(1, 0, 0)) *
		scaleToWall;
	addRectangularModel(trans, matIdx + 4);

	//left wall
	trans = translate(vec3(-offset + .2 * offset, 0, -offset)) *
		rotate((glm::mediump_float)88, vec3(0, 1, 0)) *
		scaleToWall;
	addRectangularModel(trans, matIdx + 4);

	//right wall
	trans = translate(vec3(offset, 0, -offset)) *
		rotate((glm::mediump_float) - 90, vec3(0, 1, 0)) *
		scaleToWall;
	addRectangularModel(trans, matIdx + 4);

	//back wall
	trans = translate(vec3(0, 0, -wallSize)) *
		//		rotate((glm::mediump_float)90, vec3(1, 0, 0)) *
		scaleToWall;
	addRectangularModel(trans, matIdx);

	//front wall s
	trans = translate(vec3(0, 0, 0)) *
		rotate((glm::mediump_float)180, vec3(0, 1, 0)) *
		scaleToWall;
	addRectangularModel(trans, matIdx);

	//light
	float power = 400;
	trans = translate(vec3(0, offset - 0.01f, -offset)) *
		rotate((glm::mediump_float) 90, vec3(1, 0, 0)) *
		scale(vec3(2.5f, 2.5f, 2.5f));
	addAreaLight(trans, matIdx + 3, vec3(power / 4, power, power));


	trans = translate(vec3(0, -offset + 0.01f, -offset)) *
		rotate((glm::mediump_float) -90, vec3(1, 0, 0)) *
		scale(vec3(1.5f, 1.5f, 1.5f));
	addAreaLight(trans, matIdx + 5, vec3(power / 3, 0, power / 3));
}
开发者ID:steveschwarcz,项目名称:Cuda-Path-Tracer-SS,代码行数:75,代码来源:Scene.cpp

示例4: InitializeGraph

bool SceneGraph::InitializeGraph()
{
	// Create objects
	// Add the objects into the actor map	
	// Once an object is in the SceneGraph, object destruction is responsibility of the SceneGraph
	using AntiMatter::AppLog;
	using std::string;
	using std::vector;
	using glm::mat4;
	using glm::vec3;
	using glm::translate;
	using glm::rotate;

	// just calling to test the WavefrontObj parser
	// WavefrontObj j( g_Cfg.AssetsDir() + string("obj\\house\\house.obj") );
		

	// Initialize the SceneLights collection (lights need access to the SceneGraph in order to initialize)
	// because of this, light initialization can't be done through plain old RAII
	if( ! m_lights.Initialize(this) )
	{
		AppLog::Ref().LogMsg("SceneGraph lights failed to initialize");
		return false;
	}


	// add lights to the scene graph
	typedef vector<Light*>::const_iterator CItr;
	const vector<Light*> lights = m_lights.Lights();

	for( CItr n = lights.begin(); n != lights.end(); n ++ )
	{
		Light* pLight = (*n);
		m_map.insert( ActorIdPair( pLight->Id(), pLight ) );
	}

	mat4 tr;
	mat4 mW(1.0);


	// Terrain
	Terrain* pTerrain = new (std::nothrow) Terrain(
		this, 
		&m_RootNode, 
		string("terrain"), 
		g_Cfg.AssetsDir() + string("heightfield4.bmp"),			// height map
		g_Cfg.AssetsDir() + string("grassC.jpg"),				// texture map (1 of n ?)
		g_Cfg.AssetsDir() + string("256-circle-alphamap.bmp"),	// alphamap
		128,128,
		4.0f, 4.0f, 0.1f 
	);

	if( ! pTerrain || !  pTerrain->Initialized() )
	{
		AppLog::Ref().LogMsg("SceneGraph failed to initialize Terrain");
		return false;
	}

	m_map.insert( ActorIdPair( pTerrain->Id(), pTerrain) );
	tr = translate( mat4(1.0), vec3(0, -275, 0) );
	pTerrain->GetNodeData().W()	*= tr;	
	
	
	// Globe
	Globe* pGlobe = new (std::nothrow) Globe(  
		this, 
		&m_RootNode, 
		std::string("globe"), 
		350.0f, 30, 30, 
		string(""), 
		glm::vec4(1.0, 1.0, 1.0, 0.8) 
	);

	// position the globe
	if( ! pGlobe || ! pGlobe->Initialized() )
	{
		AppLog::Ref().LogMsg("SceneGraph failed to intialize the Globe");
		return false;
	}
		
	tr = translate( glm::mat4(1.0), vec3(0, 0, 0) );
	pGlobe->GetNodeData().W() *= tr;
	m_map.insert( ActorIdPair( pGlobe->Id(), pGlobe) );



	// snow
	Snow* pSnow = new (std::nothrow) Snow(
		this,
		&m_RootNode,
		pGlobe,
		string("snowfall"),
		g_Cfg.SnowCfg()
	);

	if( ! pSnow || ! pSnow->Initialized() )
	{
		AppLog::Ref().LogMsg("SceneGraph failed to allocate heap for snow");
		return false;
	}
//.........这里部分代码省略.........
开发者ID:gwgrisk,项目名称:msc-hull-snowglobe,代码行数:101,代码来源:SceneGraph.cpp


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