Skip to content

Instantly share code, notes, and snippets.

@gszauer
Created June 4, 2013 18:20
Show Gist options
  • Save gszauer/5708216 to your computer and use it in GitHub Desktop.
Save gszauer/5708216 to your computer and use it in GitHub Desktop.
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