Created
June 4, 2013 18:20
-
-
Save gszauer/5708216 to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
using System.Collections; | |
public class TangentDemo : MonoBehaviour { | |
//////////////////////////////////////////////////////////////////////////////////////////// | |
// In order to ortho-normalize a vector set, | |
// subtract up the projection of tangent onto the normal and / or binormal from the tangent | |
//////////////////////////////////////////////////////////////////////////////////////////// | |
void Start () { | |
Debug.Log("Up: " + Vector3.up); | |
Debug.Log("Right: " + Vector3.right); | |
Debug.Log("Forward: " + Vector3.forward); | |
Vector3 up = Vector3.up; | |
Vector3 right = Vector3.right; | |
Vector3 tangent = up + Vector3.forward; | |
Vector3.OrthoNormalize(ref up, ref tangent, ref right); | |
Debug.Log("Tangent: " + tangent); | |
Debug.Log("---------------------------------"); | |
up = Vector3.up; | |
right = Vector3.right; | |
tangent = up + Vector3.forward; | |
Vector3 accumulator = Vector3.zero; | |
accumulator += up * Vector3.Dot(tangent, up); | |
accumulator += right * Vector3.Dot(tangent, right); | |
tangent -= accumulator; | |
Debug.Log("Tangent: " + tangent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment