mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-06 04:33:49 +01:00
Add camera/location support for iOS
Add front camera support for Android Allow to change the active camera in-game
This commit is contained in:
1 parent
1d6d66ac43
commit
5fbf2d7713
24 files changed
+409
-44
No files matched your search
@@ -15,6 +15,7 @@ import android.view.WindowManager;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@TargetApi(23)
|
||||
@@ -24,6 +25,7 @@ class CameraHelper {
|
||||
private Display mDisplay;
|
||||
private Camera mCamera = null;
|
||||
private boolean mIsCameraRunning = false;
|
||||
private int mCameraFacing = 0;
|
||||
private int mCameraOrientation = 0;
|
||||
private Camera.Size mPreviewSize = null;
|
||||
private long mLastFrameTime = 0;
|
||||
@@ -38,7 +40,11 @@ class CameraHelper {
|
||||
case Surface.ROTATION_180: displayDegrees = 180; break;
|
||||
case Surface.ROTATION_270: displayDegrees = 270; break;
|
||||
}
|
||||
return (mCameraOrientation - displayDegrees + 360) % 360;
|
||||
if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
||||
return (mCameraOrientation + displayDegrees) % 360;
|
||||
} else {
|
||||
return (mCameraOrientation - displayDegrees + 360) % 360;
|
||||
}
|
||||
}
|
||||
|
||||
static byte[] rotateNV21(final byte[] input, final int inWidth, final int inHeight,
|
||||
@@ -117,7 +123,7 @@ class CameraHelper {
|
||||
// convert to Jpeg
|
||||
Rect crop = new Rect(0, 0, targetW, targetH);
|
||||
yuvImage.compressToJpeg(crop, 80, baos);
|
||||
NativeApp.pushCameraImage(baos.toByteArray());
|
||||
NativeApp.pushCameraImageAndroid(baos.toByteArray());
|
||||
try {
|
||||
baos.close();
|
||||
} catch (IOException e) {
|
||||
@@ -132,14 +138,29 @@ class CameraHelper {
|
||||
mSurfaceTexture = new SurfaceTexture(10);
|
||||
}
|
||||
|
||||
static ArrayList<String> getDeviceList() {
|
||||
ArrayList<String> deviceList = new ArrayList<>();
|
||||
int nrCam = Camera.getNumberOfCameras();
|
||||
for (int index = 0; index < nrCam; index++) {
|
||||
Camera.CameraInfo info = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(index, info);
|
||||
String devName = index + ":" + (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK ? "Back Camera" : "Front Camera");
|
||||
deviceList.add(devName);
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
void startCamera() {
|
||||
Log.d(TAG, "startCamera");
|
||||
try {
|
||||
Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
|
||||
Camera.getCameraInfo(0, info);
|
||||
int cameraId = NativeApp.getSelectedCamera();
|
||||
Log.d(TAG, "startCamera: " + cameraId);
|
||||
|
||||
Camera.CameraInfo info = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(cameraId, info);
|
||||
mCameraFacing = info.facing;
|
||||
mCameraOrientation = info.orientation;
|
||||
|
||||
mCamera = Camera.open();
|
||||
mCamera = Camera.open(cameraId);
|
||||
Camera.Parameters param = mCamera.getParameters();
|
||||
|
||||
// Set preview size
|
||||
|
||||
@@ -50,12 +50,13 @@ class LocationHelper implements LocationListener {
|
||||
public void onLocationChanged(Location location) {
|
||||
float latitude = (float) location.getLatitude();
|
||||
float longitude = (float) location.getLongitude();
|
||||
// Android altitude is in meters above the WGS 84 reference ellipsoid
|
||||
float altitude = (float) location.getAltitude();
|
||||
float speed = location.getSpeed();
|
||||
float bearing = location.getBearing();
|
||||
long time = location.getTime() / 1000; // ms to s !!
|
||||
|
||||
NativeApp.pushNewGpsData(latitude, longitude, altitude, speed, bearing, time);
|
||||
NativeApp.setGpsDataAndroid(latitude, longitude, altitude, speed, bearing, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,7 @@ public class NativeApp {
|
||||
|
||||
public static native String queryConfig(String queryName);
|
||||
|
||||
public static native void pushNewGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long time);
|
||||
|
||||
public static native void pushCameraImage(byte[] image);
|
||||
public static native int getSelectedCamera();
|
||||
public static native void setGpsDataAndroid(float latitude, float longitude, float altitude, float speed, float bearing, long time);
|
||||
public static native void pushCameraImageAndroid(byte[] image);
|
||||
}
|
||||
Reference in new issue
Block a user