|
|
@@ -1,19 +1,40 @@
|
|
|
// Urho3D editor camera functions
|
|
|
|
|
|
Camera@ camera;
|
|
|
-Window@ cameraDialog;
|
|
|
+Window@ editorSettingsDialog;
|
|
|
+
|
|
|
+enum ObjectMoveMode
|
|
|
+{
|
|
|
+ OBJ_MOVE = 0,
|
|
|
+ OBJ_ROTATE,
|
|
|
+ OBJ_SCALE
|
|
|
+}
|
|
|
|
|
|
float cameraBaseSpeed = 10;
|
|
|
float cameraBaseRotationSpeed = 0.2;
|
|
|
float cameraShiftSpeedMultiplier = 5;
|
|
|
float cameraYaw = 0;
|
|
|
float cameraPitch = 0;
|
|
|
-float updateStatsAcc = 0;
|
|
|
+
|
|
|
+float newNodeDistance = 20;
|
|
|
+float moveStep = 0.5;
|
|
|
+float rotateStep = 5;
|
|
|
+float scaleStep = 0.1;
|
|
|
+bool moveSnap = false;
|
|
|
+bool rotateSnap = false;
|
|
|
+bool scaleSnap = false;
|
|
|
+ObjectMoveMode moveMode = OBJ_MOVE;
|
|
|
|
|
|
Text@ renderStatsText;
|
|
|
Text@ cameraPosText;
|
|
|
bool subscribedToCameraEdits = false;
|
|
|
|
|
|
+array<string> moveModeText = {
|
|
|
+ "Move ",
|
|
|
+ "Rotate ",
|
|
|
+ "Scale "
|
|
|
+};
|
|
|
+
|
|
|
void createCamera()
|
|
|
{
|
|
|
// Note: this camera will not be bound into a scene entity, so that it does not get listed in the editor UI
|
|
|
@@ -23,41 +44,6 @@ void createCamera()
|
|
|
pipeline.setViewport(0, Viewport(editorScene, camera));
|
|
|
}
|
|
|
|
|
|
-void moveCamera(float timeStep)
|
|
|
-{
|
|
|
- if ((ui.getFocusElement() is null) && (!input.getKeyDown(KEY_CTRL)))
|
|
|
- {
|
|
|
- float speedMultiplier = 1.0f;
|
|
|
- if (input.getKeyDown(KEY_SHIFT))
|
|
|
- speedMultiplier = cameraShiftSpeedMultiplier;
|
|
|
-
|
|
|
- if ((input.getKeyDown('W')) || (input.getKeyDown(KEY_UP)))
|
|
|
- camera.translateRelative(Vector3(0, 0, cameraBaseSpeed) * timeStep * speedMultiplier);
|
|
|
- if ((input.getKeyDown('S')) || (input.getKeyDown(KEY_DOWN)))
|
|
|
- camera.translateRelative(Vector3(0, 0, -cameraBaseSpeed) * timeStep * speedMultiplier);
|
|
|
- if ((input.getKeyDown('A')) || (input.getKeyDown(KEY_LEFT)))
|
|
|
- camera.translateRelative(Vector3(-cameraBaseSpeed, 0, 0) * timeStep * speedMultiplier);
|
|
|
- if ((input.getKeyDown('D')) || (input.getKeyDown(KEY_RIGHT)))
|
|
|
- camera.translateRelative(Vector3(cameraBaseSpeed, 0, 0) * timeStep * speedMultiplier);
|
|
|
- }
|
|
|
-
|
|
|
- if (input.getMouseButtonDown(MOUSEB_RIGHT))
|
|
|
- {
|
|
|
- IntVector2 mouseMove = input.getMouseMove();
|
|
|
- if ((mouseMove.x != 0) || (mouseMove.y != 0))
|
|
|
- {
|
|
|
- cameraYaw += mouseMove.x * cameraBaseRotationSpeed;
|
|
|
- cameraPitch += mouseMove.y * cameraBaseRotationSpeed;
|
|
|
- if (cameraPitch < -90.0f)
|
|
|
- cameraPitch = -90.0f;
|
|
|
- if (cameraPitch > 90.0f)
|
|
|
- cameraPitch = 90.0f;
|
|
|
-
|
|
|
- camera.setRotation(Quaternion(cameraPitch, cameraYaw, 0));
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
void resetCamera()
|
|
|
{
|
|
|
camera.setPosition(Vector3(0, 10, 0));
|
|
|
@@ -66,35 +52,56 @@ void resetCamera()
|
|
|
cameraYaw = 0;
|
|
|
}
|
|
|
|
|
|
-void createCameraDialog()
|
|
|
+void createEditorSettingsDialog()
|
|
|
{
|
|
|
- if (!(cameraDialog is null))
|
|
|
+ if (!(editorSettingsDialog is null))
|
|
|
return;
|
|
|
|
|
|
- @cameraDialog = ui.loadLayout(cache.getResource("XMLFile", "UI/CameraDialog.xml"), uiStyle);
|
|
|
- uiRoot.addChild(cameraDialog);
|
|
|
- centerDialog(cameraDialog);
|
|
|
- updateCameraDialog();
|
|
|
- hideCameraDialog();
|
|
|
+ @editorSettingsDialog = ui.loadLayout(cache.getResource("XMLFile", "UI/EditorSettingsDialog.xml"), uiStyle);
|
|
|
+ uiRoot.addChild(editorSettingsDialog);
|
|
|
+ centerDialog(editorSettingsDialog);
|
|
|
+ updateEditorSettingsDialog();
|
|
|
+ hideEditorSettingsDialog();
|
|
|
}
|
|
|
|
|
|
-void updateCameraDialog()
|
|
|
+void updateEditorSettingsDialog()
|
|
|
{
|
|
|
- if (cameraDialog is null)
|
|
|
+ if (editorSettingsDialog is null)
|
|
|
return;
|
|
|
-
|
|
|
- LineEdit@ nearClipEdit = cameraDialog.getChild("NearClipEdit", true);
|
|
|
+
|
|
|
+ LineEdit@ nearClipEdit = editorSettingsDialog.getChild("NearClipEdit", true);
|
|
|
nearClipEdit.setText(toString(camera.getNearClip()));
|
|
|
|
|
|
- LineEdit@ farClipEdit = cameraDialog.getChild("FarClipEdit", true);
|
|
|
+ LineEdit@ farClipEdit = editorSettingsDialog.getChild("FarClipEdit", true);
|
|
|
farClipEdit.setText(toString(camera.getFarClip()));
|
|
|
|
|
|
- LineEdit@ fovEdit = cameraDialog.getChild("FOVEdit", true);
|
|
|
+ LineEdit@ fovEdit = editorSettingsDialog.getChild("FOVEdit", true);
|
|
|
fovEdit.setText(toString(camera.getFov()));
|
|
|
|
|
|
- LineEdit@ speedEdit = cameraDialog.getChild("SpeedEdit", true);
|
|
|
+ LineEdit@ speedEdit = editorSettingsDialog.getChild("SpeedEdit", true);
|
|
|
speedEdit.setText(toString(cameraBaseSpeed));
|
|
|
|
|
|
+ LineEdit@ distanceEdit = editorSettingsDialog.getChild("DistanceEdit", true);
|
|
|
+ distanceEdit.setText(toString(newNodeDistance));
|
|
|
+
|
|
|
+ LineEdit@ moveStepEdit = editorSettingsDialog.getChild("MoveStepEdit", true);
|
|
|
+ moveStepEdit.setText(toString(moveStep));
|
|
|
+ CheckBox@ moveSnapToggle = editorSettingsDialog.getChild("MoveSnapToggle", true);
|
|
|
+ moveSnapToggle.setChecked(moveSnap);
|
|
|
+
|
|
|
+ LineEdit@ rotateStepEdit = editorSettingsDialog.getChild("RotateStepEdit", true);
|
|
|
+ rotateStepEdit.setText(toString(rotateStep));
|
|
|
+ CheckBox@ rotateSnapToggle = editorSettingsDialog.getChild("RotateSnapToggle", true);
|
|
|
+ rotateSnapToggle.setChecked(rotateSnap);
|
|
|
+
|
|
|
+ LineEdit@ scaleStepEdit = editorSettingsDialog.getChild("ScaleStepEdit", true);
|
|
|
+ scaleStepEdit.setText(toString(scaleStep));
|
|
|
+ CheckBox@ scaleSnapToggle = editorSettingsDialog.getChild("ScaleSnapToggle", true);
|
|
|
+ scaleSnapToggle.setChecked(scaleSnap);
|
|
|
+
|
|
|
+ CheckBox@ localIDToggle = editorSettingsDialog.getChild("LocalIDToggle", true);
|
|
|
+ localIDToggle.setChecked(useLocalIDs);
|
|
|
+
|
|
|
if (!subscribedToCameraEdits)
|
|
|
{
|
|
|
subscribeToEvent(nearClipEdit, "TextChanged", "editCameraNearClip");
|
|
|
@@ -103,23 +110,35 @@ void updateCameraDialog()
|
|
|
subscribeToEvent(farClipEdit, "TextFinished", "editCameraFarClip");
|
|
|
subscribeToEvent(fovEdit, "TextChanged", "editCameraFOV");
|
|
|
subscribeToEvent(fovEdit, "TextFinished", "editCameraFOV");
|
|
|
- subscribeToEvent(fovEdit, "TextChanged", "editCameraSpeed");
|
|
|
+ subscribeToEvent(speedEdit, "TextChanged", "editCameraSpeed");
|
|
|
subscribeToEvent(speedEdit, "TextFinished", "editCameraSpeed");
|
|
|
- subscribeToEvent(cameraDialog.getChild("CloseButton", true), "Released", "hideCameraDialog");
|
|
|
+ subscribeToEvent(distanceEdit, "TextChanged", "editNewNodeDistance");
|
|
|
+ subscribeToEvent(distanceEdit, "TextFinished", "editNewNodeDistance");
|
|
|
+ subscribeToEvent(moveStepEdit, "TextChanged", "editMoveStep");
|
|
|
+ subscribeToEvent(moveStepEdit, "TextFinished", "editMoveStep");
|
|
|
+ subscribeToEvent(rotateStepEdit, "TextChanged", "editRotateStep");
|
|
|
+ subscribeToEvent(rotateStepEdit, "TextFinished", "editRotateStep");
|
|
|
+ subscribeToEvent(scaleStepEdit, "TextChanged", "editScaleStep");
|
|
|
+ subscribeToEvent(scaleStepEdit, "TextFinished", "editScaleStep");
|
|
|
+ subscribeToEvent(moveSnapToggle, "Toggled", "editMoveSnap");
|
|
|
+ subscribeToEvent(rotateSnapToggle, "Toggled", "editRotateSnap");
|
|
|
+ subscribeToEvent(scaleSnapToggle, "Toggled", "editScaleSnap");
|
|
|
+ subscribeToEvent(localIDToggle, "Toggled", "editUseLocalIDs");
|
|
|
+ subscribeToEvent(editorSettingsDialog.getChild("CloseButton", true), "Released", "hideEditorSettingsDialog");
|
|
|
subscribedToCameraEdits = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void showCameraDialog()
|
|
|
+void showEditorSettingsDialog()
|
|
|
{
|
|
|
- updateCameraDialog();
|
|
|
- cameraDialog.setVisible(true);
|
|
|
- cameraDialog.bringToFront();
|
|
|
+ updateEditorSettingsDialog();
|
|
|
+ editorSettingsDialog.setVisible(true);
|
|
|
+ editorSettingsDialog.bringToFront();
|
|
|
}
|
|
|
|
|
|
-void hideCameraDialog()
|
|
|
+void hideEditorSettingsDialog()
|
|
|
{
|
|
|
- cameraDialog.setVisible(false);
|
|
|
+ editorSettingsDialog.setVisible(false);
|
|
|
}
|
|
|
|
|
|
void editCameraNearClip(StringHash eventType, VariantMap& eventData)
|
|
|
@@ -154,6 +173,62 @@ void editCameraSpeed(StringHash eventType, VariantMap& eventData)
|
|
|
edit.setText(toString(cameraBaseSpeed));
|
|
|
}
|
|
|
|
|
|
+void editNewNodeDistance(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ LineEdit@ edit = eventData["Element"].getUIElement();
|
|
|
+ newNodeDistance = max(edit.getText().toFloat(), 0);
|
|
|
+ if (eventType == StringHash("TextFinished"))
|
|
|
+ edit.setText(toString(newNodeDistance));
|
|
|
+}
|
|
|
+
|
|
|
+void editMoveStep(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ LineEdit@ edit = eventData["Element"].getUIElement();
|
|
|
+ moveStep = max(edit.getText().toFloat(), 0);
|
|
|
+ if (eventType == StringHash("TextFinished"))
|
|
|
+ edit.setText(toString(moveStep));
|
|
|
+}
|
|
|
+
|
|
|
+void editRotateStep(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ LineEdit@ edit = eventData["Element"].getUIElement();
|
|
|
+ rotateStep = max(edit.getText().toFloat(), 0);
|
|
|
+ if (eventType == StringHash("TextFinished"))
|
|
|
+ edit.setText(toString(rotateStep));
|
|
|
+}
|
|
|
+
|
|
|
+void editScaleStep(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ LineEdit@ edit = eventData["Element"].getUIElement();
|
|
|
+ scaleStep = max(edit.getText().toFloat(), 0);
|
|
|
+ if (eventType == StringHash("TextFinished"))
|
|
|
+ edit.setText(toString(scaleStep));
|
|
|
+}
|
|
|
+
|
|
|
+void editMoveSnap(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ CheckBox@ edit = eventData["Element"].getUIElement();
|
|
|
+ moveSnap = edit.isChecked();
|
|
|
+}
|
|
|
+
|
|
|
+void editRotateSnap(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ CheckBox@ edit = eventData["Element"].getUIElement();
|
|
|
+ rotateSnap = edit.isChecked();
|
|
|
+}
|
|
|
+
|
|
|
+void editScaleSnap(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ CheckBox@ edit = eventData["Element"].getUIElement();
|
|
|
+ scaleSnap = edit.isChecked();
|
|
|
+}
|
|
|
+
|
|
|
+void editUseLocalIDs(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ CheckBox@ edit = eventData["Element"].getUIElement();
|
|
|
+ useLocalIDs = edit.isChecked();
|
|
|
+}
|
|
|
+
|
|
|
void createStatsBar()
|
|
|
{
|
|
|
Font@ font = cache.getResource("Font", "cour.ttf");
|
|
|
@@ -201,8 +276,240 @@ void updateStats(float timeStep)
|
|
|
yText.resize(8);
|
|
|
zText.resize(8);
|
|
|
|
|
|
- cameraPosText.setText("Physics: " + (runPhysics ? "Running " : "Paused ") + " Camera pos: " + xText + " " + yText + " " + zText + " ");
|
|
|
+ cameraPosText.setText(moveModeText[moveMode] + "Physics: " + (runPhysics ? "Running " : "Paused ") + " Camera pos: " + xText
|
|
|
+ + " " + yText + " " + zText + " ");
|
|
|
|
|
|
renderStatsText.setSize(renderStatsText.getMinSize());
|
|
|
cameraPosText.setSize(cameraPosText.getMinSize());
|
|
|
}
|
|
|
+
|
|
|
+void moveCamera(float timeStep)
|
|
|
+{
|
|
|
+ // Move camera
|
|
|
+ if ((ui.getFocusElement() is null) && (!input.getKeyDown(KEY_CTRL)))
|
|
|
+ {
|
|
|
+ float speedMultiplier = 1.0;
|
|
|
+ if (input.getKeyDown(KEY_SHIFT))
|
|
|
+ speedMultiplier = cameraShiftSpeedMultiplier;
|
|
|
+
|
|
|
+ if ((input.getKeyDown('W')) || (input.getKeyDown(KEY_UP)))
|
|
|
+ camera.translateRelative(Vector3(0, 0, cameraBaseSpeed) * timeStep * speedMultiplier);
|
|
|
+ if ((input.getKeyDown('S')) || (input.getKeyDown(KEY_DOWN)))
|
|
|
+ camera.translateRelative(Vector3(0, 0, -cameraBaseSpeed) * timeStep * speedMultiplier);
|
|
|
+ if ((input.getKeyDown('A')) || (input.getKeyDown(KEY_LEFT)))
|
|
|
+ camera.translateRelative(Vector3(-cameraBaseSpeed, 0, 0) * timeStep * speedMultiplier);
|
|
|
+ if ((input.getKeyDown('D')) || (input.getKeyDown(KEY_RIGHT)))
|
|
|
+ camera.translateRelative(Vector3(cameraBaseSpeed, 0, 0) * timeStep * speedMultiplier);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Rotate camera
|
|
|
+ if (input.getMouseButtonDown(MOUSEB_RIGHT))
|
|
|
+ {
|
|
|
+ IntVector2 mouseMove = input.getMouseMove();
|
|
|
+ if ((mouseMove.x != 0) || (mouseMove.y != 0))
|
|
|
+ {
|
|
|
+ cameraYaw += mouseMove.x * cameraBaseRotationSpeed;
|
|
|
+ cameraPitch += mouseMove.y * cameraBaseRotationSpeed;
|
|
|
+ if (cameraPitch < -90.0f)
|
|
|
+ cameraPitch = -90.0f;
|
|
|
+ if (cameraPitch > 90.0f)
|
|
|
+ cameraPitch = 90.0f;
|
|
|
+
|
|
|
+ camera.setRotation(Quaternion(cameraPitch, cameraYaw, 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Move/rotate/scale object
|
|
|
+ if ((selectedComponent !is null) && (ui.getFocusElement() is null) && (input.getKeyDown(KEY_CTRL)))
|
|
|
+ {
|
|
|
+ Node@ node = cast<Node>(selectedComponent);
|
|
|
+ if (node !is null)
|
|
|
+ {
|
|
|
+ bool changed = false;
|
|
|
+ Vector3 adjust(0, 0, 0);
|
|
|
+ if (input.getKeyDown(KEY_UP))
|
|
|
+ adjust.z = 1;
|
|
|
+ if (input.getKeyDown(KEY_DOWN))
|
|
|
+ adjust.z = -1;
|
|
|
+ if (input.getKeyDown(KEY_LEFT))
|
|
|
+ adjust.x = -1;
|
|
|
+ if (input.getKeyDown(KEY_RIGHT))
|
|
|
+ adjust.x = 1;
|
|
|
+ if (input.getKeyDown(KEY_PAGEUP))
|
|
|
+ adjust.y = 1;
|
|
|
+ if (input.getKeyDown(KEY_PAGEDOWN))
|
|
|
+ adjust.y = -1;
|
|
|
+ if (moveMode == OBJ_SCALE)
|
|
|
+ {
|
|
|
+ if ((input.getKeyDown(KEY_ADD)) || (input.getKeyDown(KEY_OEM_PLUS)))
|
|
|
+ adjust = Vector3(1, 1, 1);
|
|
|
+ if ((input.getKeyDown(KEY_SUBTRACT)) || (input.getKeyDown(KEY_OEM_MINUS)))
|
|
|
+ adjust = Vector3(-1, -1, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (adjust != Vector3(0, 0, 0))
|
|
|
+ {
|
|
|
+ adjust *= timeStep * 10;
|
|
|
+
|
|
|
+ if (input.getKeyDown(KEY_SHIFT))
|
|
|
+ adjust *= cameraShiftSpeedMultiplier;
|
|
|
+
|
|
|
+ switch (moveMode)
|
|
|
+ {
|
|
|
+ case OBJ_MOVE:
|
|
|
+ if (!moveSnap)
|
|
|
+ {
|
|
|
+ node.setPosition(node.getPosition() + adjust * moveStep);
|
|
|
+ changed = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case OBJ_ROTATE:
|
|
|
+ if (!rotateSnap)
|
|
|
+ {
|
|
|
+ Vector3 euler = node.getRotation().getEulerAngles();
|
|
|
+ euler.x += adjust.z * rotateStep;
|
|
|
+ euler.y += adjust.x * rotateStep;
|
|
|
+ euler.z += adjust.y * rotateStep;
|
|
|
+ node.setRotation(Quaternion(euler));
|
|
|
+ changed = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case OBJ_SCALE:
|
|
|
+ if (!scaleSnap)
|
|
|
+ {
|
|
|
+ node.setScale(node.getScale() + adjust * scaleStep);
|
|
|
+ changed = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (changed)
|
|
|
+ {
|
|
|
+ // If is a physics body, make sure the physics and rendering transforms are in sync
|
|
|
+ RigidBody@ body = cast<RigidBody>(node);
|
|
|
+ if (body !is null)
|
|
|
+ body.setTransform(node.getPosition(), node.getRotation(), node.getScale());
|
|
|
+
|
|
|
+ updateComponentAttributes();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void steppedObjectManipulation(int key)
|
|
|
+{
|
|
|
+ Node@ node = cast<Node>(selectedComponent);
|
|
|
+ if (node is null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ // Do not react in non-snapped mode, because that is handled in frame update
|
|
|
+ if ((moveMode == OBJ_MOVE) && (!moveSnap))
|
|
|
+ return;
|
|
|
+ if ((moveMode == OBJ_ROTATE) && (!rotateSnap))
|
|
|
+ return;
|
|
|
+ if ((moveMode == OBJ_SCALE) && (!scaleSnap))
|
|
|
+ return;
|
|
|
+
|
|
|
+ Vector3 adjust(0, 0, 0);
|
|
|
+ if (key == KEY_UP)
|
|
|
+ adjust.z = 1;
|
|
|
+ if (key == KEY_DOWN)
|
|
|
+ adjust.z = -1;
|
|
|
+ if (key == KEY_LEFT)
|
|
|
+ adjust.x = -1;
|
|
|
+ if (key == KEY_RIGHT)
|
|
|
+ adjust.x = 1;
|
|
|
+ if (key == KEY_PAGEUP)
|
|
|
+ adjust.y = 1;
|
|
|
+ if (key == KEY_PAGEDOWN)
|
|
|
+ adjust.y = -1;
|
|
|
+ if (moveMode == OBJ_SCALE)
|
|
|
+ {
|
|
|
+ if ((key == KEY_ADD) || (key == KEY_OEM_PLUS))
|
|
|
+ adjust = Vector3(1, 1, 1);
|
|
|
+ if ((key == KEY_SUBTRACT) || (key == KEY_OEM_MINUS))
|
|
|
+ adjust = Vector3(-1, -1, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (adjust == Vector3(0, 0, 0))
|
|
|
+ return;
|
|
|
+
|
|
|
+ switch (moveMode)
|
|
|
+ {
|
|
|
+ case OBJ_MOVE:
|
|
|
+ {
|
|
|
+ Vector3 pos = node.getPosition();
|
|
|
+ if (adjust.x != 0)
|
|
|
+ {
|
|
|
+ pos.x += adjust.x * moveStep;
|
|
|
+ pos.x = floor(pos.x / moveStep + 0.5) * moveStep;
|
|
|
+ }
|
|
|
+ if (adjust.y != 0)
|
|
|
+ {
|
|
|
+ pos.y += adjust.y * moveStep;
|
|
|
+ pos.y = floor(pos.y / moveStep + 0.5) * moveStep;
|
|
|
+ }
|
|
|
+ if (adjust.z != 0)
|
|
|
+ {
|
|
|
+ pos.z += adjust.z * moveStep;
|
|
|
+ pos.z = floor(pos.z / moveStep + 0.5) * moveStep;
|
|
|
+ }
|
|
|
+ node.setPosition(pos);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case OBJ_ROTATE:
|
|
|
+ {
|
|
|
+ Vector3 rot = node.getRotation().getEulerAngles();
|
|
|
+ if (adjust.z != 0)
|
|
|
+ {
|
|
|
+ rot.x += adjust.z * rotateStep;
|
|
|
+ rot.x = floor(rot.x / rotateStep + 0.5) * rotateStep;
|
|
|
+ }
|
|
|
+ if (adjust.x != 0)
|
|
|
+ {
|
|
|
+ rot.y += adjust.x * rotateStep;
|
|
|
+ rot.y = floor(rot.y / rotateStep + 0.5) * rotateStep;
|
|
|
+ }
|
|
|
+ if (adjust.y != 0)
|
|
|
+ {
|
|
|
+ rot.z += adjust.y * rotateStep;
|
|
|
+ rot.z = floor(rot.z / rotateStep + 0.5) * rotateStep;
|
|
|
+ }
|
|
|
+ node.setRotation(Quaternion(rot));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case OBJ_SCALE:
|
|
|
+ {
|
|
|
+ Vector3 scale = node.getScale();
|
|
|
+ if (adjust.x != 0)
|
|
|
+ {
|
|
|
+ scale.x += adjust.x * scaleStep;
|
|
|
+ scale.x = floor(scale.x / scaleStep + 0.5) * scaleStep;
|
|
|
+ }
|
|
|
+ if (adjust.y != 0)
|
|
|
+ {
|
|
|
+ scale.y += adjust.y * scaleStep;
|
|
|
+ scale.y = floor(scale.y / scaleStep + 0.5) * scaleStep;
|
|
|
+ }
|
|
|
+ if (adjust.z != 0)
|
|
|
+ {
|
|
|
+ scale.z += adjust.z * scaleStep;
|
|
|
+ scale.z = floor(scale.z / scaleStep + 0.5) * scaleStep;
|
|
|
+ }
|
|
|
+ node.setScale(scale);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // If is a physics body, make sure the physics and rendering transforms are in sync
|
|
|
+ RigidBody@ body = cast<RigidBody>(node);
|
|
|
+ if (body !is null)
|
|
|
+ body.setTransform(node.getPosition(), node.getRotation(), node.getScale());
|
|
|
+
|
|
|
+ updateComponentAttributes();
|
|
|
+}
|