Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / vertex-rotation.shader
Created October 26, 2018 10:35
Vertex Rotations in Shader
// https://forum.unity.com/threads/how-to-compute-vertex-rotation.470676/
inline float3x3 xRotation3dRadians(float rad) {
float s = sin(rad);
float c = cos(rad);
return float3x3(
1, 0, 0,
0, c, s,
0, -s, c);
}
@unitycoder
unitycoder / QuadTreeTest.cs
Created November 1, 2018 10:07 — forked from DGoodayle/QuadTreeTest.cs
Quadtree in Unity
using UnityEngine;
using System.Collections;
public class QuadTreeTest : MonoBehaviour {
public class TestObject : IQuadTreeObject{
private Vector3 m_vPosition;
public TestObject(Vector3 position){
m_vPosition = position;
}
public Vector2 GetPosition(){
@unitycoder
unitycoder / 0-bit-cheatsheet.txt
Last active February 16, 2026 06:50
Working with Bits Bytes Cheat Sheet Binary Bitmask Bitwise ByteArray Extract Get
To combine two bytes into a single integer using bit shifting,
you can shift one of the bytes by 8 bits (which equals one byte)
//= BINRSHIFT(number, shift_value)
same as
= number/(2^shift_value)
same as
//=BINLSHIFT(number, shift_value)
@unitycoder
unitycoder / nodejs.txt
Last active June 27, 2020 16:12
Node.js Notes nodejs node Amazon
// command
npm install discord.io winston --save
// error
npm http GET https://registry.npmjs.org/winston npm ERR! Error: UNABLE_TO_GET_ISSUER_CERT_LOCALLY
// solution
npm config set strict-ssl=false
--------
@unitycoder
unitycoder / gist:5a6d14cbb7d5fd3c3984d8fa32370afa
Created November 5, 2018 04:24 — forked from renaudbedard/gist:7a90ec4a5a7359712202
Billboarding for Unity surface shaders
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
// get the camera basis vectors
float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22);
float3 up = float3(0, 1, 0); //normalize(UNITY_MATRIX_V._m10_m11_m12);
float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02);
// rotate to face camera
@unitycoder
unitycoder / FasterLineSegmentIntersection.cs
Last active September 2, 2024 07:31
Math Algorithms c# Calculate - 2D Line Intersection
// https://forum.unity.com/threads/line-intersection.17384/#post-4442284
bool FasterLineSegmentIntersection (Vector2 line1point1, Vector2 line1point2, Vector2 line2point1, Vector2 line2point2) {
Vector2 a = line1point2 - line1point1;
Vector2 b = line2point1 - line2point2;
Vector2 c = line1point1 - line2point1;
float alphaNumerator = b.y * c.x - b.x * c.y;
float betaNumerator = a.x * c.y - a.y * c.x;
float denominator = a.y * b.x - a.x * b.y;
@unitycoder
unitycoder / delete
Created November 7, 2018 02:09
delete
asdf
@unitycoder
unitycoder / multithreading.cs
Last active December 16, 2024 03:10
MultiThreading Start Thread with Parameters
// send parameter to thread method
Thread myThread;
ParameterizedThreadStart start = new ParameterizedThreadStart(YourMethod);
myThread = new Thread(start);
myThread.IsBackground = true;
myThread.Start(yourParams);
void YourMethod(System.Object a)
{
}
@unitycoder
unitycoder / getyoutube.php
Created November 28, 2018 17:13
Get Youtube Video URL using PHP
<?php
// https://forum.unity.com/threads/unity-5-6-1-video-player-url-youtube-support.483115/#post-3938095
//Returns the json data containing the individual url for individual video quality files
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
if(isset($_POST['url']) && $_POST['url'] != ""){
@unitycoder
unitycoder / writeablebitmap-getpixel.cs
Created December 2, 2018 19:48
Get Single Pixel Color from WriteableBitmap using BackBuffer Unsafe
WriteableBitmap canvasBitmap;
Image drawingImage;
..
// create texture
drawingImage = imgCanvas; // this is image component in wpf
RenderOptions.SetBitmapScalingMode(drawingImage, BitmapScalingMode.NearestNeighbor);
RenderOptions.SetEdgeMode(drawingImage, EdgeMode.Aliased);
w = (MainWindow)Application.Current.MainWindow;