本文整理汇总了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
}