Skip to content

Commit

Permalink
new WebARKitGL collection of GL functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Nov 5, 2023
1 parent bfcebc9 commit 684d9c6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions WebARKit/WebARKitManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ cv::Mat WebARKitManager::getPoseMatrix() {
return m_tracker->getPoseMatrix();
}

std::array<float, 16> WebARKitManager::getTransformationMatrix() {
std::array<float, 16> transformationMatrix;
arglCameraViewRHf(m_tracker->getPoseMatrix(), transformationMatrix, 1.0f);
return transformationMatrix;
}

bool WebARKitManager::isValid() {
return m_tracker->isValid();
}
Expand Down
54 changes: 54 additions & 0 deletions WebARKit/include/WebARKitGL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef WEBARKITGL_H
#define WEBARKITGL_H

#include <opencv2/core.h>

void arglCameraViewRHf(float para[3][4], float m_modelview[16], const float scale) {
m_modelview[0 + 0 * 4] = para[0][0]; // R1C1
m_modelview[0 + 1 * 4] = para[0][1]; // R1C2
m_modelview[0 + 2 * 4] = para[0][2];
m_modelview[0 + 3 * 4] = para[0][3];
m_modelview[1 + 0 * 4] = -para[1][0]; // R2
m_modelview[1 + 1 * 4] = -para[1][1];
m_modelview[1 + 2 * 4] = -para[1][2];
m_modelview[1 + 3 * 4] = -para[1][3];
m_modelview[2 + 0 * 4] = -para[2][0]; // R3
m_modelview[2 + 1 * 4] = -para[2][1];
m_modelview[2 + 2 * 4] = -para[2][2];
m_modelview[2 + 3 * 4] = -para[2][3];
m_modelview[3 + 0 * 4] = 0.0f;
m_modelview[3 + 1 * 4] = 0.0f;
m_modelview[3 + 2 * 4] = 0.0f;
m_modelview[3 + 3 * 4] = 1.0f;
if (scale != 0.0f) {
m_modelview[12] *= scale;
m_modelview[13] *= scale;
m_modelview[14] *= scale;
}
}

void arglCameraViewRHf(cv::Mat para, std::array<float, 16>& m_modelview, const float scale) {
m_modelview[0 + 0 * 4] = para.at(0, 0); // R1C1
m_modelview[0 + 1 * 4] = para.at(0, 1); // R1C2
m_modelview[0 + 2 * 4] = para.at(0, 2);
m_modelview[0 + 3 * 4] = para.at(0, 3);
m_modelview[1 + 0 * 4] = -para.at(1, 0); // R2
m_modelview[1 + 1 * 4] = -para.at(1, 1);
m_modelview[1 + 2 * 4] = -para.at(1, 2);
m_modelview[1 + 3 * 4] = -para.at(1, 3);
m_modelview[2 + 0 * 4] = -para.at(2, 0); // R3
m_modelview[2 + 1 * 4] = -para.at(2, 1);
m_modelview[2 + 2 * 4] = -para.at(2, 2);
m_modelview[2 + 3 * 4] = -para.at(2, 3);
m_modelview[3 + 0 * 4] = 0.0f;
m_modelview[3 + 1 * 4] = 0.0f;
m_modelview[3 + 2 * 4] = 0.0f;
m_modelview[3 + 3 * 4] = 1.0f;
if (scale != 0.0f) {
m_modelview[12] *= scale;
m_modelview[13] *= scale;
m_modelview[14] *= scale;
}
}

#endif // WEBARKITGL_H
3 changes: 3 additions & 0 deletions WebARKit/include/WebARKitManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define WEBARKIT_MANAGER_H

#include <WebARKitLog.h>
#include <WebARKitGL.h>
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.h>
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitUtils.h>

Expand Down Expand Up @@ -101,6 +102,8 @@ class WebARKitManager {

cv::Mat getPoseMatrix();

std::array<float, 16> getTransformationMatrix();

bool isValid();
};

Expand Down

0 comments on commit 684d9c6

Please sign in to comment.