Last active
December 24, 2019 16:14
-
-
Save xCyborg/f833b0323ae15559f4126abd663ec907 to your computer and use it in GitHub Desktop.
Some Math Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/// <summary> | |
/// Cg shading language functions written in C# | |
/// </summary> | |
public static class CgFunctions : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
print(Ceil(7.32f)); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
/// <summary> | |
/// Clamp value between [0, 1] | |
/// </summary> | |
/// <param name="x">value to clamp</param> | |
/// <returns></returns> | |
float Saturate(float x) | |
{ | |
if (x <= 0f) return 0; | |
else if (x >= 1f) return 1; | |
else return x; | |
} | |
public float Abs(float x) | |
{ | |
if (x >= 0f) return x; | |
else return -x; | |
} | |
public int Ceil(float x) | |
{ | |
int a = (int)x; | |
if ((float)a != x) | |
return (int)x + 1; | |
return (int)x; | |
} | |
public float Clamp(float x, float a, float b) | |
{ | |
if (x < a) return a; | |
else if (x > b) return b; | |
else return x; | |
} | |
public bool All(float[] x) | |
{ | |
foreach (float i in x) | |
{ | |
if (i == 0f) return false; | |
} | |
return true; | |
} | |
public bool Any(float[] x) | |
{ | |
foreach (float i in x) | |
{ | |
if (i != 0f) return true; | |
} | |
return false; | |
} | |
public float Cos(float x) | |
{ | |
return 0f; // placeholder | |
} | |
public float Sin(float x) | |
{ | |
return 0f; // placeholder | |
} | |
public float Tan(float x) | |
{ | |
return 0f; // placeholder | |
} | |
public float Acos(float x) | |
{ | |
return 0f; // placeholder | |
} | |
public float Asin(float x) | |
{ | |
return 0f; // placeholder | |
} | |
public float Atan(float x) | |
{ | |
return 0f; // placeholder | |
} | |
public float Atan2(float x, float y) | |
{ | |
return 0f; // placeholder | |
} | |
public float Cosh(float x) | |
{ | |
return 0f; // placeholder | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment