Skip to content

Instantly share code, notes, and snippets.

View davidfoster's full-sized avatar

David Foster davidfoster

View GitHub Profile
@davidfoster
davidfoster / AsmdefDebug.cs
Created January 14, 2019 16:08 — forked from filod/AsmdefDebug.cs
Find out what assemblies are being built and how long each takes. Updated to only build for Editor, and to include total time in first line of log output.
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEngine;
/// <summary>
@davidfoster
davidfoster / Understanding Quaternions Programmatically.cs
Last active March 5, 2024 14:23
Understanding Quaternions Programmatically
// deconstruct our rotation into angle/axis formation.
float rotationAngle;
Vector3 rotationAxis;
transform.rotation.ToAngleAxis(out rotationAngle, out rotationAxis);
// construct a new rotation from axis and angle.
// Qv,θ = |v * sin(θ/2), cos(θ/2)|, where v = axis, θ = angle in radians.
float sinThetaOver2 = Mathf.Sin((rotationAngle * Mathf.Deg2Rad) / 2f);
float cosThetaOver2 = Mathf.Cos((rotationAngle * Mathf.Deg2Rad) / 2f);
Quaternion newRotation = new Quaternion(
@davidfoster
davidfoster / KalmanFilterFloat.cs
Last active November 25, 2024 20:14
Simple Kalman filtering in Unity.
using System.Collections.Generic;
/// <summary>A Kalman filter implementation for <c>float</c> values.</summary>
public class KalmanFilterFloat {
//-----------------------------------------------------------------------------------------
// Constants:
//-----------------------------------------------------------------------------------------
public const float DEFAULT_Q = 0.000001f;
public static class QuaternionExtensions {
//-----------------------------------------------------------------------------------------
// Public Methods:
//-----------------------------------------------------------------------------------------
/// <summary>Returns a <c>Quaternion</c> with the same orientation but with a magnitude of 1.</summary>
public static Quaternion Normalise(this Quaternion self) {
// work out the magnitude, and if it's too small, return identity.
using UnityEngine;
public static class QuaternionExtensions {
//-----------------------------------------------------------------------------------------
// Public Methods:
//-----------------------------------------------------------------------------------------
/// <summary>Returns a <c>Vector3</c> angular velocity representation of this <c>Quaternion</c>.</summary>
public static Vector3 ToAngularVelocity(this Quaternion self) {
@davidfoster
davidfoster / GpuDetection.cs
Last active May 22, 2020 05:14
GPU Detection and Auto Quality Designation in Unity
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
[InitializeOnLoad]
#endif