Created
January 17, 2011 00:44
-
-
Save axiomsofchoice/782318 to your computer and use it in GitHub Desktop.
Test OSC server for the Jmol Kinect #pmrhack Emits a test signal - useful if you don't actually have a Kinect
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
package com.foo; | |
import java.net.SocketException; | |
import java.net.UnknownHostException; | |
import javax.vecmath.Vector3f; | |
import com.illposed.osc.OSCMessage; | |
import com.illposed.osc.OSCPortOut; | |
/** | |
* | |
* Test OSC server for the Jmol Kinect #pmrhack Emits a test signal - useful if | |
* you don't actually have a Kinect | |
* | |
* @author axiomsofchoice | |
* | |
*/ | |
public class OSC_TestServer { | |
public static final int USER1_ID = 1 ; | |
public static final int USER2_ID = 2 ; | |
public static void main(final String[] args) throws UnknownHostException, | |
SocketException, InterruptedException { | |
OSCPortOut sender = new OSCPortOut(); | |
Object a[] = new Object[14]; | |
// These are the two users of the system | |
a[0] = OSC_TestServer.USER1_ID; | |
a[7] = OSC_TestServer.USER2_ID; | |
float user1_x0 = 0.0f; | |
float user1_y0 = 0.0f; | |
float user1_z0 = 0.0f; | |
float user1_x1 = 1.0f; | |
float user1_y1 = 0.0f; | |
float user1_z1 = 0.0f; | |
float user2_x0 = 0.0f; | |
float user2_y0 = 0.0f; | |
float user2_z0 = 0.0f; | |
float user2_x1 = 1.0f; | |
float user2_y1 = 0.0f; | |
float user2_z1 = 0.0f; | |
final int no_iter = 10000 ; | |
float l_omega = 0.0f ; | |
float d_omega = (float) Math.PI / 36.0f ; | |
for (int i = 0; i < no_iter; i++) { | |
// Move about a bit (user2) | |
// One hand stays at the origin | |
// whilst the other make a unit radius circle in the xy-plane | |
user2_x1 = (float) Math.cos(l_omega) ; | |
user2_y1 = (float) Math.sin(l_omega) ; | |
// Debug what angle this should be | |
// Compute a pure scalar rotation (for the bond angle) relative to | |
// a unit vector in the x-axis | |
Vector3f v = new Vector3f(user2_x1-user2_x0, user2_y1-user2_y0, user2_z1-user2_z0); | |
// Get angle in radians | |
float ax = v.angle(new Vector3f(1f, 0f, 0f)); | |
int inc_amount = (int)((360.0f * (l_omega - ax))/(2.0 * Math.PI)) ; | |
System.out.println("user2_x1: " + user2_x1); | |
System.out.println("user2_y1: " + user2_y1); | |
System.out.println("l_omega: " + l_omega); | |
System.out.println("d_omega: " + d_omega); | |
System.out.println("ax: " + ax); | |
System.out.println("inc_amount: " + inc_amount); | |
System.out.println(); | |
// Increment the actual angle | |
// Constrain the range of l_omega to be less than 2pi radians | |
l_omega = (l_omega + d_omega) % (float)(2.0f * Math.PI) ; | |
// Work out the sorts of co-ordinates a user would have used | |
a[1] = user1_x0; | |
a[2] = user1_y0; | |
a[3] = user1_z0; | |
a[4] = user1_x1; | |
a[5] = user1_y1; | |
a[6] = user1_z1; | |
a[8] = user2_x0; | |
a[9] = user2_y0; | |
a[10] = user2_z0; | |
a[11] = user2_x1; | |
a[12] = user2_y1; | |
a[13] = user2_z1; | |
// Construct the message | |
OSCMessage msg = new OSCMessage("/pmrhack", a); | |
// Send the message | |
try { | |
sender.send(msg); | |
} catch (Exception e) { | |
System.err.println("Couldn't send"); | |
} | |
// Equivalent of 0.03fps | |
Thread.sleep(1000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment