Search code examples
androidcameraandar

using andar for android method to freeze camera


I will explain the situation. I am trying to work out how to pause the camera when a marker has appeared. What i mean by a marker is shown from this link.

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

When the mark has appeared I want a way to pause the camera so the marker wont disappear even though the camera moves. I need this so when playing a game the camera can be jogged but the marker will still stay in the right place. Here is the code form the marker activity

public class CustomActivity extends 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();
}

}

@Override

draw function used to draw the cube

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);
    }

Would I wrap code around the startPreview function. Or do I need to check to see if the object is drawn and then stop the preview in that manner.

I found this command but i am not sure how to implement it for when the marker is being displayed. I know i need some of condition but not sure what it is. camera.stopPreview();


Solution

  • Maybe try adding some code that will stop sending the camera preview buffer for processing. That way it will keep rendering the camera preview but will not process new frames.