本文整理汇总了C#中CCPoint.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# CCPoint.Normalize方法的具体用法?C# CCPoint.Normalize怎么用?C# CCPoint.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCPoint
的用法示例。
在下文中一共展示了CCPoint.Normalize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Reflect
private static CCPoint Reflect(CCPoint vectorToReflect, CCPoint surfaceToReflectOn)
{
surfaceToReflectOn.Normalize();
CCPoint projected = surfaceToReflectOn * CCPoint.Dot(vectorToReflect, surfaceToReflectOn);
return -(vectorToReflect - projected) + projected;
}
示例2: ProcessGamePad
//.........这里部分代码省略.........
}
if (caps.HasRightShoulderButton)
{
rightShoulder = (gps.Buttons.RightShoulder == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
}
gamePadButton.Back = back;
gamePadButton.Start = start;
gamePadButton.System = system;
gamePadButton.A = a;
gamePadButton.B = b;
gamePadButton.X = x;
gamePadButton.Y = y;
gamePadButton.LeftShoulder = leftShoulder;
gamePadButton.RightShoulder = rightShoulder;
gamePadButton.Player = (CCPlayerIndex)player;
dispatcher.DispatchEvent(gamePadButton);
}
// Process the game sticks
if ((caps.HasLeftXThumbStick ||
caps.HasLeftYThumbStick ||
caps.HasRightXThumbStick ||
caps.HasRightYThumbStick ||
caps.HasLeftStickButton ||
caps.HasRightStickButton))
{
CCPoint vecLeft;
if (caps.HasLeftXThumbStick || caps.HasLeftYThumbStick)
{
vecLeft = new CCPoint(gps.ThumbSticks.Left);
vecLeft.Normalize();
}
else
{
vecLeft = CCPoint.Zero;
}
CCPoint vecRight;
if (caps.HasRightXThumbStick || caps.HasRightYThumbStick)
{
vecRight = new CCPoint(gps.ThumbSticks.Right);
vecRight.Normalize();
}
else
{
vecRight = CCPoint.Zero;
}
var left = new CCGameStickStatus();
left.Direction = vecLeft;
left.Magnitude = ((caps.HasLeftXThumbStick || caps.HasLeftYThumbStick) ? gps.ThumbSticks.Left.Length() : 0f);
left.IsDown = ((caps.HasLeftStickButton) ? gps.IsButtonDown(Buttons.LeftStick) : false);
var right = new CCGameStickStatus();
right.Direction = vecRight;
right.Magnitude = ((caps.HasRightXThumbStick || caps.HasRightYThumbStick) ? gps.ThumbSticks.Right.Length() : 0f);
right.IsDown = ((caps.HasLeftStickButton) ? gps.IsButtonDown(Buttons.RightStick) : false);
gamePadStick.Left = left;
gamePadStick.Right = right;
gamePadStick.Player = (CCPlayerIndex)player;
dispatcher.DispatchEvent(gamePadStick);
}
// Process the game triggers
示例3: GetNormalClosestTo
public CCPoint GetNormalClosestTo(CCPoint point, out float distance)
{
// We need the point before to potentially calculate the normal
int pointBefore;
var fromCircleToThis = VectorFrom(point.X, point.Y, absolutePoints, out pointBefore);
// The fromCircleToThis will be less than circle.Radius units in length.
// However much less it is is how far the objects should be moved.
distance = fromCircleToThis.Length;
double amountToMoveOnX;
double amountToMoveOnY;
// If length is equal to 0,
// that means that the circle
// falls directly on the polygon's
// edge. When this occurrs, the direction
// to move is unknown. So we need to find the
// normal of the surface to know the direction to
// move. To get the normal we'll first look at the
// point before on the polygon, and figure out the normal
// from that
if (distance == 0)
{
var direction = absolutePoints[pointBefore + 1] - absolutePoints[pointBefore];
// now rotate it 90 degrees:
direction = new CCPoint(-direction.Y, direction.X);
// We need to move the point along the normal a little bit to see if the normal
// is pointing inside or out.
if (!IsPointInside(point.X + direction.X * .01f, point.Y + direction.Y * .01f))
{
direction.X = -direction.X;
direction.Y = -direction.Y;
}
direction.Normalize();
fromCircleToThis.X = direction.X;
fromCircleToThis.Y = direction.Y;
}
else
{
// normalize and invert:
fromCircleToThis /= -fromCircleToThis.Length ;
fromCircleToThis.Normalize ();
}
return fromCircleToThis;
}