Skip to content

Instantly share code, notes, and snippets.

@toxicFork
toxicFork / gist:7315788
Created November 5, 2013 08:47
Time elapsed
#define CLOCK_PRECISION (1E9)
struct timespec requestStart, requestEnd;
clock_gettime(CLOCK_REALTIME, &requestStart);
func(grid);
clock_gettime(CLOCK_REALTIME, &requestEnd);
// Calculate the time it took
double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
+ ( requestEnd.tv_nsec - requestStart.tv_nsec )
@toxicFork
toxicFork / Modification.cs
Created September 27, 2014 17:58
Modification disposable
public class Modification : IDisposable {
private readonly Object[] objects;
public Modification(string action, params Object[] objects) {
this.objects = objects;
EditorHelpers.RecordUndo(action, objects);
}
public void Dispose() {
foreach (Object o in objects) {
@toxicFork
toxicFork / TextureAtlasSlicer.cs
Last active November 24, 2019 08:28
TextureAtlasSlicer.cs
using System;
using System.Collections.Generic;
using System.Xml;
using UnityEditor;
using UnityEngine;
public class TextureAtlasSlicer : EditorWindow {
[MenuItem("CONTEXT/TextureImporter/Slice Sprite Using XML")]
public static void SliceUsingXML(MenuCommand command)
{
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class HighlightHelper {
private static readonly Type HierarchyWindowType;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class HighlightHelper
{
private static Type HierarchyWindowType;
@toxicFork
toxicFork / distanceToPlane.glsl
Last active August 29, 2015 14:17
Algorithm to get the distance of a point in the world to a plane in the world. Gist created for http://wp.me/p1tYzm-38
//http://mathworld.wolfram.com/Point-PlaneDistance.html
float distanceToPlane(float3 planePosition, float3 planeNormal, float3 pointInWorld)
{
//w = vector from plane to point
float3 w = - ( planePosition - pointInWorld );
return (
planeNormal.x * w.x +
planeNormal.y * w.y +
planeNormal.z * w.z
) / sqrt (
@toxicFork
toxicFork / pixel-to-world.cs
Created July 7, 2015 19:57
Pixel -> World coordinates | World -> Pixel coordinates
private static Vector2 WorldToPixelCoords(Vector3 projectedPoint, Sprite sprite, Transform transform)
{
var textureRect = sprite.textureRect;
var spriteBounds = sprite.bounds;
var localPoint = transform.InverseTransformPoint(projectedPoint);
localPoint.x = (localPoint.x - spriteBounds.min.x) / (spriteBounds.size.x);
localPoint.y = (localPoint.y - spriteBounds.min.y) / (spriteBounds.size.y);
@toxicFork
toxicFork / UpdateAllObjects.js
Created March 2, 2016 18:39
react-three-renderer module example
import Module from 'react-three-renderer/lib/Module';
import PropTypes from 'react/lib/ReactPropTypes';
import events from 'events';
const { EventEmitter } = events;
// or shim EventEmitter
class UpdateAllObjects extends Module {
constructor() {

Main render:

<React3/>
  <scene>
    {this.state.gameStarted ? <Game/> : <Title/>}
  </scene>
<React3>