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
bool (*functions[])() =
{
Function0,
Function1,
Function2,
};
bool LogicalAnd()
{
for (auto f : functions)
string rpAsset = "";
if (GraphicsSettings.renderPipelineAsset != null)
rpAsset = GraphicsSettings.renderPipelineAsset.GetType().Name;
if (rpAsset.Equals("HDRenderPipelineAsset"))
renderPipeline = RenderPipeline.HDRP;
else if (rpAsset.Equals("UniversalRenderPipelineAsset"))
renderPipeline = RenderPipeline.URP;
else
renderPipeline = RenderPipeline.BuiltIn;
@TheAllenChou
TheAllenChou / SdfQuantize.cginc
Last active July 6, 2020 14:33
Smooth Quantization of Signed Distance Field Sample Points
float3 quantize(float3 p, float cellSize, float strength)
{
float3 r = p / cellSize;
float3 f = floor(r);
float3 t = r - f;
return (f + smoothstep(0.0f, 1.0f, strength * (t - 0.5f) + 0.5f)) * cellSize;
}
Vector3 inputVec = Vector3.zero;
if (Input.GetKey(KeyCode.UpArrow))
inputVec += Vector3.up;
if (Input.GetKey(KeyCode.DownArrow))
inputVec += Vector3.down;
if (Input.GetKey(KeyCode.LeftArrow))
inputVec += Vector3.left;
@TheAllenChou
TheAllenChou / Seek.cs
Last active August 26, 2019 10:15
Value Seeking
// example of how to move a current value towards a target value at a constant speed
// without going over the target value
// formula is the same for vectors of any dimension
Vector3 Seek(Vector3 currentValue, Vector3 targetValue, float maxSpeed, float dt)
{
// delta/difference from current value to target value
Vector3 delta = targetValue - currentValue;
// don't take the square root of magnitude yet
// so we can potentially early out on degenerate case of currenvValue ~= targetValue
@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;
}
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;
(export-weapon-damage-table
(pistol :damage 10)
(shotgun :damage 50)
)
var table = new LookupTable();
var pistol =
new WeaponEntry
(
name = "pistol",
damage = 10
);
var shotgun =
new WeaponEntry
(
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;