Permalink
Browse files

hackety hack rotation and camera angle

  • Loading branch information...
1 parent 6817668 commit f5b8a3463d9ffbf310f068253b4b286c9d96b82c @jonasb jonasb committed Apr 7, 2012
@@ -11,6 +11,7 @@
import java.net.InetAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.util.ArrayList;
class Communicator {
@@ -118,6 +119,8 @@ public void run() {
return;
}
+ float rotationCumulative = 0;
+ float cameraAngleCumulative = 0;
while (mRunning) {
byte kb = 0;
if (mNavigator.left)
@@ -130,13 +133,18 @@ public void run() {
kb |= 1 << 3;
//TODO reuse buffer/modify the data
ByteBuffer buffer = ByteBuffer.allocate(1024);
+ buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put("CTRL".getBytes());
buffer.put(mTrustServer);
buffer.put(mTrustClient);
buffer.put((byte) 0); //padding
buffer.put((byte) 0); //padding
- buffer.putInt(0); //mx
- buffer.putInt(0); //my
+
+ rotationCumulative += mNavigator.rotation * 20;
+ cameraAngleCumulative += mNavigator.cameraAngle * 10;
+
+ buffer.putInt(closestZero(rotationCumulative)); //mx
+ buffer.putInt(closestZero(cameraAngleCumulative)); //my
buffer.putInt((int) (mNavigator.moveX * 128)); //dx -1..1 -> -127..127
buffer.putInt((int) (mNavigator.moveY * 128)); //dy -1..1 -> -127..127
buffer.put(kb);
@@ -177,6 +185,10 @@ public void run() {
}
}
+ private int closestZero(float v) {
+ return (int) (v < 0 ? Math.ceil(v) : Math.floor(v));
+ }
+
public void abort() {
mRunning = false;
}
@@ -32,16 +32,24 @@ protected void onDraw(Canvas canvas) {
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
+ case ACTION_POINTER_DOWN:
+ return true;
case ACTION_MOVE:
case ACTION_DOWN:
final int width = getWidth();
final int height = getHeight();
- final float x = event.getX();
- final float y = event.getY();
-
- mNavigator.moveX = (x - width / 2) / (width / 2);
- mNavigator.moveY = (y - height / 2) / (height / 2);
+ for (int i = 0; i < event.getPointerCount(); i++) {
+ final float x = event.getX(i);
+ final float y = event.getY(i);
+ if (x < width / 2) {
+ mNavigator.moveX = (x - width / 4) / (width / 4);
+ mNavigator.moveY = (y - height / 2) / (height / 2);
+ } else {
+ mNavigator.rotation = (x - width / 2 - width / 4) / (width / 4);
+ mNavigator.cameraAngle = (y - height / 2) / (height / 2);
+ }
+ }
/*
// wasd
mNavigator.left = (x < width / 3);
@@ -8,9 +8,11 @@
public float moveX = 0; // -1.0..1.0
public float moveY = 0; // -1.0..1.0
+ public float rotation = 0; // -1.0..1.0
+ public float cameraAngle = 0; // -1.0..1.0
public void reset() {
up = down = left = right = false;
- moveX = moveY = 0;
+ moveX = moveY = rotation = cameraAngle = 0;
}
}

0 comments on commit f5b8a34

Please sign in to comment.