Log in or register to post comments

How to draw different 3D object on press different Menu?

August 22, 2011 - 2:04am #1

Hello,

I created some menu (typical android GUI menu) in qcar. just like the new sdk's toggle flash, auto focus menu in imagetargets. Now I want to draw different 3D object when I click specific menu.suppose teapot menu press will draw teapot object on marker and cube menu press will draw cube object. I already created some 3D object and tested. Now, how i configure/ link my menu to draw this 3D object?

Any suggestion/hint most welcome?

Thanks
Rassall

Re: How to draw different 3D object on press different Menu?

September 8, 2011 - 10:24am #9

This is a basic coding problem at this point. I'll just give you a bit of pseudo code, the rest is up to you!

// global
int shouldPlaySound = 0;

// on menu press
shouldPlaySound = 1;

// in renderFrame
if (shouldPlaySound == 1)
{
    // play sound
    shouldPlaySound = 0;
}

- Kim

Re: How to draw different 3D object on press different Menu?

September 7, 2011 - 1:07am #8

Thanks Kim,

According to last post, I tried to call the play function directly from menu functions. but the problem is if I press any menu then the specific audio clips auto play even without any marker detection. because the find trackbles function in rendering function.

JNIEXPORT jboolean JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_toggleFlash(JNIEnv*, jobject, jboolean flash)
{
playSoundEffect(0);
modelId = 1;
}

How I can add the hasplayed global boolean to play sound clip one time in render function. can you help here with some coding...

thanks..

Rassall

Re: How to draw different 3D object on press different Menu?

September 6, 2011 - 7:52pm #7

The renderFrame method is called every frame (so approximately 30 times a second). You need the OpenGL rendering code to happen each frame, but you certainly don't want to play a sound effect each frame. One approach would be to add a hasPlayed global boolean that you can use to ensure the sound is only played once per request.

In this particular situation, however, you shouldn't even need to drop down to native code. You're capturing UI events in Java, and playing sound effects in Java, so just skip the native round trip and play the sound directly from your menu handling code.

- Kim

Re: How to draw different 3D object on press different Menu?

September 6, 2011 - 1:46am #6

Hi Kim,

I am trying to implement sound here in my menu functions with the help of Domineos example. i already added the coding in java src file and jni file.
but facing problem on repeating sound during detect marker. Basically sound clip should play only one time for each menu function. My jni code is below here:

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)

if (modelId == 1)
{
.......................
.......................

glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE,
(const GLvoid*) &indices[0]);

playSoundEffect(0);

}

if (modelId == 2)
{
.......................
.......................

glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE,
(const GLvoid*) &indices1[0]);

playSoundEffect1(0);

}

here when i press menu 1(modelId=1) then the sound play with unlimited repeating and same for menu 2 (modelId=2).its just like hang by sound repeating.

How I solve the problem here. such that when I press menu 1 then specific sound should play only one time and when I press another menu another sound should play only one time.

Can you suggest me...

thanks
Rassall

Re: How to draw different 3D object on press different Menu?

August 25, 2011 - 2:30am #5

Thanks Kim,

Its working now...

Re: How to draw different 3D object on press different Menu?

August 23, 2011 - 8:38pm #4

You won't do any rendering in the menu1 function, you should continue to add your rendering code to the renderFrame function. Try creating a global variable to keep track of which model should be rendered. Something like this:

int modelId = 1;

JNIEXPORT jboolean JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_menu1(JNIEnv*, jobject, jboolean menu)
{
    modelId = 1;
}

JNIEXPORT jboolean JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_menu2(JNIEnv*, jobject, jboolean menu)
{
    modelId = 2;
}

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
{
    if (modelId == 1)
    {
        // render model 1
    }
    else if (modelId == 2)
    {
        // render model 2
    }
}

- Kim

Re: How to draw different 3D object on press different Menu?

August 23, 2011 - 12:30am #3

Thanks Kim for information to do this..

Now I m trying to follow the flash menu way in imagetargets example.

For that i written following coding in imagetargets.cpp:

public boolean onOptionsItemSelected(MenuItem item)
{

if(item.getTitle().equals("Menu"))
{
mMenu = !mMenu;
boolean result = menu1(mMenu);
}
...
}

now the I don't understand how i call the model from following function in imagetargets.cpp:

JNIEXPORT jboolean JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_menu1(JNIEnv*, jobject, jboolean menu)
{
..........///what will be the code here to call the model to draw from renderFrame functions?
}

As I drawn 2 model in following render function. so model will draw based on specific menu press.

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
{
..........//model 1
...........//model 2
}

Can you share some code here how to call 3D model from render function...

Thanks
Rassall

Re: How to draw different 3D object on press different Menu?

August 22, 2011 - 8:01am #2

Take a look at how the flash menu works in the samples. There are several native functions declared in ImageTargets.java that look something like this:

private native boolean toggleFlash(boolean flash);

That function is defined in ImageTargets.cpp with the following syntax:

JNIEXPORT jboolean JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_toggleFlash(JNIEnv*, jobject, jboolean flash)
{
    ...
}

You'll probably want to create a similar function that sets a global flag indicating which model should be rendered. Then you can just switch the code in your renderFrame method depending on this flag.

Read up on the JNI (Java Native Interface) for more details.

- Kim

Log in or register to post comments