目标是制作一个简单的 2d 箭头指南针应用程序,就像这里的iPhone 3D Programming 一书中的应用程序一样,它可以平滑地旋转以响应方向变化。
AndroidManifest.xml(订阅方向更改)
<activity android:name="android.app.NativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
AndroidApp.cpp(获取旋转角度)
void AndroidApp::handleCmd (int32_t cmd) {
switch (cmd) {
case APP_CMD_CONFIG_CHANGED:
// Your code here
break;
}
}
RenderingEngine.cpp(存储角度以在渲染场景时旋转箭头)
void RenderingEngine::OnRotate(DeviceOrientation orientation)
{
float angle = 0;
switch (orientation) {
case DeviceOrientationLandscapeLeft:
angle = 270;
break;
case DeviceOrientationPortraitUpsideDown:
angle = 180;
break;
case DeviceOrientationLandscapeRight:
angle = 90;
break;
}
m_desiredAngle = angle;
}