Skip to content

Commit

Permalink
android head tracking
Browse files Browse the repository at this point in the history
compiles, doesn't work yet... how to debug java code?
  • Loading branch information
ricardoquesada committed Jun 8, 2016
1 parent cbf5f64 commit 7e5d6ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public static float[] getSensorRotationMatrix() {
float[] inclinationM = new float[16];
float[] gravs = new float[3];
float[] geoMags = new float[3];
SensorManager.getRotationMatrix(rotationMatrix, inclimationMatrix, gravs, geoMags);
SensorManager.getRotationMatrix(rotationM, inclinationM, gravs, geoMags);
return rotationM;
}
}
17 changes: 13 additions & 4 deletions cocos/platform/android/jni/JniHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,29 @@ class CC_DLL JniHelper
}

template <typename... Ts>
static jfloatArray callStaticFloatArrayMethod(const std::string& className,
static float* callStaticFloatArrayMethod(const std::string& className,
const std::string& methodName,
Ts... xs) {
jfloatArray ret;
static float ret[32];
cocos2d::JniMethodInfo t;
std::string signature = "(" + std::string(getJNISignature(xs...)) + ")[F";
if (cocos2d::JniHelper::getStaticMethodInfo(t, className.c_str(), methodName.c_str(), signature.c_str())) {
ret = (jfloatArray) t.env->CallStaticObjectMethod(t.classID, t.methodID, convert(t, xs)...);
jfloatArray array = (jfloatArray) t.env->CallStaticObjectMethod(t.classID, t.methodID, convert(t, xs)...);
jsize len = t.env->GetArrayLength(array);
if (len <= 32) {
jfloat* elems = t.env->GetFloatArrayElements(array, 0);
if (elems) {
memcpy(ret, elems, sizeof(float) * len);
t.env->ReleaseFloatArrayElements(array, elems, 0);
};
}
t.env->DeleteLocalRef(t.classID);
deleteLocalRefs(t.env);
return &ret[0];
} else {
reportError(className, methodName, signature);
}
return ret;
return nullptr;
}

template <typename... Ts>
Expand Down
10 changes: 6 additions & 4 deletions cocos/vr/CCVRGenericHeadTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static Mat4 matrixFromRotationMatrix(const CMRotationMatrix& rotationMatrix)
0.0f,
1.0f);
}
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

static Mat4 getRotateEulerMatrix(float x, float y, float z)
{
Expand Down Expand Up @@ -97,7 +98,6 @@ static Mat4 getRotateEulerMatrix(float x, float y, float z)
matrix.m[15] = 1.0f;
return matrix;
}
#endif

VRGenericHeadTracker::VRGenericHeadTracker()
: _localPosition(Vec3::ZERO)
Expand Down Expand Up @@ -144,7 +144,8 @@ void VRGenericHeadTracker::startTracking()
// the inertial reference frame has z up and x forward, while the world has z out and x right
_worldToInertialReferenceFrame = getRotateEulerMatrix(-90.f, 0.f, 90.f);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

_deviceToDisplay = getRotateEulerMatrix(0.f, 0.f, -90.f);
_worldToInertialReferenceFrame = getRotateEulerMatrix(-90.f, 0.f, 90.f);
#endif
}

Expand Down Expand Up @@ -176,8 +177,9 @@ Mat4 VRGenericHeadTracker::getLocalRotation()
static const std::string helperClassName = "org/cocos2dx/lib/Cocos2dxHelper";
auto rotMatrix = JniHelper::callStaticFloatArrayMethod(helperClassName, "getSensorRotationMatrix");

Mat4 ret(rotMatrix);
return ret;
Mat4 inertialReferenceFrameToDevice(rotMatrix);
Mat4 worldToDevice = inertialReferenceFrameToDevice * _worldToInertialReferenceFrame;
return _deviceToDisplay * worldToDevice;
#else
return Mat4::IDENTITY;
#endif
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp-tests/Classes/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ bool AppDelegate::applicationDidFinishLaunching()
_testController = TestController::getInstance();

glview->setVREnabled(true);

return true;
}

Expand Down

0 comments on commit 7e5d6ad

Please sign in to comment.