- Sort Posts
- 15 replies
- Last post
Re: How to do this ?? (Virtualbuttons)
Re: How to do this ?? (Virtualbuttons)
this is code
#ifdef __cplusplus extern "C" { #endif int statebutton=0; // Textures: int textureCount = 0; Texture** textures = 0;
if (button->isPressed()) { // Run through button name array to find texture index for (int j = 0; j < NUM_BUTTONS; ++j) { if (strcmp(button->getName(), virtualButtonColors[j]) == 0) { textureIndex = j+1; statebutton = 1; if (j==0) { const Texture* const thisTexture = textures[textureIndex]; // Scale 3D model QCAR::Matrix44F modelViewScaled = modelViewMatrix; SampleUtils::scalePoseMatrix(kSpiderScale, kSpiderScale, kSpiderScale, &modelViewScaled.data[0]); QCAR::Matrix44F modelViewProjectionScaled; SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewScaled.data[0], &modelViewProjectionScaled.data[0]); // Render 3D model glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderVerts[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionScaled.data[0] ); glDrawArrays(GL_TRIANGLES, 0, spiderNumVerts); } if (j==1) { const Texture* const thisTexture = textures[textureIndex]; // Scale 3D model QCAR::Matrix44F modelViewScaled = modelViewMatrix; SampleUtils::scalePoseMatrix(kTeapotScale, kTeapotScale, kTeapotScale, &modelViewScaled.data[0]); QCAR::Matrix44F modelViewProjectionScaled; SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewScaled.data[0], &modelViewProjectionScaled.data[0]); // Render 3D model glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotVertices[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionScaled.data[0] ); glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]); } if (j==2) { const Texture* const thisTexture = textures[textureIndex]; // Scale 3D model QCAR::Matrix44F modelViewScaled = modelViewMatrix; SampleUtils::scalePoseMatrix(kSpiderexScale, kSpiderexScale, kSpiderexScale, &modelViewScaled.data[0]); QCAR::Matrix44F modelViewProjectionScaled; SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewScaled.data[0], &modelViewProjectionScaled.data[0]); // Render 3D model glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderexVerts[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderexNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderexTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionScaled.data[0] ); glDrawArrays(GL_TRIANGLES, 0, spiderexNumVerts); } if (j==3) { const Texture* const thisTexture = textures[textureIndex]; // Scale 3D model QCAR::Matrix44F modelViewScaled = modelViewMatrix; SampleUtils::scalePoseMatrix(kVaseScale, kVaseScale, kVaseScale, &modelViewScaled.data[0]); QCAR::Matrix44F modelViewProjectionScaled; SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewScaled.data[0], &modelViewProjectionScaled.data[0]); // Render 3D model glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &vaseVerts[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &vaseNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &vaseTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionScaled.data[0] ); glDrawArrays(GL_TRIANGLES, 0, vaseNumVerts); } break; } } }
// We only render if there is something on the array if (vbCounter>0) { // Render frame around button glUseProgram(vbShaderProgramID); glVertexAttribPointer(vbVertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &vbVertices[0]); glEnableVertexAttribArray(vbVertexHandle); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] ); // We multiply by 8 because that's the number of vertices per button // The reason is that GL_LINES considers only pairs. So some vertices // must be repeated. glDrawArrays(GL_LINES, 0, target->getNumVirtualButtons()*8); SampleUtils::checkGlError("VirtualButtons drawButton"); glDisableVertexAttribArray(vbVertexHandle); } if(statebutton ==0){ const Texture* const thisTexture = textures[textureIndex]; // Scale 3D model QCAR::Matrix44F modelViewScaled = modelViewMatrix; SampleUtils::scalePoseMatrix(kbananaScale, kbananaScale, kbananaScale, &modelViewScaled.data[0]); QCAR::Matrix44F modelViewProjectionScaled; SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewScaled.data[0], &modelViewProjectionScaled.data[0]); // Render 3D model glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaVerts[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionScaled.data[0] ); glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts); }
what can I do?
Re: How to do this ?? (Virtualbuttons)
Now, I can use the buttons to change object but I have some problem.
The first object that show on maker when I don't press the button is banana.
I want it to disapear when I press the button to change object.
the new object will show instead of banana.>>>this part I can do.
I want when I don't press the button, banana will show again on marker. >>> this part i can't do . Banana don't show again when I press button (first time) then don't press . Banana will show on marker before I don't press the button(first time) only.
Re: How to do this ?? (Virtualbuttons)
Re: How to do this ?? (Virtualbuttons)
Basic coding skills are a requirement for working with the SDK. Pick apart that renderFrame method until you understand it, then you should be able to work with it to conditionally render the model you want.
You may also want to look at the FrameMarkers sample. It renders a different model on each marker, that code might be a useful reference.
- Kim
Re: How to do this ?? (Virtualbuttons)
Re: How to do this ?? (Virtualbuttons)
Thank you so much Kim:)
I remove it already but teapot is disappear. I want teapot appear on target when I don't press the buttons.
And when I build VirtualButtons shared library It error about kSpiderScale
C:/development/android/qcar-android-1-0-6/samples/virtualbuttons/jni/VirtualButt ons.cpp: In function 'void Java_com_qualcomm_QCARSamples_VirtualButtons_VirtualB uttonsRenderer_renderFrame(JNIEnv*, _jobject*)':
C:/development/android/qcar-android-1-0-6/samples/virtualbuttons/jni/VirtualButt ons.cpp:284: error: 'kSpiderScale' was not declared in this scope
/cygdrive/c/Development/Android/android-ndk-r6/build/core/build-binary.mk:220: r ecipe for target `/cygdrive/c/development/android/qcar-android-1-0-6/samples/vir tualbuttons/obj/local/armeabi/objs-debug/VirtualButtons/VirtualButtons.o' failed
make: *** [/cygdrive/c/development/android/qcar-android-1-0-6/samples/virtualbut tons/obj/local/armeabi/objs-debug/VirtualButtons/VirtualButtons.o] Error 1
This is code
// If the button is pressed, than use this texture: if (button->isPressed()) { // Run through button name array to find texture index for (int j = 0; j < NUM_BUTTONS; ++j) { if (strcmp(button->getName(), virtualButtonColors[j]) == 0) { textureIndex = j+1; // Assumptions: assert(textureIndex < textureCount); const Texture* const thisTexture = textures[textureIndex]; // Scale 3D model QCAR::Matrix44F modelViewScaled = modelViewMatrix; SampleUtils::scalePoseMatrix(kSpiderScale, kSpiderScale, kSpiderScale, &modelViewScaled.data[0]); QCAR::Matrix44F modelViewProjectionScaled; SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewScaled.data[0], &modelViewProjectionScaled.data[0]); // Render 3D model glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderVerts[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionScaled.data[0] ); glDrawArrays(GL_TRIANGLES, 0, spiderNumVerts); break; } } }
Re: How to do this ?? (Virtualbuttons)
It's very similar to the code you posted here. Comment out this section (towards the end of the function):
// Render 3D model glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotVertices[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionScaled.data[0] ); glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]);
- Kim
Re: How to do this ?? (Virtualbuttons)
Did you remove the teapot rendering code at the end of that function? If not, you'll end up rendering the teapot over your model, most likely hiding it.
As always, make sure you're running ndk-build and refreshing (or cleaning) the Eclipse project after making changes to the native code.
- Kim
Re: How to do this ?? (Virtualbuttons)
Kim
I try it already. (my object name is spider)
// If the button is pressed, than use this texture: if (button->isPressed()) { // Run through button name array to find texture index for (int j = 0; j < NUM_BUTTONS; ++j) { if (strcmp(button->getName(), virtualButtonColors[j]) == 0) { // Assumptions: assert(textureIndex < textureCount); const Texture* const thisTexture = textures[textureIndex]; // Set the texture used for the teapot model: int textureIndex = 0; GLfloat vbVertices[96]; unsigned char vbCounter=0; // Scale 3D model QCAR::Matrix44F modelViewScaled = modelViewMatrix; SampleUtils::scalePoseMatrix(kTeapotScale, kTeapotScale, kTeapotScale, &modelViewScaled.data[0]); QCAR::Matrix44F modelViewProjectionScaled; SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewScaled.data[0], &modelViewProjectionScaled.data[0]); //Render 3D model glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderVerts[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &spiderTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionScaled.data[0] ); glDrawArrays(GL_TRIANGLES, 0, spiderNumVerts); break; } } } instead this script // If the button is pressed, than use this texture: if (button->isPressed()) { // Run through button name array to find texture index for (int j = 0; j < NUM_BUTTONS; ++j) { if (strcmp(button->getName(), virtualButtonColors[j]) == 0) { textureIndex = j+1; break; } } }
i think,i do it wrong.
because when i use it, the object not change and the texure not change too. just show teapot only.
sorry for my foolish :o
Re: How to do this ?? (Virtualbuttons)
Re: How to do this ?? (Virtualbuttons)
Start with the VirtualButtons sample. Take a look at the renderFrame method in VirtualButtons.cpp. This part is where the button press is handled:
// If the button is pressed, than use this texture: if (button->isPressed()) { // Run through button name array to find texture index for (int j = 0; j < NUM_BUTTONS; ++j) { if (strcmp(button->getName(), virtualButtonColors[j]) == 0) { textureIndex = j+1; break; } } }
This code picks the texture index based on the button that is currently pressed. You can update it to pick a particular model to render as well. Do this by swapping the vertices, normals, texcoords, and indices used later in the same function.
- Kim
Thank you Kim
I set statebutton = 0 at these point.
Result is banana always show.
It overlap with new object when I press the button.
I Think I set it wrong place.
I don't know where to set it.