Hi,
I’m experimenting with this package (GitHub - playcanvas/playcanvas-ar: Fast and Easy Augmented Reality for the Web). I’m trying to make the tracking a little less nervous and jittery by interpolating the position the tracked object accepts from ARToolkit. @will you mentioned that as a feasable solution to a similar issue on github.
Did I understand it right if an event called getMarker
is received from the ARToolkit whenever a marker is read. Which should be every frame unless the Track alternate frame
option is enabled, in case it’s every other frame.
Then my take would be to try and store the position and rotation received in some targetRotation/targetRotation and then use Vector3.lerp to move the actual transform of the entity towards the target over time (let’s say half a second of similar).
First question: Would that even remedy what I’m referring to as the wobbly movement in my screengrab?
Second question: I’ve tried for hours trying to implement the simplest lerp algorithms I’ve found on various places around here, but just can’t get my head around it. I’d be happy to share code, or if someone has done something along this line and could chirp in and help me out, I’d be very thankful.
What I’ve tried basically goes along the lines of this:
Instead of updating position directly like in the original:
entity.setPosition(self.finalMatrix.getTranslation());
entity.setEulerAngles(self.finalMatrix.getEulerAngles());
I’ve tried variations of this:
//entity.setPosition(self.finalMatrix.getTranslation());
//entity.setEulerAngles(self.finalMatrix.getEulerAngles());
// Add Lerping of object towards target position and rotation.
self.targetPosition = self.finalMatrix.getTranslation();
self.targetRotation = self.finalMatrix.getEulerAngles();
self.lerpAlpha = Math.min(self.lerpedTime/self.LERP_SPEED,1);
self.lerpedPosition.lerp(self.startPosition, self.targetPosition, self.lerpedTime);
self.lerpedRotation.lerp(self.startRotation, self.targetRotation, self.lerpedTime);
entity.setPosition(self.lerpedPosition);
entity.setEulerAngles(self.lerpedPosition);
// When new tracking data appears, also reset startPosition and lerpedTime
//self.lerpedTime = 0;
//self.startPosition = entity.getPosition();
//self.startRotation = entity.getEulerAngles();
btw, I increase lerpedTime in Update() since it’s the only one that has access to dt
:
this.lerpedTime += dt;
But I’m confused how and when to update my alpha and when to reset startPosition and currentLerpTime. (I guess on every getMarker event?)
Well. I’m confused.