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


C# CCPoint.Normalize方法代码示例

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

        }
开发者ID:xamarin,项目名称:mobile-samples,代码行数:10,代码来源:CollisionResponse.cs

示例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
开发者ID:KevinHeyer,项目名称:CocosSharp,代码行数:67,代码来源:CCApplication.cs

示例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;

		}
开发者ID:xamarin,项目名称:mobile-samples,代码行数:56,代码来源:Polygon.cs


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