Skip to content

Instantly share code, notes, and snippets.

View TheAllenChou's full-sized avatar
🐰
Bunnies.

Ming-Lun "Allen" Chou TheAllenChou

🐰
Bunnies.
View GitHub Profile
@TheAllenChou
TheAllenChou / DrawFan.cs
Last active May 24, 2018 23:59
Draw A Fan Between Vectors a & b
void DrawFan(Vector3 o, Vector3 a, Vector3 b, uint numSegments)
{
a.Normalize();
b.Normalize();
Vector3 axis = Vector3.Cross(a, b);
float angle = Mathf.Acos(Vector3.Dot(a, b)) * Mathf.Rad2Deg;
float deltaAngle = angle / numSegments;
Quaternion q = Quaternion.AngleAxis(deltaAngle, axis);
int lastUpdateSector = 0;
void Update()
{
xRotation = Mathf.Repeat(xRotation, 360.0f);
int currentSector = (int) (xRotation / 45.0f);
if (currentSector != lastUpdate)
{
int n = lastUpdateSector - currentSector;
n = (n >= 0) ? n : -n;
if (n > 4)
public struct Aabb
{
public Vector2 Min;
public Vector2 Max;
public Aabb(Vector2 min, Vector2 max)
{
Min = min;
Max = max;
}
#define BEGIN_TEST_DEFINES static const int testIndexCounterBase = __COUNTER__
#define END_TEST_DEFINES static const int kNumTests = (__COUNTER__ - testIndexCounterBase - 1)
#define TEST_CASE(TestName) \
static const int k##TestName##Index = __COUNTER__ - testIndexCounterBase - 1; \
bool TestName##Func(TestArgs &args)
struct TestEval
{
int m_testIndex;
TEST_EVAL_LIST(myTests)
{
TEST_EVAL(MyTest0),
TEST_EVAL(MyTest1),
// ...
}
RunTests(myTests, ARRAY_COUNT(myTests), args, passBits);
List<GameObject> sprites;
List<GameObject> nameTextFields;
for (int i = 0, n = sprites.Length; i < n; ++i)
{
var s = sprites[i];
var ntf = nameTextFields[i];
int row = i / numCols;
int col = i % numCols;
var table = new LookupTable();
var pistol =
new WeaponEntry
(
name = "pistol",
damage = 10
);
var shotgun =
new WeaponEntry
(
(export-weapon-damage-table
(pistol :damage 10)
(shotgun :damage 50)
)
public static Vector3 ClampBend(Vector3 vector, Vector3 reference, float maxBendAngle)
{
float vectorLenSqr = vector.sqrMagnitude;
if (vectorLenSqr < MathUtil.Epsilon)
return vector;
float referenceLenSqr = reference.sqrMagnitude;
if (referenceLenSqr < MathUtil.Epsilon)
return vector;
@TheAllenChou
TheAllenChou / quaternion-axis-angle-vector.cs
Last active August 5, 2019 04:43
Conversion between Quaternions & Angular (Axis-Angle) Vectors
public static Vector3 GetAxis(Quaternion q)
{
Vector3 v = new Vector3(q.x, q.y, q.z);
float len = v.magnitude;
if (len < MathUtil.Epsilon)
return Vector3.left;
return v / len;
}