3

I am new in Android AS WELL IN Augmented Reality and i am facing some problem in AR .

That i am using an example of AndAR and in this example i can see simple cube box on my markers.

But i want to use my own image on my marker instead of that in build cube.

And i want to use different image for different markers.

this is my code:- where cube is generated.

public class CustomObject extends ARObject {


public CustomObject(String name, String patternName,
        double markerWidth, double[] markerCenter) {
    super(name, patternName, markerWidth, markerCenter);
    float   mat_ambientf[]     = {0f, 1.0f, 0f, 1.0f};
    float   mat_flashf[]       = {0f, 1.0f, 0f, 1.0f};
    float   mat_diffusef[]       = {0f, 1.0f, 0f, 1.0f};
    float   mat_flash_shinyf[] = {50.0f};

    mat_ambient = GraphicsUtil.makeFloatBuffer(mat_ambientf);
    mat_flash = GraphicsUtil.makeFloatBuffer(mat_flashf);
    mat_flash_shiny = GraphicsUtil.makeFloatBuffer(mat_flash_shinyf);
    mat_diffuse = GraphicsUtil.makeFloatBuffer(mat_diffusef);

}
public CustomObject(String name, String patternName,
        double markerWidth, double[] markerCenter, float[] customColor) {
    super(name, patternName, markerWidth, markerCenter);
    float   mat_flash_shinyf[] = {50.0f};

    mat_ambient = GraphicsUtil.makeFloatBuffer(customColor);
    mat_flash = GraphicsUtil.makeFloatBuffer(customColor);
    mat_flash_shiny = GraphicsUtil.makeFloatBuffer(mat_flash_shinyf);
    mat_diffuse = GraphicsUtil.makeFloatBuffer(customColor);

}

private SimpleBox box = new SimpleBox();
private FloatBuffer mat_flash;
private FloatBuffer mat_ambient;
private FloatBuffer mat_flash_shiny;
private FloatBuffer mat_diffuse;

/**
 * Everything drawn here will be drawn directly onto the marker,
 * as the corresponding translation matrix will already be applied.
 */
@Override
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);

    //draw cube
    gl.glColor4f(0, 1.0f, 0, 1.0f);
    gl.glTranslatef( 0.0f, 0.0f, 12.5f );


    box.draw(gl);
}
@Override
public void init(GL10 gl) {
    // TODO Auto-generated method stub

}

Please help me out to overcome from this problem.

Thanks.

Vikram Mahal
  • 306
  • 1
  • 11

1 Answers1

0

To create a new marker you can use one of these online marker generator tools:

Create a marker and save it preferably with a .patt suffix (e.g. dog.patt).

Copy your marker in an accessible directory from your Android application (e.g SDCard).

To load your specific marker, you need to look at the Custom Activity in the AndAR repository to see how it's done ( /svn/trunk/AndAR/src/edu/dhbw/andar/pub/CustomActivity.java ):

someObject = new CustomObject("test", "patt.hiro", 80.0, new double[]{0,0});
artoolkit.registerARObject(someObject);

When you declare your 3D object (CustomObject, the one drawing your SimpleBox), you can specify which marker it should use as initialization parameters (e.g. patt.hiro).

For information the initialization parameters are: marker name (arbitrary), file marker (your .patt file), size of the marker (mm), marker center (by default 0,0)).

  • 1
    Hi, I want to display image as a model instead of creating simple cube which displays on searching a marker. – Vikram Mahal May 15 '13 at 13:20
  • Ok it's a different problem. For doing that, you need to create a textured quad object in OpenGL and use your image for the texture. Look in stackoverflow, google for: textured quad, openGL ES on how to do that. [http://stackoverflow.com/questions/13455590/opengl-es-2-0-textured-quad] So you can probably create another CustomObject like QuadCustomObject and use this one in your CustomActivity. – Raphael Grasset May 15 '13 at 13:51
  • Hi, can anyone recommend me a way to use different image model for different markers in my android AR app. – Vikram Mahal May 16 '13 at 05:19