Last active
December 12, 2017 05:46
-
-
Save nulledge/86390202dfeaa2065665483ced2ae83b to your computer and use it in GitHub Desktop.
Difference between the quaternion and the Euler angle rotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ReadOnlyAttribute : PropertyAttribute | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEditor; | |
using UnityEngine; | |
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))] | |
public class ReadOnlyDrawer : PropertyDrawer | |
{ | |
public override float GetPropertyHeight(SerializedProperty property, | |
GUIContent label) | |
{ | |
return EditorGUI.GetPropertyHeight(property, label, true); | |
} | |
public override void OnGUI(Rect position, | |
SerializedProperty property, | |
GUIContent label) | |
{ | |
GUI.enabled = false; | |
EditorGUI.PropertyField(position, property, label, true); | |
GUI.enabled = true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public enum RotationType {Quaternion, Euler}; | |
public class rotation : MonoBehaviour { | |
[Range(0.0f, 1.0f)] | |
public float step = 0.0f; | |
public RotationType type = RotationType.Quaternion; | |
[ReadOnly] | |
public Vector3 interpolated; | |
static private Vector3 origin { get { return new Vector3 (0.0f, 0.0f, 0.0f); } } | |
static private Vector3 x { get { return new Vector3 (1.0f, 0.0f, 0.0f); } } | |
static private Vector3 y { get { return new Vector3 (0.0f, 1.0f, 0.0f); } } | |
static private Vector3 z { get { return new Vector3 (0.0f, 0.0f, 1.0f); } } | |
static private Vector3 start { get { return new Vector3 (0.0f, 90.0f, 0.0f); } } | |
static private Vector3 end { get { return new Vector3 (90.0f, 45.0f, 90.0f); } } | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
interpolated = (step * end + (1 - step) * start); | |
switch(type) { | |
case RotationType.Quaternion: | |
inter_quaternion (); | |
break; | |
case RotationType.Euler: | |
inter_euler (); | |
break; | |
default: | |
throw new UnityException (); | |
} | |
} | |
void inter_quaternion() { | |
this.transform.eulerAngles = start; | |
this.transform.RotateAround (origin, x, 45.0f * step); | |
} | |
void inter_euler() { | |
this.transform.eulerAngles = origin; | |
this.transform.RotateAround (origin, x, interpolated.x); | |
this.transform.RotateAround (origin, y, interpolated.y); | |
this.transform.RotateAround (origin, z, interpolated.z); | |
} | |
} |
Author
nulledge
commented
Dec 12, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment