Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated examples to glm #6389

Merged
merged 17 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions addons/ofxiOS/src/utils/ofxiOSCoreMotion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#pragma once

#import <CoreMotion/CoreMotion.h>
#include "ofMatrix4x4.h"
#include "ofVectorMath.h"


class ofxiOSCoreMotion {

Expand All @@ -30,22 +31,22 @@ class ofxiOSCoreMotion {
void disableAttitude();

void resetAttitude(bool toCurrentReferenceFrame = true);
void setUpdateFrequency(float updateFrequency);
void update();
ofVec3f getAccelerometerData();
ofVec3f getGyroscopeData();
ofVec3f getMagnetometerData();

void setUpdateFrequency(float updateFrequency);
void update();

glm::vec3 getAccelerometerData();
glm::vec3 getGyroscopeData();
glm::vec3 getMagnetometerData();
float getRoll();
float getPitch();
float getYaw();
ofQuaternion getQuaternion();
ofMatrix4x4 getRotationMatrix();
ofVec3f getGravity();
ofVec3f getUserAcceleration();
ofVec3f getMagneticField();
glm::quat getQuaternion();
glm::mat4 getRotationMatrix();
glm::vec3 getGravity();
glm::vec3 getUserAcceleration();
glm::vec3 getMagneticField();

protected:

// core motion
Expand All @@ -56,15 +57,15 @@ class ofxiOSCoreMotion {
float updateFrequency;
bool enableAttitude, enableGyro, enableAccelerometer, enableMagnetometer;

ofVec3f accelerometerData;
ofVec3f gyroscopeData;
ofVec3f magnetometerData;
glm::vec3 accelerometerData;
glm::vec3 gyroscopeData;
glm::vec3 magnetometerData;
float roll, pitch, yaw;
ofQuaternion attitudeQuat;
ofMatrix4x4 rotMatrix;
ofVec3f gravity;
ofVec3f userAcceleration;
ofVec3f magneticField;
glm::quat attitudeQuat;
glm::mat4 rotMatrix;
glm::vec3 gravity;
glm::vec3 userAcceleration;
glm::vec3 magneticField;

};

44 changes: 23 additions & 21 deletions addons/ofxiOS/src/utils/ofxiOSCoreMotion.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
[motionManager stopDeviceMotionUpdates];
enableAttitude = false;
roll = pitch = yaw = 0;
attitudeQuat.set(0, 0, 0, 1);
rotMatrix.makeIdentityMatrix();
gravity.set(0,0,0);
userAcceleration.set(0, 0, 0);
magneticField.set(0, 0, 0);
attitudeQuat = glm::quat(1,0,0,0);
rotMatrix = glm::mat4(1);
gravity = { 0, 0, 0 };
userAcceleration = { 0, 0, 0 };
magneticField = { 0, 0, 0 };

}

void ofxiOSCoreMotion::setupAccelerometer() {
Expand All @@ -73,7 +73,7 @@

[motionManager stopAccelerometerUpdates];
enableAccelerometer = false;
accelerometerData.set(0, 0, 0);
accelerometerData = { 0, 0, 0 };
}

void ofxiOSCoreMotion::setupGyroscope() {
Expand All @@ -87,7 +87,7 @@

[motionManager stopGyroUpdates];
enableGyro = false;
gyroscopeData.set(0, 0, 0);
gyroscopeData = { 0, 0, 0 };
}

void ofxiOSCoreMotion::setupMagnetometer() {
Expand All @@ -101,7 +101,7 @@

[motionManager stopMagnetometerUpdates];
enableMagnetometer = false;
magnetometerData.set(0, 0, 0);
magnetometerData = { 0, 0, 0 };
}

void ofxiOSCoreMotion::setUpdateFrequency(float updateFrequency) {
Expand Down Expand Up @@ -167,15 +167,17 @@


// attitude quaternion
CMQuaternion quat = attitude.quaternion;
attitudeQuat.set(quat.x, quat.y, quat.z, quat.w);
attitudeQuat.x = attitude.quaternion.x;
attitudeQuat.y = attitude.quaternion.y;
attitudeQuat.z = attitude.quaternion.z;
attitudeQuat.w = attitude.quaternion.w;

// attitude rotation matrix
CMRotationMatrix rot = attitude.rotationMatrix;
rotMatrix.set(rot.m11, rot.m21, rot.m31, 0,
rotMatrix = { rot.m11, rot.m21, rot.m31, 0,
rot.m12, rot.m22, rot.m32, 0,
rot.m13, rot.m23, rot.m33, 0,
0, 0, 0, 1);
0, 0, 0, 1};
}

if(enableAccelerometer) {
Expand All @@ -200,15 +202,15 @@
}
}

ofVec3f ofxiOSCoreMotion::getAccelerometerData() {
glm::vec3 ofxiOSCoreMotion::getAccelerometerData() {
return accelerometerData;
}

ofVec3f ofxiOSCoreMotion::getGyroscopeData() {
glm::vec3 ofxiOSCoreMotion::getGyroscopeData() {
return gyroscopeData;
}

ofVec3f ofxiOSCoreMotion::getMagnetometerData() {
glm::vec3 ofxiOSCoreMotion::getMagnetometerData() {
return magnetometerData;
}

Expand All @@ -224,22 +226,22 @@
return yaw;
}

ofQuaternion ofxiOSCoreMotion::getQuaternion() {
glm::quat ofxiOSCoreMotion::getQuaternion() {
return attitudeQuat;
}

ofMatrix4x4 ofxiOSCoreMotion::getRotationMatrix() {
glm::mat4 ofxiOSCoreMotion::getRotationMatrix() {
return rotMatrix;
}

ofVec3f ofxiOSCoreMotion::getGravity() {
glm::vec3 ofxiOSCoreMotion::getGravity() {
return gravity;
}

ofVec3f ofxiOSCoreMotion::getUserAcceleration() {
glm::vec3 ofxiOSCoreMotion::getUserAcceleration() {
return userAcceleration;
}

ofVec3f ofxiOSCoreMotion::getMagneticField() {
glm::vec3 ofxiOSCoreMotion::getMagneticField() {
return magneticField;
}
Loading