Skip to content

Instantly share code, notes, and snippets.

View clavis-magna's full-sized avatar

andrew burrell clavis-magna

View GitHub Profile
@clavis-magna
clavis-magna / objectRotation.js
Created November 24, 2012 04:36
local and global rotation functions for THREE.js objects updated for recent revisions of THREE.js
//following two rotation functions are updated versions of code from: https://github.com/mrdoob/three.js/issues/1219
//updated to work in latest versions (r52 tested) of THREE.js
// Rotate an object around an axis in object space
var rotationMatrix
function rotateAroundObjectAxis( object, axis, radians ) {
rotationMatrix = new THREE.Matrix4();
rotationMatrix.makeRotationAxis( axis.normalize(), radians );
object.matrix.multiplySelf( rotationMatrix ); // post-multiply
object.rotation.setEulerFromRotationMatrix(object.matrix, object.order);
@clavis-magna
clavis-magna / gist:4143073
Created November 25, 2012 10:49
Find World Vector3 from Local Vector3 of rotated object (for example, to cast a ray forward of a moving and rotating object)
var X_AXIS = new THREE.Vector3(1,0,0); //arbitrary vector local to object
var focusVector = new THREE.Vector3();
var localRot = new THREE.Quaternion();
//convert local rotation from Euler to Quaternion and store it in localRot
localRot.setFromEuler(object.mesh.rotation);
//multiply to quat by the vector we want to cast the ray towards (locally to the casting object)
//store resulting vector in focusVector
localRot.multiplyVector3(X_AXIS, focusVector);
@clavis-magna
clavis-magna / gist:7608948
Created November 23, 2013 00:01
bouncing ball
float x = 100;
float y = 100;
float xSpeed = 1;
float ySpeed = 3.3;
void setup(){
size(200,200);
smooth();
background(255);
}
@clavis-magna
clavis-magna / gist:7609688
Created November 23, 2013 01:37
move with keys
int x = 100;
int y = 100;
color circleColour = color(0,0,0);
void setup(){
size(200,200);
noStroke();
}
@clavis-magna
clavis-magna / gist:14863a3af4f5d9a50e72
Created October 12, 2014 06:29
zero gravity oculus rift character controller with arduino input
// attach this script to the OVRCameraController prefabs parent object
// add a rigid body to the OVRCameraController prefabs parent object
// turn gavity off on the rigidbody
// !! requires purchase of Uniduino from the asset store;
using UnityEngine;
using System.Collections;
using Uniduino;
@clavis-magna
clavis-magna / gist:42fe43e5f7ef0291596b
Last active August 29, 2015 14:18
draw a raindrop shape in processing
void setup(){
size(500,500);
}
void draw(){
//draw a drop at 120, 120 size 8
drawRaindrop(120,120,8);
}
//draw raindrop x = x position, y = y positiom, size = size
@clavis-magna
clavis-magna / gist:227548db757902ca6056
Created April 16, 2015 00:21
processing test colour under the mouse
void setup() {
size(500, 500);
background(255, 0, 0);
}
void draw() {
background(255, 0, 0);
fill(0, 0, 255);
ellipse(250, 250, 50, 50);
color myColor = get(mouseX, mouseY);
@clavis-magna
clavis-magna / gist:89262a77c48e4424c273
Last active August 29, 2015 14:19
basic audio trigger using minim
import ddf.minim.*;
Minim minim;
AudioSample skid;
void setup()
{
size(512, 200);
minim = new Minim(this);
@clavis-magna
clavis-magna / gist:71c4b056502687899a5a
Created May 12, 2015 00:31
change color of screen based on mouse click
//tests if mouse button is pressed and where the mouse is on the screen
//changes background color accordingly
void setup(){
size(500,500);
background(255,0,0);
}
void draw(){
//top left quater of screen && mouse pressed
@clavis-magna
clavis-magna / gist:a7f204fdf2aafe3feb9e
Created May 12, 2015 00:32
processing bouncing ball
int xPos = 0;
int speed = 4;
void setup(){
size(300,300);
}
void draw(){
background(150,150,150);