• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# UnityEngine.Quaternion类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UnityEngine.Quaternion的典型用法代码示例。如果您正苦于以下问题:C# Quaternion类的具体用法?C# Quaternion怎么用?C# Quaternion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Quaternion类属于UnityEngine命名空间,在下文中一共展示了Quaternion类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Quat

 public Quat(Quaternion _quat)
 {
     this.x = _quat.x;
     this.y = _quat.y;
     this.z = _quat.z;
     this.w = _quat.w;
 }
开发者ID:coconutinteractive,项目名称:shakedown,代码行数:7,代码来源:MySerializables.cs


示例2: Write

		public void Write(Quaternion quaternion)
		{
			Write(quaternion.x);
			Write(quaternion.y);
			Write(quaternion.z);
			Write(quaternion.w);
		}
开发者ID:Neproify,项目名称:ivmp,代码行数:7,代码来源:PlatformUnityExtras.cs


示例3: RotateTo

        // Rotate this target towards a position
        public void RotateTo(Vector3 position)
        {
            if (pivot == null) return;

            if (pivot != lastPivot) {
                defaultLocalRotation = pivot.localRotation;
                lastPivot = pivot;
            }

            // Rotate to the default local rotation
            pivot.localRotation = defaultLocalRotation;

            // Twisting around the twist axis
            if (twistWeight > 0f) {
                Vector3 targetTangent = transform.position - pivot.position;
                Vector3 n = pivot.rotation * twistAxis;
                Vector3 normal = n;
                Vector3.OrthoNormalize(ref normal, ref targetTangent);

                normal = n;
                Vector3 direction = position - pivot.position;
                Vector3.OrthoNormalize(ref normal, ref direction);

                Quaternion q = QuaTools.FromToAroundAxis(targetTangent, direction, n);
                pivot.rotation = Quaternion.Lerp(Quaternion.identity, q, twistWeight) * pivot.rotation;
            }

            // Swinging freely
            if (swingWeight > 0f) {
                Quaternion s = Quaternion.FromToRotation(transform.position - pivot.position, position - pivot.position);
                pivot.rotation = Quaternion.Lerp(Quaternion.identity, s, swingWeight) * pivot.rotation;
            }
        }
开发者ID:nickgirardo,项目名称:KADAPT,代码行数:34,代码来源:InteractionTarget.cs


示例4: Update

        // Update is called once per frame
        void Update()
        {
            if (target.gameObject == null) {

                if (_statusIndicators.gameObject != null) {
                    _statusIndicators.SetDirectors ();
                    Destroy (this.gameObject);
                }
                return;
            }

            _direction = target.transform.position - transform.position;
            //_direction.z = 0f;

            _lookRotation = Quaternion.LookRotation (_direction, Vector3.back);

            Quaternion rotateTo = Quaternion.Slerp (transform.rotation, _lookRotation, RotationSpeed);
            rotateTo.x = 0f;
            rotateTo.y = 0f;
            this.transform.rotation = rotateTo;

            if (_direction.magnitude > minDist) {
                newAlpha = 1 - _direction.magnitude / maxDist;
            } else {
                newAlpha = _direction.magnitude / minDist - 0.4f;
            }

            image.color = new Color (image.color.r, image.color.g, image.color.b, newAlpha);
            //Debug.Log("Normalized magnitude: " + (int)_direction.magnitude + " New Alpa: " +newAlpha );
        }
开发者ID:Kundara,项目名称:project1,代码行数:31,代码来源:Director.cs


示例5: Write

 public void Write(Quaternion qua)
 {
     writer.Write(qua.x);
     writer.Write(qua.y);
     writer.Write(qua.z);
     writer.Write(qua.w);
 }
开发者ID:johncoffee,项目名称:gyro,代码行数:7,代码来源:PhoneController.cs


示例6: Start

        public void Start()
        {
            key = GameObject.Find("Key").gameObject;

            dupMarker = Quaternion.Euler(0, transform.rotation.eulerAngles.y + 45, 0);
            originMarker = Quaternion.Euler(0, originDoor.transform.rotation.eulerAngles.y - 45, 0);
        }
开发者ID:Dawnwoodgames,项目名称:LotsOfTowers,代码行数:7,代码来源:Door.cs


