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


C# Vector4.SqrMagnitude方法代码示例

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


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

示例1: Update

	void Update ()
	{
		//	in VR mode, no mouse/gyro at all!
		if (UsingVr() )
			return;

		bool UseGyro = UseGyroOnMobile;
		{
			if (UseGyro)
				Input.gyro.enabled = true;
			UseGyro &= Input.gyro.enabled;
		}
	

		if (UseGyro) 
		{
			bool GyroValid = Input.gyro.enabled;
			{
				//	first usage of the attituide is all zeros, ignore this
				Vector4 Gyro4 =  new Vector4( Input.gyro.attitude.x, Input.gyro.attitude.y, Input.gyro.attitude.z, Input.gyro.attitude.w );
				GyroValid &= Gyro4.SqrMagnitude() > 0;
			}

			if ( GyroValid )
			{
				//	correction stolen from google cardboad SDK
				var att = Input.gyro.attitude;
				att = new Quaternion(att.x, att.y, -att.z, -att.w);
				att = Quaternion.Euler(0, 0, 0) * att;

				if ( mInitialGyro == null )
				{
					mInitialGyro = att;
				}

				transform.localRotation = Quaternion.Inverse(mInitialGyro.Value) * att;
			}
		}
		else if (axes == RotationAxes.MouseXAndY)
		{
			// Read the mouse input axis
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			
			rotationX = ClampAngle (rotationX, minimumX, maximumX);
			rotationY = ClampAngle (rotationY, minimumY, maximumY);
			
			Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
			Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right);
			
			transform.localRotation = originalRotation * xQuaternion * yQuaternion;
		}
		else if (axes == RotationAxes.MouseX)
		{
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationX = ClampAngle (rotationX, minimumX, maximumX);
			
			Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
			transform.localRotation = originalRotation * xQuaternion;
		}
		else
		{
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationY = ClampAngle (rotationY, minimumY, maximumY);
			
			Quaternion yQuaternion = Quaternion.AngleAxis (-rotationY, Vector3.right);
			transform.localRotation = originalRotation * yQuaternion;
		}
	}
开发者ID:NewChromantics,项目名称:Panopoly,代码行数:69,代码来源:MouseLook.cs


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