From f281f316627b163489ecb39d837144142c9353f9 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Thu, 8 Apr 2010 15:27:31 +0200 Subject: Added HVector and HMatrix classes. --- SConstruct | 2 +- assimp.cpp | 49 +++++++++++++++++-------------------------------- hcoord.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ hcoord.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 hcoord.cpp create mode 100644 hcoord.h diff --git a/SConstruct b/SConstruct index 8d75526..0b7006f 100644 --- a/SConstruct +++ b/SConstruct @@ -2,7 +2,7 @@ env = Environment( LIBS = ['ARgsub_lite', 'ARvideo', 'AR', 'assimp'], ) -common_sources = ['application.cpp', 'videoprovider.cpp', 'pattern.cpp', 'texture.cpp', 'texturesdl.cpp'] +common_sources = ['application.cpp', 'videoprovider.cpp', 'hcoord.cpp', 'pattern.cpp', 'texture.cpp', 'texturesdl.cpp'] if env['PLATFORM'] == 'darwin': env.Append(CPPFLAGS = '-m32') diff --git a/assimp.cpp b/assimp.cpp index cccdc0e..e50532d 100755 --- a/assimp.cpp +++ b/assimp.cpp @@ -4,6 +4,8 @@ #include "pattern.h" #include "application.h" +#include "hcoord.h" + #include "texturesdl.h" #include @@ -20,9 +22,11 @@ class FiskPattern : public Pattern { int patt_id2; + HMatrix m1_mat; + bool m2_visible; - double m2_vec[3]; + HVector m2_vec; public: FiskPattern() : Pattern("patterns/m1.patt") { @@ -77,8 +81,6 @@ class FiskPattern : public Pattern { patt_width = 50.0; - patt_trans_kake[3][0] = patt_trans_kake[3][1] = patt_trans_kake[3][2] = 0; - patt_trans_kake[3][3] = 1.0; } protected: @@ -87,7 +89,7 @@ class FiskPattern : public Pattern { for(int j = 0; j < marker_num; j++) { if(patt_id == marker_info[j].id) { - arGetTransMat(&marker_info[j], patt_center, patt_width, patt_trans_kake); + arGetTransMat(&marker_info[j], patt_center, patt_width, m1_mat.m); m1_visible = true; //else if( marker_info[k].cf < marker_info[j].cf ) k = j; } @@ -97,28 +99,13 @@ class FiskPattern : public Pattern { return; } - //patt_trans_kake[0][0] = patt_trans_kake[1][1] = patt_trans_kake[2][2] = 1; - //patt_trans_kake[0][1] = patt_trans_kake[0][2] = 0; - //patt_trans_kake[1][0] = patt_trans_kake[1][2] = 0; - //patt_trans_kake[2][0] = patt_trans_kake[2][1] = 0; - - double m2_matrix[3][4]; + HMatrix m2_mat; for(int j = 0; j < marker_num; j++) { if(patt_id2 == marker_info[j].id) { - arGetTransMat(&marker_info[j], patt_center, patt_width, m2_matrix); + arGetTransMat(&marker_info[j], patt_center, patt_width, m2_mat.m); m2_visible = true; - - double x = m2_matrix[0][3]; - double y = m2_matrix[1][3]; - double z = m2_matrix[2][3]; - - arUtilMatInv(patt_trans_kake, m2_matrix); - - m2_vec[0] = m2_matrix[0][0] * x + m2_matrix[0][1] * y + m2_matrix[0][2] * z + m2_matrix[0][3]; - m2_vec[2] = -(m2_matrix[1][0] * x + m2_matrix[1][1] * y + m2_matrix[1][2] * z + m2_matrix[1][3]); - m2_vec[1] = m2_matrix[2][0] * x + m2_matrix[2][1] * y + m2_matrix[2][2] * z + m2_matrix[2][3]; - + m2_vec = m1_mat.inverse() * m2_mat.getTranslation(); } } @@ -126,14 +113,10 @@ class FiskPattern : public Pattern { } virtual void draw() { - double gl_para[16]; - //arglCameraView(patt_trans_kake, gl_para, 1.0); - glMatrixMode(GL_MODELVIEW); - //glLoadMatrixd(gl_para); - glLoadTransposeMatrixd((double*)patt_trans_kake); + m1_mat.glLoad(); - //glTranslatef(0.0, -8.0, 0.0); + glPushMatrix(); glRotatef(90, 1, 0, 0); @@ -159,6 +142,8 @@ class FiskPattern : public Pattern { } } + glPopMatrix(); + if(m2_visible) { glLineWidth(5); glDisable(GL_TEXTURE_2D); @@ -166,19 +151,19 @@ class FiskPattern : public Pattern { glColor3f(1, 1, 1); glVertex3f(0, 0, 0); - glVertex3f(m2_vec[0], m2_vec[1], m2_vec[2]); + glVertex3f(m2_vec.x, m2_vec.y, m2_vec.z); glColor3f(1, 0, 0); glVertex3f(0, 0, 0); - glVertex3f(m2_vec[0], 0, 0); + glVertex3f(m2_vec.x, 0, 0); glColor3f(0, 1, 0); glVertex3f(0, 0, 0); - glVertex3f(0, m2_vec[1], 0); + glVertex3f(0, m2_vec.y, 0); glColor3f(0, 0, 1); glVertex3f(0, 0, 0); - glVertex3f(0, 0, m2_vec[2]); + glVertex3f(0, 0, m2_vec.z); glEnd(); glEnable(GL_TEXTURE_2D); diff --git a/hcoord.cpp b/hcoord.cpp new file mode 100644 index 0000000..86e9f26 --- /dev/null +++ b/hcoord.cpp @@ -0,0 +1,41 @@ +#include "hcoord.h" +#include +#include + +HVector::HVector() { + w = 1.0; +} + +HVector::HVector(double _x, double _y, double _z, double _w) { + x = _x; + y = _y; + z = _z; + w = _w; +} + +HMatrix::HMatrix() { + m[3][0] = m[3][1] = m[3][2] = 0; + m[3][3] = 1.0; +} + +HMatrix HMatrix::inverse() { + HMatrix res; + arUtilMatInv(m, res.m); + return res; +} + +HVector HMatrix::operator*(const HVector& vec) { + HVector res; + res.x = m[0][0] * vec.x + m[0][1] * vec.y + m[0][2] * vec.z + m[0][3]; + res.y = m[1][0] * vec.x + m[1][1] * vec.y + m[1][2] * vec.z + m[1][3]; + res.z = m[2][0] * vec.x + m[2][1] * vec.y + m[2][2] * vec.z + m[2][3]; + return res; +} + +HVector HMatrix::getTranslation() { + return HVector(m[0][3], m[1][3], m[2][3]); +} + +void HMatrix::glLoad() { + glLoadTransposeMatrixd((double*)m); +} diff --git a/hcoord.h b/hcoord.h new file mode 100644 index 0000000..075d180 --- /dev/null +++ b/hcoord.h @@ -0,0 +1,28 @@ +#ifndef HCOORD_H +#define HCOORD_H + +class HVector { + public: + double x, y, z, w; + + HVector(); + HVector(double _x, double _y, double _z, double _w = 1.0); + +}; + +class HMatrix { + public: + double m[4][4]; + + HMatrix(); + + HMatrix inverse(); + + HVector operator*(const HVector& vec); + + HVector getTranslation(); + + void glLoad(); +}; + +#endif -- cgit v1.2.3