示例7: DrawCircle

		public static void DrawCircle(Vector3 origin, Quaternion rotation, float radius, int pieceCount, Color color)
		{
			if (3 > pieceCount)
			{
				return;
			}
			if (0 >= radius)
			{
				return;
			}

			float pieceAngle = 360.0f / pieceCount;

			Vector3 p0 = origin + rotation * Vector3.forward * radius;
			Vector3 p1 = p0;
			for (int i = 0; i < pieceCount-1; ++i)
			{
				var r = Quaternion.Euler(0, pieceAngle*(i+1), 0);
				Vector3 p2 = origin + rotation * (r * Vector3.forward * radius);
				Debug.DrawLine(p1, p2, color);

				p1 = p2;
			}
			Debug.DrawLine(p0, p1, color);
		}
开发者ID:siwenRen,项目名称:Wolf,代码行数:25,代码来源:DebugUtils.cs


示例8: PrepareGridRender

 public DrawGridParameters PrepareGridRender(Camera camera, Vector3 pivot, Quaternion rotation, float size, bool orthoMode, bool gridVisible)
 {
   bool flag1 = false;
   bool flag2 = false;
   bool flag3 = false;
   if (gridVisible)
   {
     if (orthoMode)
     {
       Vector3 vector3 = rotation * Vector3.forward;
       if ((double) Mathf.Abs(vector3.y) > 0.200000002980232)
         flag2 = true;
       else if (vector3 == Vector3.left || vector3 == Vector3.right)
         flag1 = true;
       else if (vector3 == Vector3.forward || vector3 == Vector3.back)
         flag3 = true;
     }
     else
       flag2 = true;
   }
   this.xGrid.target = flag1;
   this.yGrid.target = flag2;
   this.zGrid.target = flag3;
   DrawGridParameters drawGridParameters;
   drawGridParameters.pivot = pivot;
   drawGridParameters.color = (Color) SceneViewGrid.kViewGridColor;
   drawGridParameters.size = size;
   drawGridParameters.alphaX = this.xGrid.faded;
   drawGridParameters.alphaY = this.yGrid.faded;
   drawGridParameters.alphaZ = this.zGrid.faded;
   return drawGridParameters;
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:32,代码来源:SceneViewGrid.cs


示例9: UpdateGravity

        private void UpdateGravity()
        {
            _GravityDirection = GetGravityDirection();

            _Rigidbody.AddForce(_GravityDirection * Gravity, ForceMode2D.Force);
            _TargetRotation = Quaternion.Euler(new Vector3(0f, 0f, VectorUtils.GetAngle(Vector2.down, _GravityDirection)));
        }
开发者ID:chrismcmath,项目名称:LD33,代码行数:7,代码来源:HumanHitBehaviour.cs


示例10: LimitSwing

		/*
		 * Apply the swing rotation limits
		 * */
		public Quaternion LimitSwing(Quaternion rotation) {
			if (axis == Vector3.zero) return rotation; // Ignore with zero axes
			if (rotation == Quaternion.identity) return rotation; // Assuming initial rotation is in the reachable area
			
			// Get the rotation angle orthogonal to Axis
			Vector3 swingAxis = rotation * axis;
			float angle = GetOrthogonalAngle(swingAxis, secondaryAxis, axis);
			
			// Convert angle from 180 to 360 degrees representation
			float dot = Vector3.Dot(swingAxis, crossAxis);
			if (dot < 0) angle = 180 + (180 - angle);
			
			// Evaluate the limit for this angle
			float limit = spline.Evaluate(angle);
			
			// Get the limited swing axis
			Quaternion swingRotation = Quaternion.FromToRotation(axis, swingAxis);
			Quaternion limitedSwingRotation = Quaternion.RotateTowards(Quaternion.identity, swingRotation, limit);
			
			// Rotation from current(illegal) swing rotation to the limited(legal) swing rotation
			Quaternion toLimits = Quaternion.FromToRotation(swingAxis, limitedSwingRotation * axis);
			
			// Subtract the illegal rotation
			return toLimits * rotation;
		}
开发者ID:cupsster,项目名称:ExtremeBusiness,代码行数:28,代码来源:RotationLimitSpline.cs


示例11: LimitRotation

		/*
		 * Limits the rotation in the local space of this instance's Transform.
		 * */
		protected override Quaternion LimitRotation(Quaternion rotation) {		
			// Subtracting off-limits swing
			Quaternion swing = LimitSwing(rotation);
			
			// Apply twist limits
			return LimitTwist(swing, axis, secondaryAxis, twistLimit);
		}
开发者ID:cupsster,项目名称:ExtremeBusiness,代码行数:10,代码来源:RotationLimitSpline.cs


示例12: ObscuredQuaternion

		private ObscuredQuaternion(RawEncryptedQuaternion value)
		{
			currentCryptoKey = cryptoKey;
			hiddenValue = value;
			fakeValue = initialFakeValue;
			inited = true;
		}
开发者ID:predominant,项目名称:Treasure_Chest,代码行数:7,代码来源:ObscuredQuaternion.cs


示例13: DrawDoubleCircle

		public static void DrawDoubleCircle(Vector3 origin, Quaternion rotation, float radius1, float radius2, int pieceCount, Color color)
		{
			if (3 > pieceCount)
			{
				return;
			}
			if (0 >= radius1 || 0 >= radius2)
			{
				return;
			}
			
			float pieceAngle = 360.0f / pieceCount;
			
			Vector3 p0_1 = origin + rotation * Vector3.forward * radius1;
			Vector3 p0_2 = origin + rotation * Vector3.forward * radius2;
			Vector3 p1_1 = p0_1;
			Vector3 p1_2 = p0_2;
			for (int i = 0; i < pieceCount-1; ++i)
			{
				var r = Quaternion.Euler(0, pieceAngle*(i+1), 0);
				Vector3 p2_1 = origin + rotation * (r * Vector3.forward * radius1);
				Vector3 p2_2 = origin + rotation * (r * Vector3.forward * radius2);
				Debug.DrawLine(p1_1, p2_1, color);
				Debug.DrawLine(p1_2, p2_2, color);
				Debug.DrawLine(p2_1, p2_2, color);
				
				p1_1 = p2_1;
				p1_2 = p2_2;
			}
			Debug.DrawLine(p0_1, p1_1, color);
			Debug.DrawLine(p0_1, p0_2, color);
		}
开发者ID:siwenRen,项目名称:Wolf,代码行数:32,代码来源:DebugUtils.cs


示例14: UpdateRotation

 private void UpdateRotation(Quaternion currentRotation, float currentDegrees)
 {
     float closerDegress = GetCloserDegrees (currentDegrees);
     Vector3 newAngles = new Vector3 (currentRotation.eulerAngles.x,closerDegress,currentRotation.eulerAngles.z);
     Quaternion newRot = Quaternion.Euler (newAngles);
     myTransform.localRotation = Quaternion.Lerp (currentRotation,newRot,Time.deltaTime * currentSpeed);
 }
开发者ID:juliancruz87,项目名称:madbricks,代码行数:7,代码来源:SnapRotator.cs


示例15: ActivateObject

        public static GameObject ActivateObject(string objectName, Vector3 pos, Quaternion rotation)
        {
            ObjectPool pool = Instance.pools.FirstOrDefault(t => t.ObjectName == objectName);
            if (pool == null) return null;

            return pool.GetObject(pos, rotation);
        }
开发者ID:AkuKuylaars,项目名称:Blocklands,代码行数:7,代码来源:ObjectPoolManager.cs


示例16: GravityObject

		public GravityObject (Vector2 position, Quaternion rotation, ObjectTypes type)
			: this()
		{
			Position = position;
			Rotation = rotation;
			Type = type;
		}
开发者ID:SteinLabs,项目名称:Gravity,代码行数:7,代码来源:GravityObject.cs


示例17: Set

        protected virtual void Set(Part p, ReentrySimulation.SimCurves _simCurves)
        {
            Rigidbody rigidbody = p.rb;

            totalMass = rigidbody == null ? 0 : rigidbody.mass; // TODO : check if we need to use this or the one without the childMass
            shieldedFromAirstream = p.ShieldedFromAirstream;

            noDrag = rigidbody == null && !PhysicsGlobals.ApplyDragToNonPhysicsParts;
            hasLiftModule = p.hasLiftModule;
            bodyLiftMultiplier = p.bodyLiftMultiplier * PhysicsGlobals.BodyLiftMultiplier;

            simCurves = _simCurves;

            cubes = new DragCubeList();
            CopyDragCubesList(p.DragCubes, cubes);

            // Rotation to convert the vessel space vesselVelocity to the part space vesselVelocity
            vesselToPart = Quaternion.LookRotation(p.vessel.GetTransform().InverseTransformDirection(p.transform.forward), p.vessel.GetTransform().InverseTransformDirection(p.transform.up)).Inverse();

            //DragCubeMultiplier = PhysicsGlobals.DragCubeMultiplier;
            //DragMultiplier = PhysicsGlobals.DragMultiplier;


            //if (p.dragModel != Part.DragModel.CUBE)
            //    MechJebCore.print(p.name + " " + p.dragModel);

            //oPart = p;

        }
开发者ID:CliftonMarien,项目名称:MechJeb2,代码行数:29,代码来源:SimulatedPart.cs


示例18: LoadQuaternion

 public static Quaternion LoadQuaternion(JsonTextReader reader)
 {
     Quaternion rotation = new Quaternion(0, 0, 0, 0);
     if (reader == null) return rotation;
     string currVal = "";
     while (reader.Read())
     {
         if (reader.Value != null)
         {
             if (reader.TokenType == JsonToken.PropertyName) currVal = (string)reader.Value;
             else
             {
                 switch (currVal)
                 {
                     case "x": rotation.x = (float)(double)reader.Value; break;
                     case "y": rotation.y = (float)(double)reader.Value; break;
                     case "z": rotation.z = (float)(double)reader.Value; break;
                     case "w": rotation.w = (float)(double)reader.Value; break;
                     default: break;
                 }
             }
         }
         else if (reader.TokenType == JsonToken.EndObject) return rotation;
     }
     return rotation;
 }
开发者ID:amaximan,项目名称:educational,代码行数:26,代码来源:LoadManager.cs


示例19: LookRotation

        public void LookRotation(Transform character, Transform camera)
        {
            float yRot = CrossPlatformInputManager.GetAxis("Mouse X") * XSensitivity;
            float xRot = CrossPlatformInputManager.GetAxis("Mouse Y") * YSensitivity;

            if (yRot == 0)
                yRot = CrossPlatformInputManager.GetAxis("Right_X") * XSensitivity;

            if (xRot == 0)
                xRot = CrossPlatformInputManager.GetAxis("Right_Y") * YSensitivity;

            m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f);
            m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f);

            if(clampVerticalRotation)
                m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot);

            if(smooth)
            {
                character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot,
                    smoothTime * Time.deltaTime);
                camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot,
                    smoothTime * Time.deltaTime);
            }
            else
            {
                character.localRotation = m_CharacterTargetRot;
                camera.localRotation = m_CameraTargetRot;
            }

            UpdateCursorLock();
        }
