Rotate on swipe
Hello all i am new for javascript and lens studio , i need to know is there any way to rotate 3D object with finger swipe ? both side up-down and left-right .
right now i am doing this automatic
var transform = script.getTransform();
var event = script.createEvent("LateUpdateEvent");
event.bind(function (eventData)
{
var transform = script.getTransform();
var rotation = transform.getLocalRotation();
var rotateBy = quat.angleAxis(0.02, vec3.up());
rotation = rotation.multiply(rotateBy);
transform.setLocalRotation(rotation);
});
but how to do using swipe ?
i had achieve this functionality with help of this code , but still buggy behaviour.
var isDragStart = false;
var touchStartPos;
var transform = script.getTransform();
var minimumDrag = 0.05;
var touchStart = script.createEvent("TouchStartEvent");
touchStart.bind(OnTouchStart);
var drag = script.createEvent("TouchMoveEvent");
drag.bind(StartRotation);
var event = script.createEvent("TouchEndEvent");
event.bind(function(eventData) {
touchStartPos = null;
});
function OnTouchStart(eventData) {
touchStartPos = eventData.getTouchPosition();
}
function StartRotation(eventData) {
if (touchStartPos) {
var currentPos = eventData.getTouchPosition();
var posChange = new vec2(currentPos.x - touchStartPos.x, currentPos.y - touchStartPos.y);
// print(Math.abs(posChange.x) +" "+Math.abs(posChange.y));
var rotation = transform.getLocalRotation();
if (Math.abs(posChange.y) > minimumDrag) {
if (posChange.y > 0.1) {
print("Down");
var rotateBy = quat.angleAxis(Math.PI * getDeltaTime() / 5, vec3.right());
} else {
print("Up");
var rotateBy = quat.angleAxis(Math.PI * getDeltaTime() / 5, vec3.left());
}
rotation = rotation.multiply(rotateBy);
transform.setLocalRotation(rotation);
} else if (Math.abs(posChange.x) > minimumDrag) {
if (posChange.x > 0.1) {
print("right");
var rotateBy = quat.angleAxis(Math.PI * getDeltaTime() / 5, vec3.up());
} else {
print("left");
var rotateBy = quat.angleAxis(Math.PI * getDeltaTime() / 5, vec3.down());
}
rotation = rotation.multiply(rotateBy);
transform.setLocalRotation(rotation);
}
}
}
Hi, Intellify Developer1 !
Please try out this script:
Also you might want to use touchBlocking
( https://lensstudio.snapchat.com/api/classes/TouchDataProvider/ )
Bingo Script work as i want , need little more help , is there way to restrict max rotation from both side ?
for example from horizontal and vertical rotation can not be more than +-45
Hi! Sorry for the late answer.
This is not exactly what you wanted but here is a cone limit approach, maybe you can utilize it. It can also be used for the gyro camera rotation limitation
Best
Olha
Hi Olha, thanks for this script. is there a way to control the limitations of negative side and up rotation?
I need to make my object not rotating downwards, then limit the rotation upwards