How to use the webvr-polyfill/src/sensor-fusion/complementary-filter.prototype function in webvr-polyfill

To help you get started, we’ve selected a few webvr-polyfill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github naver / egjs-view360 / src / YawPitchControl / input / ComplementaryFilter.js View on Github external
import MathUtil from "webvr-polyfill/src/math-util";
import ComplementaryFilter from "webvr-polyfill/src/sensor-fusion/complementary-filter";

ComplementaryFilter.prototype.run_ = function() {
	if (!this.isOrientationInitialized) {
		this.accelQ = this.accelToQuaternion_(this.currentAccelMeasurement.sample);
		this.previousFilterQ.copy(this.accelQ);
		this.isOrientationInitialized = true;
		return;
	}

	const deltaT = this.currentGyroMeasurement.timestampS -
	this.previousGyroMeasurement.timestampS;

	// Convert gyro rotation vector to a quaternion delta.
	const gyroDeltaQ = this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample, deltaT);

	this.gyroIntegralQ.multiply(gyroDeltaQ);

	// filter_1 = K * (filter_0 + gyro * dT) + (1 - K) * accel.
github naver / egjs-view360 / src / YawPitchControl / input / ComplementaryFilter.js View on Github external
const targetQ = new MathUtil.Quaternion();

	targetQ.copy(this.filterQ);
	targetQ.multiply(deltaQ);

	// SLERP factor: 0 is pure gyro, 1 is pure accel.
	this.filterQ.slerp(targetQ, 1 - this.kFilter);

	this.previousFilterQ.copy(this.filterQ);

	if (!this.isFilterQuaternionInitialized) {
		this.isFilterQuaternionInitialized = true;
	}
};

ComplementaryFilter.prototype.getOrientation = function() {
	if (this.isFilterQuaternionInitialized) {
		return this.filterQ;
	} else {
		return null;
	}
};

export default ComplementaryFilter;