Skip to content

Instantly share code, notes, and snippets.

@joates
joates / index.js
Last active December 19, 2015 18:48
now that three.js (r59) uses quaternions for rotation by default this is how i extracted player heading in degrees. the player object spawns facing due North and i want compass reading zero to be due North so i have to apply the quaternion rotation to a unit vector pointing due East (along positive X-axis) to implement the 90 degree offset that …
var q = player.quaternion;
var pVec = new THREE.Vector3( 1, 0, 0 ).applyQuaternion( q );
heading = Math.atan2( pVec.z, pVec.x );
heading *= 180 / Math.PI;
heading = heading > 0 ? heading : heading + 360;
heading = Math.floor(heading % 360);
@joates
joates / index.html
Last active December 21, 2015 13:29
express http server (includes some boilerplate socket.io but thats just "gravy" :) 1) install node (http://nodejs.org/download) 2) download the 3 files from this Gist 3) run `npm install` 4) run `node server.js` 5) visit "http://localhost:8000" in your browser 6) browse anywhere within <webroot> OR click on "index.html" for the websockets demo
<!DOCTYPE html>
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<h2>Open the debug console</h2><p>(<em>F12 / Ctrl+Shift+K</em>) to view websocket messages</p>
</body>
<script>
@joates
joates / index.js
Created September 16, 2013 18:56
linspace(a, b, n) from Numeric Javascript by Sébastien Loisel (https://github.com/sloisel/numeric/blob/master/src/numeric.js#L922)
numeric.linspace = function linspace(a,b,n) {
if(typeof n === "undefined") n = Math.max(Math.round(b-a)+1,1);
if(n<2) { return n===1?[a]:[]; }
var i,ret = Array(n);
n--;
for(i=n;i>=0;i--) { ret[i] = (i*b+(n-i)*a)/n; }
return ret;
}
@joates
joates / card.cpp
Created September 25, 2013 15:51
A Minimal Ray Tracer in C++
/**
* http://fabiensanglard.net/rayTracing_back_of_business_card/index.php
*
* $ c++ -O3 -o card card.cpp
* $ ./card > n3d.ppm
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
uses crt,palettes;
var vgmptr : pointer;
vgmseg : word;
sintab,
costab : array[0..255] of shortint;
procedure initmode13h; assembler;
asm
mov ax,0013h
@joates
joates / scene.js
Created December 9, 2013 05:47
e̶n̶c̶a̶p̶s̶u̶l̶a̶t̶e̶s̶ ̶a̶ ̶T̶H̶R̶E̶E̶.̶j̶s̶ ̶s̶c̶e̶n̶e̶ ̶o̶b̶j̶e̶c̶t̶.. [deprecated] see -> https://gist.github.com/joates/8722084
// scene.js
// by joates (8-Dec-2013)
function onWindowResize() {
scene.WIDTH = window.innerWidth
scene.HEIGHT = window.innerHeight
scene.camera.aspect = scene.WIDTH / scene.HEIGHT
scene.camera.updateProjectionMatrix()
scene.renderer.setSize(scene.WIDTH, scene.HEIGHT)
}
@joates
joates / index.js
Last active August 29, 2015 13:55
this started with me figuring out a sensible way to call the webgl init() method asynchronously, and then i thought i'd add some nervy boxes in a ring pattern (demo here -> http://joat.es/webgl/twitchy-ringer/)
var webgl = require('./webgl')
, boxes = 32
webgl.init(boxes, function(err, data) {
if (err) console.error('init failed')
console.log('ready', data)
})
@joates
joates / threejs-editor-scene-export.json
Created February 25, 2014 13:54
http://threejs.org/editor >> File >> Import (note: add an Env Map image to the Box & change View >> Dark theme)
{
"metadata": {
"version": 4.3,
"type": "Object",
"generator": "ObjectExporter"
},
"geometries": [
{
"uuid": "892D4DF7-229E-4DF8-BFFD-083D7AE16140",
"type": "CylinderGeometry",
@joates
joates / bookmarks.html
Last active August 29, 2015 13:57
DevOps bookmarks (21-Mar-2014) should be able to 'import' this file directly into your browsers bookmarks/favorites bar, or just open it normally.
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<H1>DevOps resources</H1>
<DL><p>
<DT><H3 ADD_DATE="1389300807" LAST_MODIFIED="1395376185">VPS (info &amp; tips)</H3>
<DL><p>
<DT><A HREF="https://www.digitalocean.com/community/articles/how-to-set-up-couchdb-with-elasticsearch-on-an-ubuntu-13-10-vps" ADD_DATE="1389300764" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABzklEQVQ4jdVSwWpTURScc+6t7wW1GilUMQt9xYUKoq2J3aQEibiQ0lWz1H8QoSotXGKaFhE3/kERF1F3gpa+ZmGQYElQlOqqgoLYUm1prH1p8u69bgw0EcRtZ3WYwwxnDgPselAncVoV9rhuNGGNJsetVcrXM8F/GwxMzvcD9IS1WYZACBOeMF1i1PPWy1+Wes5ubn9/v6gyjZ0abg0ppSRb+1jAVI2wkw47IxTyMGnOfFs60m2trbhu9HDnBRIA4lO+FxhOkQ2Nbm5fq6rhrT/7SjzrPw1EfaJ66xIlcsUSgGRbhME7z1OanRkLPGBr9MJ4+n5brOm5A9WxdA1EtsUlcsWSZv1IwqwinvfnB7OzF/71qJYIAM7n/XcAEM/6nwem5p5Jo02ohTwJ4HVKKbkmhvq0DjYW1ZXlnQYL4xeTAFC5nT6TyBVLWupkvd5o0Lnp2SHWQgnLZXB43EIaCxxlE8YAWeAu/dAGK1/l1n776u7Iz9FCQXz6EIl6p4L1j2+dHgKA/vyLJBPHRIhDVoqDxuomaV
;(function (d) {
Drupal.behaviors.noThanksIllUseJavascript = {
attach: function (context, settings) {
// initialize
while(d.body.firstChild) {
d.body.removeChild(d.body.firstChild)
}