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


C++ cVector::normalize方法代码示例

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


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

示例1: setViewpoint

void cCritterViewer::setViewpoint(cVector toviewer, cVector lookatpoint, 
	BOOL trytoseewholeworld)
{
//First do some default setup stuff
	_fieldofviewangle = cCritterViewer::STARTFIELDOFVIEWANGLE;
	setSpeed(0.0);
#ifndef THREEDVECTORS //not THREEDVECTORS means the 2D case.
	_attitude = cMatrix(cVector2(1.0, 0.0), cVector2(0.0, 1.0), _position);
#else //THREEDVECTORS
	_attitude = cMatrix(-cVector::ZAXIS, -cVector::XAXIS, cVector::YAXIS, cVector::ZEROVECTOR);
		/* To get a reasonable default orientation, we arrange the viewer axes so that:  
		viewer x axis = world -z axis, viewer y axis = world -x axis, viewer z axis = world y axis.
		We pick this orientation so that if the viewer moves "forward" (along its tangent vector)
		it moves towards the world.  (We correct the mismatch between the coordinate systems in the 
		cCritterViewer::loadViewMatrix method, which has a long comment about this.)
		 Note that we will adjust _position (fourth column) later in this  call
		 with a moveTo, also we may rotate the _attitude a bit. */
	if (!_perspective) //Ortho view, simply move up.
	{
		_proportionofworldtoshow = 1.0; //Show all of a flat world.
		moveTo(lookatpoint + cCritterViewer::ORTHOZOFFSET * cVector::ZAXIS); // Get above the world
		_maxspeed = _maxspeedstandard = 0.5 * cCritterViewer::ORTHOZOFFSET; //Mimic perspective case.
	}
	else //_perspective
	{
		if (toviewer.isPracticallyZero()) //Not usable, so pick a real direction.
			toviewer = cVector::ZAXIS; //Default is straight up.
		if (trytoseewholeworld) /* Treat toviewer as a direction, and back off in that direction
			enough to see the whole world */
		{
			toviewer.normalize(); //Make it a unit vector.
			_proportionofworldtoshow = cCritterViewer::PROPORTIONOFWORLDTOSHOW;
			//Trying to show all of a world when flying around it, often leaves too big a space around it.
			Real furthestcornerdistance = pgame()->border().maxDistanceToCorner(lookatpoint); 
			Real tanangle = tan(_fieldofviewangle/2.0); /* We work with half the fov in this calculation, 
				the tanangle will be the ratio of visible distance to distance above the world,
				that is, tanangle = dr/dz, where
				Our dr is _proportionofworldtoshow * furthestcornerdistance, and
				our dz is the unknown seeallz height we need to back off to. 
				Swap tangangle and dz to get the next formula. */
			ASSERT(tanangle);
			Real seeallz = _proportionofworldtoshow * furthestcornerdistance / tanangle; 
			moveTo(lookatpoint + seeallz * toviewer);
		}
		else /*Not trytoseewholeworld.  In this case we don't normalize toviewer, instead	
			we treat it as a displacment from the lookatpoint. */
			moveTo(lookatpoint + toviewer);
		lookAt(lookatpoint);
		_maxspeed = _maxspeedstandard = 0.5 * (position()-lookatpoint).magnitude(); 
			/* Define the speed like this so it typically takes two seconds (1/0.5)
			to fly in to lookatpoint. */
		_lastgoodplayeroffset = position() - pgame()->pplayer()->position();
	}
#endif //THREEDVECTORS case
}
开发者ID:jstty,项目名称:OlderProjects,代码行数:55,代码来源:critterviewer.cpp


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