i m working on project using Virtual Buttons sample app
which requires more virtual buttons to b added.
i made some changes in native code virtualbutton.cpp file in which tried adding one more virtual button like this
// Enumeration for masking button indices into single integer:
enum BUTTONS
{
BUTTON_1 = 1,
BUTTON_2 = 2,
BUTTON_3 = 4,
BUTTON_4 = 8,
BUTTON_5 = 16
};
int buttonMask = 0;
// Virtual Button runtime creation:
bool updateBtns = false;
const char* virtualButtonColors[] = {"red", "blue", "yellow", "green", "my"};
const int NUM_BUTTONS = 5;
.
.
.
.
.
.
// Add a button to the list of buttons which are toggled in the next update call
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_VirtualButtons_VirtualButtons_addButtonToToggle(JNIEnv *env, jobject obj, jint virtualButtonIdx)
{
LOG("Java_com_qualcomm_QCARSamples_VirtualButtons_VirtualButtons_addButtonToToggle");
assert(virtualButtonIdx >= 0 && virtualButtonIdx < NUM_BUTTONS);
switch (virtualButtonIdx)
{
case 0:
buttonMask |= BUTTON_1;
break;
case 1:
buttonMask |= BUTTON_2;
break;
case 2:
buttonMask |= BUTTON_3;
break;
case 3:
buttonMask |= BUTTON_4;
break;
case 4:
buttonMask |= BUTTON_5;
break;
}
updateBtns = true;
}
.
.
.
.
.
..
and in VirtualButtons_UpdateCallBack class i arbitrarily calculated the dimensions of the new virtual button which i named as Num Button 5 as
if (buttonMask & BUTTON_1)
{
LOG("Toggle Button 1");
toggleVirtualButton(imageTarget, virtualButtonColors[0],
-108.68f, -53.52f, -75.75f, -65.87f);
}
if (buttonMask & BUTTON_2)
{
LOG("Toggle Button 2");
toggleVirtualButton(imageTarget, virtualButtonColors[1],
-45.28f, -53.52f, -12.35f, -65.87f);
}
if (buttonMask & BUTTON_3)
{
LOG("Toggle Button 3");
toggleVirtualButton(imageTarget, virtualButtonColors[2],
14.82f, -53.52f, 47.75f, -65.87f);
}
if (buttonMask & BUTTON_4)
{
LOG("Toggle Button 4");
toggleVirtualButton(imageTarget, virtualButtonColors[3],
76.57f, -53.52f, 109.50f, -65.87f);
}
if (buttonMask & BUTTON_5)
{
LOG("Toggle Button 5");
toggleVirtualButton(imageTarget, virtualButtonColors[4],
64.82f, -3.52f, 97.75f, -15.87f);
}
.
.
.
.
.
.
.
.
.
and in renderFrame class i added this after already added vertices
vbVertices[vbCounter+24]=vbRectangle->getLeftTopX();
vbVertices[vbCounter+25]=vbRectangle->getLeftTopY();
vbVertices[vbCounter+26]=0.0f;
vbVertices[vbCounter+27]=vbRectangle->getRightBottomX();
vbVertices[vbCounter+28]=vbRectangle->getLeftTopY();
vbVertices[vbCounter+29]=0.0f;
vbCounter+=30;
.
.
.
.
.
.
.
.
in VirtualButtons.java i added
private static final int MENU_MY = 4;
and
in onCreateoptions.....
menu.add(0, MENU_MY, 0, R.string.menu_my)
.setIcon(R.drawable.menu_my);
.
.
.
and in onOptionsItemSelected... i added
case MENU_MY:
addButtonToToggle(4);
break;
.
.
.
i hav also added these coordinates in wood.xml file
now when i run the code as soon as i point towards trackable the boundry of already existed buttons is no longer there n "my" button is also no added
plz help!!
Re: Add new trackacle