本文整理汇总了C++中VPoint::Normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ VPoint::Normalize方法的具体用法?C++ VPoint::Normalize怎么用?C++ VPoint::Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VPoint
的用法示例。
在下文中一共展示了VPoint::Normalize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _ComputeFactors
void VRadialGradientPattern::_ComputeFactors()
{
//ensure that focal point lies inside exterior radius
//(otherwise gradient drawing is undeterminate)
if (fEndRadiusX != 0 && fEndRadiusY != 0 && (fStartPoint.x != fEndPoint.x || fStartPoint.y != fEndPoint.y))
{
//map focal to circle coordinate space with center at end point and radius equal to fEndRadiusX
GReal fx = fStartPoint.x-fEndPoint.x;
GReal fy = (fStartPoint.y-fEndPoint.y)*fEndRadiusX/fEndRadiusY;
if ((fx*fx+fy*fy) > fEndRadiusX*fEndRadiusX*(GReal) 0.9999*(GReal) 0.9999) //radius*0.9999 in order to avoid math discrepancy errors
{
//set focal to intersection with circle
GReal angle = atan2(fy,fx);
fy = sin(angle)*fEndRadiusX*(GReal) 0.9999;
fx = cos(angle)*fEndRadiusX*(GReal) 0.9999;
//map focal from circle coordinate space to user coordinate space
fStartPoint.x = fx+fEndPoint.x;
fStartPoint.y = fy*fEndRadiusY/fEndRadiusX+fEndPoint.y;
}
}
//here end point and radius need to be adjusted for reflect and repeat wrapping modes
if (GetWrapMode() != ePatternWrapClamp)
{
VPoint startPoint = fStartPoint;
VPoint endPoint = fEndPoint;
//map radius and focal coordinates from ellipsoid coordinate space (user space) to circular coordinate space centered on end point
//(more easy to work with circular coordinate space)
GReal endRadius = xbox::Max( fEndRadiusX, fEndRadiusY);
if (startPoint != endPoint
&&
fEndRadiusX != fEndRadiusY
&&
fEndRadiusX != 0
&&
fEndRadiusY != 0)
{
VPoint focal = startPoint-endPoint;
if (fEndRadiusX >= fEndRadiusY)
focal.y *= fEndRadiusX/fEndRadiusY;
else
focal.x *= fEndRadiusY/fEndRadiusX;
startPoint = endPoint + focal;
}
//if focal is not centered and as radius is enlarged for tiling wrapping modes,
//we must modify center point to ensure ratio (dist focal to radius)/radius keep the same
//otherwise drawing will not be correct
if (startPoint != endPoint && endRadius != 0)
{
VPoint vFocalToCenter = endPoint-startPoint;
GReal distFocalToCenter = vFocalToCenter.GetLength();
if (distFocalToCenter > endRadius)
distFocalToCenter = endRadius;
GReal distFocalToRadius = endRadius-distFocalToCenter;
vFocalToCenter.Normalize();
endRadius *= kPATTERN_GRADIENT_TILE_MAX_COUNT;
endPoint += vFocalToCenter*(endRadius-distFocalToRadius*kPATTERN_GRADIENT_TILE_MAX_COUNT);
//ensure that focal still lies in exterior circle :
//because of math discrepancy errors (especially near end radius border) we need to check that to avoid Quartz2D artifacts
//map focal to circle coordinate space with center at new end point
GReal fx = startPoint.x-endPoint.x;
GReal fy = startPoint.y-endPoint.y;
while ((fx*fx+fy*fy) > endRadius*endRadius*(GReal) 0.9999*(GReal) 0.9999) //radius*0.9999 to deal with math discrepancy errors (value 0.9999 determined by experimentation)
endRadius *= (GReal) 1.01;
}
else
//focal is centered: only enlarge radius
endRadius *= kPATTERN_GRADIENT_TILE_MAX_COUNT;
//update tiling datas
fEndRadiusTiling = endRadius;
if (endPoint != fEndPoint)
{
//adjust new end point position (to take account ellipsoid shape)
if (fEndRadiusX >= fEndRadiusY)
{
GReal ratio = fEndRadiusY/fEndRadiusX;
startPoint -= endPoint;
//map new end point from circular coordinate space centered on last end point to user space
//(this will be new origin for circular coordinate space)
endPoint -= fEndPoint;
endPoint.y *= ratio;
fEndPointTiling = fEndPoint+endPoint;
#if VERSIONMAC
startPoint += fEndPointTiling; //keep start point in circular coordinate space whom origin is equal to end point
//(transform to user space is delayed to gradient transform)
//.........这里部分代码省略.........