summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--application.cpp2
-rwxr-xr-xassimp.cpp91
-rw-r--r--pattern.cpp10
-rw-r--r--pattern.h7
4 files changed, 100 insertions, 10 deletions
diff --git a/application.cpp b/application.cpp
index 3ff3ab3..da0557f 100644
--- a/application.cpp
+++ b/application.cpp
@@ -127,7 +127,7 @@ void Application::main_loop(void) {
glDepthFunc(GL_LEQUAL);
patt->update(marker_info, marker_num);
- patt2->update(marker_info, marker_num);
+ if(patt2) { patt2->update(marker_info, marker_num); }
glDisable( GL_DEPTH_TEST );
diff --git a/assimp.cpp b/assimp.cpp
index aea1187..cccdc0e 100755
--- a/assimp.cpp
+++ b/assimp.cpp
@@ -18,8 +18,16 @@ class FiskPattern : public Pattern {
Texture** textures;
+ int patt_id2;
+
+ bool m2_visible;
+
+ double m2_vec[3];
+
public:
FiskPattern() : Pattern("patterns/m1.patt") {
+ patt_id2 = arLoadPatt("patterns/m2.patt");
+
scene = importer->ReadFile("tewi.x", 0);
if(scene) {
@@ -68,15 +76,62 @@ class FiskPattern : public Pattern {
textures[9] = new TextureSDL("gradient.png");
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:
+ virtual void update(ARMarkerInfo* marker_info, int marker_num) {
+ bool m1_visible = m2_visible = false;
+
+ 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);
+ m1_visible = true;
+ //else if( marker_info[k].cf < marker_info[j].cf ) k = j;
+ }
+ }
+
+ if(!m1_visible) {
+ 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];
+
+ 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);
+ 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];
+
+ }
+ }
+
+ draw();
+ }
+
virtual void draw() {
double gl_para[16];
- arglCameraView(patt_trans_kake, gl_para, 1.0);
+ //arglCameraView(patt_trans_kake, gl_para, 1.0);
glMatrixMode(GL_MODELVIEW);
- glLoadMatrixd(gl_para);
+ //glLoadMatrixd(gl_para);
+ glLoadTransposeMatrixd((double*)patt_trans_kake);
//glTranslatef(0.0, -8.0, 0.0);
@@ -104,9 +159,34 @@ class FiskPattern : public Pattern {
}
}
+ if(m2_visible) {
+ glLineWidth(5);
+ glDisable(GL_TEXTURE_2D);
+ glBegin(GL_LINES);
+
+ glColor3f(1, 1, 1);
+ glVertex3f(0, 0, 0);
+ glVertex3f(m2_vec[0], m2_vec[1], m2_vec[2]);
+
+ glColor3f(1, 0, 0);
+ glVertex3f(0, 0, 0);
+ glVertex3f(m2_vec[0], 0, 0);
+
+ glColor3f(0, 1, 0);
+ glVertex3f(0, 0, 0);
+ glVertex3f(0, m2_vec[1], 0);
+
+ glColor3f(0, 0, 1);
+ glVertex3f(0, 0, 0);
+ glVertex3f(0, 0, m2_vec[2]);
+
+ glEnd();
+ glEnable(GL_TEXTURE_2D);
+ }
}
};
+/*
class MarisaPattern : public Pattern {
private:
const aiScene* scene;
@@ -206,6 +286,7 @@ class MarisaPattern : public Pattern {
}
};
+*/
int main(int argc, char **argv) {
try {
@@ -216,10 +297,10 @@ int main(int argc, char **argv) {
app->patt = new FiskPattern();
- Assimp::Importer _importer2;
- importer = &_importer2;
+ //Assimp::Importer _importer2;
+ //importer = &_importer2;
- app->patt2 = new MarisaPattern();
+ //app->patt2 = new MarisaPattern();
app->run();
} catch(std::runtime_error e) {
diff --git a/pattern.cpp b/pattern.cpp
index 63b3bcc..e2a8fcd 100644
--- a/pattern.cpp
+++ b/pattern.cpp
@@ -29,12 +29,20 @@ void Pattern::update(ARMarkerInfo* marker_info, int marker_num) {
}
}
-SpritePattern::SpritePattern(Texture* _tex) : Pattern("patt.jon") {
+SpritePattern::SpritePattern(Texture* _tex) : Pattern("patterns/hiro.patt") {
tex = _tex;
}
void SpritePattern::draw() {
double gl_para[16];
+
+ patt_trans_kake[0][0] = patt_trans_kake[1][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;
+
+
arglCameraView(patt_trans_kake, gl_para, 1.0);
glMatrixMode(GL_MODELVIEW);
diff --git a/pattern.h b/pattern.h
index 75c91e3..cc32ebc 100644
--- a/pattern.h
+++ b/pattern.h
@@ -7,15 +7,16 @@
class Pattern {
private:
- int patt_id;
protected:
+ int patt_id;
+
double patt_width;
double patt_center[2];
- double patt_trans_kake[3][4];
+ double patt_trans_kake[4][4];
public:
Pattern(std::string filename);
- void update(ARMarkerInfo* marker_info, int marker_num);
+ virtual void update(ARMarkerInfo* marker_info, int marker_num);
protected:
virtual void draw() = 0;