开发者ID:Eibis,项目名称:GGJ2016,代码行数:32,代码来源:MouseLook.cs


示例20: DoSmoothLookAt

        void DoSmoothLookAt()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (go == null)
            {
                return;
            }

            var goTarget = targetObject.Value;
            if (goTarget == null && targetPosition.IsNone)
            {
                return;
            }

            // re-initialize if game object has changed

            if (previousGo != go)
            {
                lastRotation = go.transform.rotation;
                desiredRotation = lastRotation;
                previousGo = go;
            }

            // desired look at position

            Vector3 lookAtPos;
            if (goTarget != null)
            {
                lookAtPos = !targetPosition.IsNone ?
                    goTarget.transform.TransformPoint(targetPosition.Value) :
                    goTarget.transform.position;
            }
            else
            {
                lookAtPos = targetPosition.Value;
            }

            if (keepVertical.Value)
            {
                lookAtPos.y = go.transform.position.y;
            }

            // smooth look at

            var diff = lookAtPos - go.transform.position;
            if (diff.sqrMagnitude > 0)
            {
                desiredRotation = Quaternion.LookRotation(diff, upVector.IsNone ? Vector3.up : upVector.Value);
            }

            lastRotation = Quaternion.Slerp(lastRotation, desiredRotation, speed.Value * Time.deltaTime);
            go.transform.rotation = lastRotation;

            // debug line to target

            if (debug.Value)
            {
                Debug.DrawLine(go.transform.position, lookAtPos, Color.grey);
            }
        }
开发者ID:xxxred,项目名称:SoulOfSword,代码行数:60,代码来源:SmoothLookAt.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.Ray类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.ProceduralMaterial类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap