Implement additional alternative camera control method

This commit is contained in:
utkabobr
2025-04-02 03:43:49 +03:00
parent 838cedbf1a
commit 8b200e689c
7 changed files with 58 additions and 31 deletions
@@ -4,12 +4,6 @@ import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Intent;
import android.util.Log;
import android.webkit.WebView;
import com.instacart.library.truetime.TrueTime;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
@@ -32,15 +26,11 @@ import ru.ytkab0bp.slicebeam.boot.PrefsTask;
import ru.ytkab0bp.slicebeam.boot.PrintConfigWarmupTask;
import ru.ytkab0bp.slicebeam.boot.TrueTimeTask;
import ru.ytkab0bp.slicebeam.boot.VibrationUtilsTask;
import ru.ytkab0bp.slicebeam.cloud.CloudController;
import ru.ytkab0bp.slicebeam.config.ConfigObject;
import ru.ytkab0bp.slicebeam.slic3r.ConfigOptionDef;
import ru.ytkab0bp.slicebeam.slic3r.PrintConfigDef;
import ru.ytkab0bp.slicebeam.slic3r.Slic3rConfigWrapper;
import ru.ytkab0bp.slicebeam.utils.IOUtils;
import ru.ytkab0bp.slicebeam.utils.Prefs;
import ru.ytkab0bp.slicebeam.utils.VibrationUtils;
import ru.ytkab0bp.slicebeam.utils.ViewUtils;
public class SliceBeam extends Application {
public static SliceBeam INSTANCE;
@@ -1,5 +1,6 @@
package ru.ytkab0bp.slicebeam.components.bed_menu;
import android.content.Context;
import android.widget.Toast;
import androidx.dynamicanimation.animation.FloatValueHolder;
@@ -10,6 +11,7 @@ import java.util.Arrays;
import java.util.List;
import ru.ytkab0bp.slicebeam.R;
import ru.ytkab0bp.slicebeam.components.BeamAlertDialogBuilder;
import ru.ytkab0bp.slicebeam.recycler.SimpleRecyclerItem;
import ru.ytkab0bp.slicebeam.recycler.SpaceItem;
import ru.ytkab0bp.slicebeam.render.Camera;
@@ -122,7 +124,20 @@ public class CameraMenu extends ListBedMenu {
animateTo(toOrigin, toPosition);
}),
new SpaceItem(portrait ? ViewUtils.dp(8) : 0, portrait ? 0 : ViewUtils.dp(8)),
new BedMenuItem(R.string.MenuCameraEnableRotation, R.drawable.sync_outline_28).setCheckable((buttonView, isChecked) -> Prefs.setRotationEnabled(isChecked), Prefs.isRotationEnabled()),
new BedMenuItem(R.string.MenuCameraControlMode, R.drawable.hand_point_up_outline_28).onClick(v -> {
Context ctx = v.getContext();
new BeamAlertDialogBuilder(v.getContext())
.setTitle(R.string.MenuCameraControlMode)
.setSingleChoiceItems(new CharSequence[] {
ctx.getString(R.string.MenuCameraControlModeOne),
ctx.getString(R.string.MenuCameraControlModeTwo),
ctx.getString(R.string.MenuCameraControlModeThree)
}, Prefs.getCameraControlMode(), (dialog, which) -> {
Prefs.setCameraControlMode(which);
dialog.dismiss();
})
.show();
}),
new BedMenuItem(R.string.MenuCameraOrtho, R.drawable.image_format_32).setCheckable((buttonView, isChecked) -> {
Prefs.setOrthoProjectionEnabled(isChecked);
fragment.getGlView().getRenderer().updateProjection();
@@ -68,12 +68,12 @@ public class Prefs {
return mPrefs.getString("beam_server_data", "{}");
}
public static boolean isRotationEnabled() {
return mPrefs.getBoolean("rotation_enabled", true);
public static int getCameraControlMode() {
return mPrefs.getInt("camera_control_mode", mPrefs.getBoolean("rotation_enabled", true) ? CAMERA_CONTROL_MODE_ROTATE_MOVE : CAMERA_CONTROL_MODE_MOVE_ONLY);
}
public static void setRotationEnabled(boolean e) {
mPrefs.edit().putBoolean("rotation_enabled", e).apply();
public static void setCameraControlMode(int mode) {
mPrefs.edit().putInt("camera_control_mode", mode).apply();
}
public static boolean isOrthoProjectionEnabled() {
@@ -38,8 +38,8 @@ public class GLView extends GLSurfaceView implements IThemeView {
private int touchSlop;
private boolean fromTwoPointers;
private boolean isRotating;
private boolean isMoving;
private boolean onePointerGesture;
private boolean twoPointerGesture;
private boolean isScaling;
private long lastActionTime = System.currentTimeMillis();
@@ -268,14 +268,14 @@ public class GLView extends GLSurfaceView implements IThemeView {
if (e.getPointerCount() == 1) {
fromTwoPointers = false;
isScaling = false;
isMoving = false;
twoPointerGesture = false;
lastActionTime = 0;
}
return true;
}
if (e.getPointerCount() == 1) {
if (!isRotating && action != MotionEvent.ACTION_CANCEL) {
if (!onePointerGesture && action != MotionEvent.ACTION_CANCEL) {
if (renderer.onClick(e.getX() * Prefs.getRenderScale(), e.getY() * Prefs.getRenderScale())) {
requestRender();
}
@@ -283,7 +283,7 @@ public class GLView extends GLSurfaceView implements IThemeView {
lastX = e.getX(0);
lastY = e.getY(0);
isRotating = false;
onePointerGesture = false;
}
// TODO: Rotate with inertia
@@ -300,16 +300,16 @@ public class GLView extends GLSurfaceView implements IThemeView {
if (deltaMs > 128) {
isScaling = false;
isMoving = false;
twoPointerGesture = false;
}
boolean startingGesture = false;
if (!isScaling && !isMoving) {
if (!isScaling && !twoPointerGesture) {
if (Math.abs(distanceX) < touchSlop && Math.abs(distanceY) < touchSlop && Math.abs(len - lastLength) > touchSlop * 1.5f) {
isScaling = true;
startingGesture = true;
} else if (Math.sqrt(distanceX * distanceX + distanceY * distanceY) >= touchSlop) {
isMoving = true;
twoPointerGesture = true;
startingGesture = true;
}
}
@@ -325,9 +325,14 @@ public class GLView extends GLSurfaceView implements IThemeView {
lastX = x;
lastY = y;
} else if (isMoving) {
} else if (twoPointerGesture) {
if (!startingGesture) {
renderer.getCamera().move(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
int mode = Prefs.getCameraControlMode();
if (mode == Prefs.CAMERA_CONTROL_MODE_ROTATE_MOVE || mode == Prefs.CAMERA_CONTROL_MODE_MOVE_ONLY) {
renderer.getCamera().move(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
} else {
renderer.getCamera().rotateAround(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
}
requestRender();
}
@@ -338,16 +343,17 @@ public class GLView extends GLSurfaceView implements IThemeView {
float distanceX = lastX - e.getX(), distanceY = lastY - e.getY();
boolean startingGesture = false;
if (!isRotating) {
if (!onePointerGesture) {
if (Math.sqrt(distanceX * distanceX + distanceY * distanceY) >= touchSlop) {
isRotating = true;
onePointerGesture = true;
startingGesture = true;
}
}
if (isRotating) {
if (onePointerGesture) {
if (!startingGesture) {
if (Prefs.isRotationEnabled()) {
int mode = Prefs.getCameraControlMode();
if (mode == Prefs.CAMERA_CONTROL_MODE_ROTATE_MOVE) {
renderer.getCamera().rotateAround(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
} else {
renderer.getCamera().move(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="28dp"
android:height="28dp"
android:viewportWidth="28"
android:viewportHeight="28">
<path
android:pathData="M11.005,4.145c-0.412,-1.693 -2.25,-2.621 -3.852,-1.896a2.82,2.82 0,0 0,-1.57 3.22l1.704,7.504a2.66,2.66 0,0 0,-3.779 0.57,2.715 2.715,0 0,0 0.042,3.22l4.622,6.094 0.001,0.002 0.036,0.049a6.136,6.136 0,0 0,0.576 0.644c0.398,0.388 0.996,0.877 1.817,1.317 1.658,0.888 4.158,1.536 7.628,0.836 2.844,-0.574 4.844,-2.15 5.902,-4.29 1.041,-2.107 1.121,-4.655 0.37,-7.147l-1.113,-4.743c-0.399,-1.697 -2.197,-2.671 -3.831,-2.03 -0.403,0.159 -0.75,0.398 -1.03,0.693a2.744,2.744 0,0 0,-2.289 -0.52,2.57 2.57,0 0,0 -1.242,0.653 2.498,2.498 0,0 0,-0.216 -0.139c-0.619,-0.355 -1.357,-0.431 -2.095,-0.246a3.037,3.037 0,0 0,-0.636 0.28l-1.045,-4.071ZM14.521,12.088 L14.522,12.09a1,1 0,0 0,1.937 -0.5l-0.001,-0.002 -0.254,-0.991c-0.142,-0.552 0.147,-0.906 0.467,-0.977a0.765,0.765 0,0 1,0.889 0.521l0.432,1.318v0.003a1,1 0,0 0,1.902 -0.619v-0.003l-0.12,-0.367a0.9,0.9 0,0 1,0.515 -1.116,0.864 0.864,0 0,1 1.152,0.625l1.121,4.774a1,1 0,0 0,0.017 0.063c0.646,2.12 0.536,4.14 -0.24,5.709 -0.762,1.543 -2.218,2.755 -4.505,3.216 -3.016,0.61 -5.042,0.03 -6.288,-0.639a6.08,6.08 0,0 1,-1.367 -0.986,4.141 4.141,0 0,1 -0.377,-0.421 0.952,0.952 0,0 0,-0.025 -0.035l-4.634,-6.11a0.715,0.715 0,0 1,-0.01 -0.843,0.66 0.66,0 0,1 1.043,-0.052l2.128,2.061a1,1 0,0 0,1.671 -0.94L7.531,5.02l-0.002,-0.01a0.82,0.82 0,0 1,0.449 -0.94,0.785 0.785,0 0,1 1.088,0.565l2.023,7.878a1,1 0,0 0,1.938 -0.491c-0.29,-1.16 -0.203,-1.683 -0.12,-1.889 0.05,-0.122 0.118,-0.193 0.312,-0.268 0.278,-0.06 0.46,-0.01 0.566,0.052 0.113,0.064 0.222,0.186 0.278,0.4l0.458,1.77ZM9.805,21.703ZM9.805,21.703"
android:fillColor="#000"
android:fillType="evenOdd"/>
</vector>
+4 -1
View File
@@ -48,7 +48,10 @@
<string name="MenuCameraLeft">Вид\nслева</string>
<string name="MenuCameraRight">Вид\nсправа</string>
<string name="MenuCameraOrtho">Ортог. проекц.</string>
<string name="MenuCameraEnableRotation">Вкл. поворот</string>
<string name="MenuCameraControlMode">Режим управ.</string>
<string name="MenuCameraControlModeOne">Один палец - поворот, два пальца - перемещение</string>
<string name="MenuCameraControlModeTwo">Один палец - перемещение, два пальца - поворот</string>
<string name="MenuCameraControlModeThree">Только перемещение</string>
<string name="MenuOrientation">Ориентация</string>
<string name="MenuOrientationArrange">Расст. модели</string>
<string name="MenuOrientationArrangeFinished">Модели расставлены.</string>
+4 -1
View File
@@ -50,7 +50,10 @@
<string name="MenuCameraLeft">Left view</string>
<string name="MenuCameraRight">Right view</string>
<string name="MenuCameraOrtho">Orth. project.</string>
<string name="MenuCameraEnableRotation">Allow rotation</string>
<string name="MenuCameraControlMode">Control mode</string>
<string name="MenuCameraControlModeOne">One finger - rotation, two fingers - movement</string>
<string name="MenuCameraControlModeTwo">One finger - movement, two fingers - rotation</string>
<string name="MenuCameraControlModeThree">Only movement</string>
<string name="MenuOrientation">Orientation</string>
<string name="MenuOrientationArrange">Arrange models</string>
<string name="MenuOrientationArrangeFinished">Models arranged.</string>