0

我会说明情况。我正在尝试解决如何在出现标记时暂停相机。我所说的标记是从这个链接显示的。

http://code.google.com/p/andar/

当标记出现时,我想要一种暂停相机的方法,这样即使相机移动,标记也不会消失。我需要这个,所以在玩游戏时相机可以慢跑,但标记仍会留在正确的位置。这是标记活动的代码

公共类 CustomActivity 扩展 AndARActivity {

CustomObject2 someObject;
ARToolkit artoolkit;
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    CustomRenderer renderer = new CustomRenderer();//optional, may be set to null
    super.setNonARRenderer(renderer);//or might be omited
    try {
        //register a object for each marker type
        artoolkit = super.getArtoolkit();
        someObject = new CustomObject2
            ("test", "patt.hiro", 80.0, new double[]{0,0});
        artoolkit.registerARObject(someObject);
        someObject = new CustomObject2
        ("test", "android.patt", 80.0, new double[]{0,0});
        artoolkit.registerARObject(someObject);
        someObject = new CustomObject2
        ("test", "barcode.patt", 80.0, new double[]{0,0});
        artoolkit.registerARObject(someObject);
    } catch (AndARException ex){
        //handle the exception, that means: show the user what happened
        System.out.println("");
    }       
    startPreview();
}

/**
 * Inform the user about exceptions that occurred in background threads.
 * This exception is rather severe and can not be recovered from.
 * TODO Inform the user and shut down the application.
 */
public void uncaughtException(Thread thread, Throwable ex) {
    Log.e("AndAR EXCEPTION", ex.getMessage());
    finish();
}

}

@覆盖

用于绘制立方体的绘制函数

public final void draw(GL10 gl) {
        super.draw(gl);

        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR,mat_flash);
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, mat_flash_shiny);    
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mat_diffuse);  
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mat_ambient);

        //this code draws the cube. 
        gl.glColor4f(0, 1.0f, 0, 1.0f);
        gl.glTranslatef( 0.0f, 0.0f, 12.5f );


        // experement with the api
        //draw the box
      box.draw(gl);
    }

我会在 startPreview 函数周围包装代码吗?或者我是否需要检查对象是否被绘制,然后以这种方式停止预览。

我找到了这个命令,但我不确定在显示标记时如何实现它。我知道我需要一些条件,但不确定它是什么。camera.stopPreview();

4

1 回答 1

2

也许尝试添加一些代码来停止发送相机预览缓冲区进行处理。这样,它将继续渲染相机预览,但不会处理新帧。

于 2012-08-01T22:04:26.410 回答