public void display(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   synchronized (this._camera) {
     try {
       gl.glClear(
           GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
       NyARGLDrawUtil.drawBackGround(gl, this._camera.getSourceImage(), 1.0);
       this._nyar.update(this._camera);
       if (this._nyar.isExistMarker(this.ids[0])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[0]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       if (this._nyar.isExistMarker(this.ids[1])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[1]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       Thread.sleep(1);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
示例#2
0
 /** i_square,resultの有効期間は、この関数の終了までです。 */
 protected void onUpdateHandler(NyARSquare i_square, NyARDoubleMatrix44 result) {
   try {
     NyARGLUtil.toCameraViewRH(result, 1.0, this.gltransmat);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#3
0
 // エントリポイント
 public static void main(String[] args) {
   try {
     NyARParam cparam = NyARParam.createFromARParamFile(new FileInputStream(PARAM_FILE));
     cparam.changeScreenSize(SCREEN_X, SCREEN_Y);
     new SingleARMarker(cparam);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return;
 }
 public static void main(String[] args) {
   try {
     NyARMarkerSystemConfig config =
         new NyARMarkerSystemConfig(new FileInputStream(PARAM_FILE), SCREEN_X, SCREEN_Y);
     new SimpleLiteMStandard(config);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return;
 }
示例#5
0
 /** カメラデバイスからのコールバック */
 public void onUpdateBuffer(Buffer i_buffer) {
   try {
     synchronized (this._sync_object) {
       this._cap_image.setBuffer(i_buffer);
       // フレームワークに画像を転送
       this._processor.detectMarker(this._cap_image);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#6
0
  public void display(GLAutoDrawable drawable) {
    if (!_cap_image.hasBuffer()) {
      return;
    }
    // 背景を書く
    this._gl.glClear(
        GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
    // OnEnter,OnUpdateの間に、transmatに初回行列がストアされる実行されることを防ぎます。
    try {
      NyARGLDrawUtil.drawBackGround(this._gl, this._cap_image, 1.0);
      synchronized (this._sync_object) {
        if (this._processor.current_code < 0) {

        } else {
          // Projection transformation.
          this._gl.glMatrixMode(GL.GL_PROJECTION);
          this._gl.glLoadMatrixd(_camera_projection, 0);
          this._gl.glMatrixMode(GL.GL_MODELVIEW);
          // Viewing transformation.
          this._gl.glLoadIdentity();
          this._gl.glLoadMatrixd(this._processor.gltransmat, 0);
          // All other lighting and geometry goes here.
          this._gl.glPushMatrix();
          this._gl.glDisable(GL.GL_LIGHTING);

          // マーカのXZ平面をマーカの左上、表示開始位置を10cm上空へ。
          // くるーんくるん
          Date d = new Date();
          float r = (d.getTime() / 50) % 360;
          this._gl.glRotatef(r, 0f, 0f, 1.0f);
          this._gl.glTranslatef(-70f, 0f, 1.0f);
          this._gl.glRotatef(90, 1.0f, 0f, 0f);
          NyARGLDrawUtil.drawText("MarkerId:" + this._processor.current_code, 1f);
          this._gl.glPopMatrix();
          Thread.sleep(1); // タスク実行権限を一旦渡す
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return;
  }
示例#7
0
  /**
   * Reads an image from an archived file and return it as ByteBuffer object.
   *
   * @author Mike Butler, Kiet Le
   */
  private ByteBuffer readImage(String filename, Dimension dim) {
    if (dim == null) dim = new Dimension(0, 0);
    ByteBuffer bytes = null;
    try {
      DataInputStream dis =
          new DataInputStream(getClass().getClassLoader().getResourceAsStream(filename));
      dim.width = dis.readInt();
      dim.height = dis.readInt();
      System.out.println("Creating buffer, width: " + dim.width + " height: " + dim.height);
      // byte[] buf = new byte[3 * dim.height * dim.width];
      bytes = BufferUtil.newByteBuffer(3 * dim.width * dim.height);
      for (int i = 0; i < bytes.capacity(); i++) {
        bytes.put(dis.readByte());
      }
      dis.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
    bytes.rewind();
    return bytes;
  }
示例#8
0
  public void init(GLAutoDrawable drawable) {
    this._gl = drawable.getGL();
    this._gl.glEnable(GL.GL_DEPTH_TEST);
    NyARGLDrawUtil.setFontStyle("SansSerif", Font.BOLD, 36);
    NyARGLDrawUtil.setFontColor(Color.RED);
    this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    // NyARToolkitの準備
    try {
      // プロセッサの準備
      this._processor =
          new MarkerProcessor(this._ar_param, this._cap_image.getBufferType(), this._glnya);
      this._processor.setARCodeTable(_code_table, 16, 80.0);

      // カメラパラメータの計算
      NyARGLUtil.toCameraFrustumRH(this._ar_param, 1.0, 10, 10000, this._camera_projection);
      // キャプチャ開始
      this._capture.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
    this._animator = new Animator(drawable);
    this._animator.start();
    return;
  }
  /** Update or add a sprite to the client side game. */
  public void addPacket(HacktendoPacket Packet) {
    while (!getInitialized()) { // Make sure things have loaded before we start mucking with stuff.
      try {
        Thread.sleep(5);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    do {
      Sprite S = (Sprite) Sprites.get(new Integer(Packet.getID()));
      boolean setRenderType = false;
      if (S == null) {
        S = new Sprite(this);
        setRenderType = true;
        S.setParameter("destroy", new TypeBoolean(false));
        S.setParameter("globalID", new TypeInteger(Packet.getID()));
        S.setParameter("id", new TypeInteger(Packet.getID()));
        Sprites.put(new Integer(Packet.getID()), S);
        S.setOffscreenProcessing(false);
      }
      S.setScriptID(Packet.getScriptID());
      S.setImageID(Packet.getImage());

      if (S.getSpriteID() != playerID || setRenderType) { // Allow the sprite to move client side.
        S.setX(Packet.getX());
        S.setY(Packet.getY());
        S.setZ(Packet.getZ());
        S.setParameter("xTarget", new TypeInteger(Packet.getTargetX()));
        S.setParameter("yTarget", new TypeInteger(Packet.getTargetY()));
        S.setParameter("newTarget", new TypeBoolean(true));
      }

      if (Packet.getExplodeSprite()) S.explode();
      if (Packet.getDestroySprite()) S.setParameter("destroy", new TypeBoolean(true));
      S.setFrame(Packet.getFrame());
      S.setXRotation(Packet.getXRotation());
      S.setYRotation(Packet.getYRotation());
      S.setZRotation(Packet.getZRotation());

      S.setWidth(Packet.getWidth());
      S.setHeight(Packet.getHeight());
      S.setDepth(Packet.getDepth());
      S.setZOffset(Packet.getZOffset() * -1);

      if (setRenderType) S.setRenderType(Packet.getRenderType());

    } while (Packet.next() > 0);

    // Takes the form Object[]{ID,IP,Name,NPC,BODY_ID}
    if (Packet.getReferenceArray() != null) {
      for (int i = 0; i < Packet.getReferenceArray().size(); i++) {
        Object O[] = (Object[]) Packet.getReferenceArray().get(i);
        Sprite S = (Sprite) Sprites.get((Integer) O[0]);

        System.out.println("ID: " + O[0]);
        if (S != null) {
          String ip = (String) O[1];
          String name = (String) O[2];
          boolean npc = (Boolean) O[3];

          S.setParameter("ip", new TypeString(ip));
          S.setParameter("name", new TypeString(name));
          S.setParameter("npc", new TypeBoolean(npc));

          if (S.getScriptID() == SPRITE_SCRIPT) {
            S.setOffscreenProcessing(true);
            S.setAutoCollide(true);
            Sprite S2 = (Sprite) Sprites.get((Integer) O[4]);
            S.setParameter("body", new TypeInteger(S2.getSpriteID()));
          }

          if (ip.equals(MyHacker.getIP())) {
            if (S.getScriptID() == SPRITE_SCRIPT) {
              playerSprite = S;
            }
            playerID = S.getSpriteID();
            System.out.println(
                "We are setting the player to equal : "
                    + S.getSpriteID()
                    + " This Is Sprite ID: "
                    + O[0]);
            HacktendoLinker.addGlobal("player", new TypeInteger(S.getSpriteID()));
          }
        }
      }
    }
  }