Skip to content

Instantly share code, notes, and snippets.

@toshinoritakata
Created March 24, 2012 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshinoritakata/2177919 to your computer and use it in GitHub Desktop.
Save toshinoritakata/2177919 to your computer and use it in GitHub Desktop.
ARToolkitをOgre3dで使う際のマーカ座標の変換を行う例
void ARListener::detectMarker(unsigned char* buffer)
{
int thresh = 150;
ARMarkerInfo* marker_info;
int marker_num;
arDetectMarker(const_cast<ARUint8*>(buffer), thresh, &marker_info, &marker_num);
// check for object visibility
for (int i = 0; i < MARKER_NUM; i ++) {
int k = -1;
for (int j = 0; j < marker_num; j++) {
if (marker_info[j].cf > 0.5) {
if (models[i].markerId == marker_info[j].id) {
if (k == -1) k = j;
else if (marker_info[k].cf < marker_info[j].cf) k = j;
}
}
}
if (k == -1) {
models[i].isVisible = false;
continue;
}
models[i].isVisible = true;
double patt_trans[3][4];
arGetTransMat(&marker_info[k], models[i].markerCenter, models[i].markerWidth, patt_trans);
double mv[16];
argConvGlpara(patt_trans, mv);
// 数値にNanが含まれていないかチェック
bool isValidNumbers = true;
for (int j = 0; j < 16; j ++) {
if (_isnan(mv[j])) {
isValidNumbers = false;
break;
}
}
if (isValidNumbers == false) continue;
Ogre::Vector3 curPos((Ogre::Real)mv[12], (Ogre::Real)-mv[13], (Ogre::Real)-mv[14]);
models[i].translation_ = models[i].translation_ * 0.4f + curPos * 0.6f;
Ogre::Vector3 rx = Ogre::Vector3((Ogre::Real)mv[0], (Ogre::Real)-mv[1], (Ogre::Real)-mv[2]);
Ogre::Vector3 ry = Ogre::Vector3((Ogre::Real)mv[4], (Ogre::Real)-mv[5], (Ogre::Real)-mv[6]);
Ogre::Vector3 rz = Ogre::Vector3((Ogre::Real)mv[8], (Ogre::Real)-mv[9], (Ogre::Real)-mv[10]);
Ogre::Quaternion curOri = Ogre::Quaternion(rx.normalisedCopy(), ry.normalisedCopy(), rz.normalisedCopy());
models[i].orientation_ = Ogre::Quaternion::Slerp(0.4f, models[i].orientation_, curOri, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment