How to change the sphere into 3d models. (obj models) (augmented reality)

edited November 2013 in Questions about Code

Hello,

how do i change the spheres into 3d models?

I have an example that works but when I copy the files and lines it doesn't work in my project.

this is where I am at the moment -->

. . . . . .

// we want to use the gsvideo camera support stack

 import codeanticode.gsvideo.*;
// multiple marker tracking
import jp.nyatla.nyar4psg.*;
 // only necessary if you're using the OPENGL renderer (see the size() call in setup())
 import processing.opengl.*;
 // import obj
 import saito.objloader.*;
 import javax.media.opengl.*;





 //activeerd GSCapture
 GSCapture cam;
 //activeerd ar
 NyARMultiBoard nya;
 //importeerd het model
 OBJModel model ;
 float rot = 0.0;
 // importeerd 2 soorten fonts.
 PFont font, font2d;
 //fullscreen shizzle
 import fullscreen.*; 
 FullScreen fs; 







      void setup() {




   // our display is 640x480
   size(640,480,P3D);
     // the same size as the display, which should be 640x480
     // Dit is alleen voor p3d. want hij gaat nu naar fullscreen mode
    fs = new FullScreen(this); 
   // enter fullscreen mode
   fs.enter(); 



   //maakt de fonts aan.
   colorMode(RGB, 100);
    background(20);
   font=createFont("FFScala", 32);
   font2d = createFont("FFScala", 10);


 //start de webcam
   cam=new GSCapture(this,width,height);
   cam.start();


   //PATRONEN:
   // array of pattern file names, these have to be in the data subdir of this sketch
   // patt.hiro =string0 patt.kanji=string1 etc etc. 
   String[] patts = {"patt.hiro", "patt.kanji"};
   // array of corresponding widths in mm
   double[] widths = {80,80};


   // initialise the NyARMultiBoard
   // the camera parameter file is also in the data subdir
   nya=new NyARMultiBoard(this,width,height,"camera_para.dat",patts,widths);
   print(nya.VERSION);



   // marker detection algorithm parameter
   nya.gsThreshold=110;//(0<n<255) default=110
   // a marker has to be detected with a confidence greater than
   // this threshold for it to be considered a true detection
   nya.cfThreshold=0.2;//(0.0<n<1.0) default=0.4
 }







 // draw marker corners and also position in text
 void drawMarkerPos(int[][] pos2d)
 {
   textFont(font,10.0);
   stroke(100,0,0);
   fill(100,0,0);

   // draw ellipses at outside corners of marker
   for(int i=0;i<4;i++){
     ellipse(pos2d[i][0], pos2d[i][1],5,5);
   }

   fill(0,0,0);
   for(int i=0;i<4;i++){
     text("("+pos2d[i][0]+","+pos2d[i][1]+")",pos2d[i][0],pos2d[i][1]);
   }
 }






 // standard processing event handler that's called for display updates
 void draw() {
   // we only do something when the camera input is avail able
   if (cam.available() !=true) {
     return;
   }

   // get an image from the camera
   cam.read();

   // need to put camera image on screen, so temporarily disable depth testing
   hint(DISABLE_DEPTH_TEST);
  // put webcam image on screen
   image(cam,0,0);
   hint(ENABLE_DEPTH_TEST);

   // if *any* markers have been detected this will be true
   if (nya.detect(cam))
   {
     // going to be doing 2D drawing (drawMarkerPos) so temporarily disable depth testing
     hint(DISABLE_DEPTH_TEST);

     // for all detected markers, draw corner points
     for (int i=0; i < nya.markers.length; i++)
     {
       if (nya.markers[i].detected)
       {
         drawMarkerPos(nya.markers[i].pos2d);
       }
     }

     // depth test back on, we're going to draw 3D YEAH!!
     hint(ENABLE_DEPTH_TEST);

     // for all detected markers:
     for (int i=0; i < nya.markers.length; i++)
     {
       if (nya.markers[i].detected)
       {
   // set the model-view transform to that of the marker
   // this will adapt automatically to P3D or OPENGL renderers
   nya.markers[i].beginTransform();

   translate(5,5,0);
   // 5 pixels naar rechts en 5 pixels naar boven. dit bepaald de locatie. 
  // van ALLE afbeeldingen. 

   // ALs het eem hiro marker is(want case is 0), draw a 3D sphere van 40
   switch(i) {
     case 0:
       stroke(255,100,0);
       sphere(40);
     break;  
     // als het een kanji marker is (want case is 1) draw a sphere van 10 
     case 1:
       stroke(5,200,255);
       sphere(10);
     break;  

     default:
       println("maak een case aan");
     break;
   }

   // after drawing marker-relative 3D geometry, we
   // HAVE to end the transform (so now we're back in
   // world space)
   nya.markers[i].endTransform();

  }
}

} else { //geen markers gevonden. } }

Answers

  • edited November 2013

    and this is the example. this uses the singlemarker and i want to use the multi marker.

     import codeanticode.gsvideo.*;
     import jp.nyatla.nyar4psg.*;
     import processing.opengl.*;
     import javax.media.opengl.*;
     import saito.objloader.*;
    
     GSCapture cam;
     SingleARTKMarker nya;
     OBJModel model ;
     PFont font;
     float rot = 0.0;
     //fullscreen shizzle
     import fullscreen.*; 
     FullScreen fs; 
    
     void setup() {
       frameRate(10);
         //necessary for Mac OS X
    
    
       //try {
       //quicktime.QTSession.open();
       //} catch (quicktime.QTException qte) { 
       //qte.printStackTrace();
       //} 
    
       //size(screen.width,screen.height,OPENGL); 
       size(640,480,OPENGL);
        fs = new FullScreen(this); 
       // enter fullscreen mode
       fs.enter(); 
    
       colorMode(RGB, 100);
    
       font=createFont("FFScala", 32);
       //キャプチャを作成  -> een opname maken
       cam=new GSCapture(this,width,height);
     cam.start();
       //平面検出クラスを作成  --> Maak een vlakke detectie-klasse
       //Left hand projection matrix
       nya=new      
     SingleARTKMarker(this,width,height,"camera_para.dat",SingleARTKMarker.CS_LEFT);
       println(nya.VERSION);
       String[] marker={"patt.hiro","patt.kanji"};
       nya.setARCodes(marker,80);
       nya.setConfidenceThreshold(0.,0.0);
    
    
       model = new OBJModel(this, "1.obj", "absolute", TRIANGLES);
       model.enableDebug();
       model.scale(100);
       model.translateToCenter();
       model.enableTexture();
     }
     //この関数は、マーカ頂点の情報を描画します。 -> Deze functie tekent de marker      hoekpunt informatie.
     void drawMarkerPos(int[][] points)
     {
       textFont(font,10.0);
       stroke(100,0,0);
       fill(50,0,0);
       for(int i=0;i<4;i++){
         ellipse(nya.pos2d[i][0], nya.pos2d[i][1],5,5);
       }
       fill(0,0,0);
       for(int i=0;i<4;i++){
         text("("+nya.pos2d[i][0]+","+nya.pos2d[i][1]+")",nya.pos2d[i][0],nya.pos2d[i][1]);
       }
     }
    
     String angle2text(float a)
     {
       int i=(int)degrees(a);
       i=(i>0?i:i+360);
       return (i<100?"  ":i<10?" ":"")+Integer.toString(i);
     }
     String trans2text(float i)
     {
       return (i<100?"  ":i<10?" ":"")+Integer.toString((int)i);     
     }
    
     void draw() {
       background(255);
       if (cam.available() !=true) {
         return;
       }
       cam.read();
       //背景を描画 Achtergrond
      hint(DISABLE_DEPTH_TEST);
      image(cam,0,0);
       hint(ENABLE_DEPTH_TEST);
    
       //detect結果で処理を分ける。 (Resultaten gescheiden verwerking, leest verschillende markers
       switch(nya.detect(cam)){
       case SingleARTKMarker.ST_NOMARKER:
         //マーカ見つかんない markers
         break;
       case SingleARTKMarker.ST_NEWMARKER:
    //マーカが見つかったらしい markers
         println("Marker appeared. #"+nya.markerid);
         break;
       case SingleARTKMarker.ST_UPDATEMARKER:
         //マーカの位置を更新中・・・ markers
    
         //マーカの位置を描画
    hint(DISABLE_DEPTH_TEST);
         drawMarkerPos(nya.pos2d);
         hint(ENABLE_DEPTH_TEST);
    
         //キューブを描画 (tekent een cubus)
         PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
         nya.beginTransform(pgl);//マーカ座標系での描画を開始する。
         //ここからマーカ座標系
         translate(10000,19,0);
         if(nya.markerid==0){fill(255,0,0);}else if(nya.markerid==1){fill(0,0,255);}
    
    
    
         noFill();
         for(int n = 0; n <= 25; n++){
           stroke(0,255,0, 50);
        //   ellipse(0,0,100+3*n,100+3*n);
    
         }
    
    
         rotateX(radians(-180));
         translate(0,-50,0);
         //rotateY(radians(-90));
    
         //stroke(255,200,0);
         //fill(100,0,0);
         //box(40);
         noStroke();
         model.draw();
         nya.endTransform();//マーカ座標系での描画を終了する。(必ず呼んで!) einde      markertekenen
    
         break;
       case SingleARTKMarker.ST_REMOVEMARKER:
         //マーカなくなったでござる。
         println("Marker disappeared.");
         break;
            }
            rot = rot + 0.2;
          }
    
Sign In or Register to comment.