Skip to content

Instantly share code, notes, and snippets.

View mattatz's full-sized avatar
👁️‍🗨️
Yes

mattatz mattatz

👁️‍🗨️
Yes
View GitHub Profile
@mattatz
mattatz / binomial.rs
Created April 18, 2024 02:41
A memoized binomial coefficient calculator for Rust
use std::collections::HashMap;
use nalgebra::RealField;
/// Returns the binomial coefficient of `n` and `k`.
#[allow(unused)]
pub fn binomial(n: usize, k: usize) -> f64 {
if k == 0 || k == n {
return 1.;
} else if n == 0 || k > n {
@mattatz
mattatz / spherical_coordinate_system.rs
Last active January 25, 2024 01:05
A small program to calculate the area of a triangle on a spherical surface using spherical geometry.
use nalgebra::Point3;
use std::f64::consts::PI;
/// Reference: http://sshmathgeom.private.coocan.jp/geometryonsphere.pdf
pub struct SphericalCoordinate {
pub theta: f64, // latitude: -half pi <= theta <= half pi
pub phi: f64, // longitude: -2pi <= phi <= 2pi
}
@mattatz
mattatz / THREE.GradientCubeTexture.js
Last active January 26, 2021 15:43
Vertical linear gradient colored cube texture in three.js
// Vertical gradient cube texture
export default class GradientCubeTexture extends THREE.CubeTexture {
constructor(bottom = '#4488aa', top = '#aaddff', size = 32) {
super()
// px, nx, py, ny, pz, nz
this.images[0] = this.create(top, bottom, size)
this.images[1] = this.create(top, bottom, size)
@mattatz
mattatz / SlackWebhook.cs
Created November 28, 2019 08:38
Post a message to a slack channel in Unity by webhook.
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
[System.Serializable]
public class SlackAttachment
{
public string title;
public string text;
@mattatz
mattatz / Matrix.hlsl
Last active May 10, 2024 04:39
Matrix operations for HLSL
#ifndef __MATRIX_INCLUDED__
#define __MATRIX_INCLUDED__
#define IDENTITY_MATRIX float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
float4x4 inverse(float4x4 m) {
float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0], n14 = m[3][0];
float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1], n24 = m[3][1];
float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2], n34 = m[3][2];
float n41 = m[0][3], n42 = m[1][3], n43 = m[2][3], n44 = m[3][3];
@mattatz
mattatz / Quaternion.hlsl
Last active May 6, 2024 17:10
Quaternion structure for HLSL
#ifndef __QUATERNION_INCLUDED__
#define __QUATERNION_INCLUDED__
#define QUATERNION_IDENTITY float4(0, 0, 0, 1)
#ifndef PI
#define PI 3.14159265359f
#endif
// Quaternion multiplication
@mattatz
mattatz / Easing.hlsl
Created January 19, 2018 04:37
Easing functions for HLSL.
#ifndef _EASING_INCLUDED_
#define _EASING_INCLUDED_
float ease_linear(float x) {
return x;
}
float ease_in_quad(float x) {
float t = x; float b = 0; float c = 1; float d = 1;
return c*(t/=d)*t + b;
@mattatz
mattatz / mat4.h
Last active January 21, 2022 14:30
Column major 4x4 matrix struct for CUDA.
// Column major 4x4 matrix for CUDA.
// Sources:
// - https://github.com/JAGJ10/Snow/blob/master/Snow/matrix.h
// - https://github.com/mrdoob/three.js/blob/master/src/math/Matrix4.js
#pragma once
#include "cuda_runtime.h"
struct mat4 {
@mattatz
mattatz / ComponentUtil.cs
Last active April 18, 2024 03:04
CopyComponent by Script for Unity
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace Utils
{
@mattatz
mattatz / Rand.cs
Created January 11, 2017 04:03
Random class for Unity.
using Random = System.Random;
using UnityEngine;
namespace mattatz {
public class Rand {
Random rnd;