Log in or register to post comments

How I create button for switching model

January 22, 2011 - 6:45pm #1

I need to create button that event of button can choose or select model that users wanted

How can I do?

Re: How I create button for switching model

January 24, 2011 - 6:28am #4

It's going to be a little difficult working with QCAR if you don't know C/C++, but here's the basic idea:

When an Android button is tapped in Java, you call a native method to handle the event. This happens in the UIThread, and it's important to know that the UIThread cannot make OpenGL calls.

The OpenGL context is bound to the GLThread. If you're looking at the ImageTargets sample project, all the methods in the ImageTargetsRenderer.java class are called on the GLThread. When these methods call down to native it is safe to make OpenGL calls.

So when a button is pressed in Java, you call down to native and save a bit of state, say an ID for the model you want drawn. Then, on the next onDrawFrame method call (this is called in a loop by the rendering system) you can use that state information to draw the correct model.

You can swap the model by changing the calls to glVertexAttribPointer and glDrawElements. You may also want to bind a different texture by changing the call to glBindTexture. Search for those names in ImageTargets.cpp or Dominoes.cpp (the ImageTargets sample is much simpler, and might be a better starting point).

- Kim

Re: How I create button for switching model

January 23, 2011 - 8:58pm #3

I have already tested your Dominoes sample application and VirtualButtons sample. It work fine

I have already created button on the screen but I don't know how send the events to native code to switch model

My application have two buttons which modify from Dominoes

The first button , I input event for playing mediaplayer of Android Sdk
The second button ,I need to create event for switching model

Please help me ,
I dont' have knowledge in C/C++
Thank you kim for your suggestion

Re: How I create button for switching model

January 23, 2011 - 7:21am #2

Do you want to create a button that the user taps on the screen, or a Virtual Button that the user presses on the target?

If you just want an on-screen button, you can use the Android SDK to place it and handle its events, and then send the events to native code to switch your model. See the Dominoes sample application for some example code.

If you'd like to use QCAR's Virtual Buttons, take a look at the VirtualButtons sample for some example code on creating these and handling events. It should be pretty simple to swap your model data after a button press.

- Kim

Log in or register to post comments