Log in or register to post comments

Java Heap Space Error in virtualButtons

April 1, 2013 - 3:45am #1

Hi All,

In VirtualButtons i have to change teapot to car object.

I had a car animation file. I converted that .FBX file format to .OBJ through FBX converter and then I convert that .OBJ to .h file through obj2openGL.perlscript.

But that .h file was taking 405 mb memory how can I change teapot object to car object.

Was there any way to do for large files.

Can Any one Help me.

 

Thanks in Advance.

Java Heap Space Error in virtualButtons

April 11, 2013 - 12:25am #32

Great!

Java Heap Space Error in virtualButtons

April 10, 2013 - 10:02pm #31

Thanks it's working fine now.

Java Heap Space Error in virtualButtons

April 10, 2013 - 9:18am #30

Ok, that explains the issue; the scale is very big, so if you want to stop the translation you need to use a MaxDistance quite small (because you are working on a base scale of 200), so for example use MaxDistance = 0.1f or 0.2f for example.

 

Java Heap Space Error in virtualButtons

April 10, 2013 - 1:32am #29

AlessandroB,

Still i am not getting.

my object is 3d car model. i gave static const float kCarScale = 200.0f;

 

Java Heap Space Error in virtualButtons

April 10, 2013 - 12:58am #28

Hi, this is the code I just tried (which stops the teapot at some point):

 QCAR::Matrix44F modelViewProjection;

        SampleUtils::translatePoseMatrix(0.f, 0.f, kObjectScale,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                     &modelViewMatrix.data[0]);

        const float MaxDistance = 20.0f;

        float distance = sqrtf( targetCumulatedDisplacement.data[0] * targetCumulatedDisplacement.data[0] +
                                targetCumulatedDisplacement.data[1] * targetCumulatedDisplacement.data[1] +
                                targetCumulatedDisplacement.data[2] * targetCumulatedDisplacement.data[2] );

        if (distance < MaxDistance)
        {

        	float screenDeltaX = 0.0f;// moving to the right 2 pixels every frame
        	float screenDeltaY = 2.0f;//

        	QCAR::Vec3F targetLocalDisplacement;
        	computeTargetTranslationFromScreenVector(screenDeltaX, screenDeltaY, modelViewMatrix, targetLocalDisplacement);

        	targetCumulatedDisplacement.data[0] += targetLocalDisplacement.data[0];
        	targetCumulatedDisplacement.data[1] += targetLocalDisplacement.data[1];
        	targetCumulatedDisplacement.data[2] += targetLocalDisplacement.data[2];
        }

        SampleUtils::translatePoseMatrix(targetCumulatedDisplacement.data[0],
        		targetCumulatedDisplacement.data[1],
        		targetCumulatedDisplacement.data[2],
                                         &modelViewMatrix.data[0]);

        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);

        glUseProgram(shaderProgramID);

Also, one question: are you still using the teapot (with kObjectScale = 3 ) ?, or have you changed the model and scale factor ?

If you are using a larger kObjectScale value, you will probably need to use very small values for MaxDistance.

 

Java Heap Space Error in virtualButtons

April 9, 2013 - 10:58pm #27

AlessandroB,

As you said I put MaxDistance = 0.0f it's not moving.

but if I give value 1.0f to maxdistance its not stoping, going on.

float distance = sqrtf( targetCumulatedDisplacement.data[0] * targetCumulatedDisplacement.data[0] +
targetCumulatedDisplacement.data[1] * targetCumulatedDisplacement.data[1] +
targetCumulatedDisplacement.data[2] * targetCumulatedDisplacement.data[2] );
if (distance < MaxDistance)
{
  QCAR::Vec3F targetLocalDisplacement;
  computeTargetTranslationFromScreenVector(screenDeltaX, screenDeltaY,modelViewMatrix, targetLocalDisplacement);

 targetCumulatedDisplacement.data[0] += distance; // += targetLocalDisplacement.data[0];
 targetCumulatedDisplacement.data[1] += distance; // += targetLocalDisplacement.data[1];
 targetCumulatedDisplacement.data[2] += distance; // += targetLocalDisplacement.data[2];
 distance = distance + 1.0f;
}

I changed little bit but its not moving.

was i done any thing wrong here.

Thanks in Advance.

 

Java Heap Space Error in virtualButtons

April 9, 2013 - 7:24am #26

If it is not stopping it means you still have some code around which updates the cumulated Target Translation, please check (and also try with MaxDistance = 0, just to be sure)

For the rotation, the technique is similar to the one that I already illustrated for translating, it's just a matter of updating your rotation angle according to some logic that you need to define in your application.

 

 

Java Heap Space Error in virtualButtons

April 9, 2013 - 6:05am #25

Hi,

I gave maxDistance = 20.0f but still its not stoping.

ok if we gave the degree its rotating but How to rotate towards right/left.

Thanks.

Java Heap Space Error in virtualButtons

April 9, 2013 - 5:26am #24

Hi, have you tried wreducing the value of MaxDistance ? if it is small enough, you should see the model stopping movig at some point.

For rotating a 3D model, you can use some code like the following:

SampleUtils::rotatePoseMatrix( some_angle_degrees, 0.0f, 0.0f, 1.0, 
                            &modelViewMatrix.data[0] );

you can put that code right after the line SampleUtils::translatePoseMatrix(...)

Java Heap Space Error in virtualButtons

April 9, 2013 - 4:56am #23

Hi AlessandroB,

I changed the code as you said, but still it's going on not stopping for particular distance.

And also how to rotate 3d model?

Thanks in Advacance.

Java Heap Space Error in virtualButtons

April 8, 2013 - 5:38am #22

The code should look more like this:


// Set transformations:
QCAR::Matrix44F modelViewProjection;

SampleUtils::translatePoseMatrix(0.f, 0.f, kBananaScale,&modelViewMatrix.data[0]);
SampleUtils::scalePoseMatrix(kBananaScale, kBananaScale, kBananaScale,&modelViewMatrix.data[0]);

float screenDeltaX = 0.0f;// moving to the right 2 pixels every frame
float screenDeltaY = 0.0f;

float distance = sqrtf( targetCumulatedDisplacement.data[0] * targetCumulatedDisplacement.data[0] +
targetCumulatedDisplacement.data[1] * targetCumulatedDisplacement.data[1] +
targetCumulatedDisplacement.data[2] * targetCumulatedDisplacement.data[2] );
if (distance < MaxDistance) 
{
  QCAR::Vec3F targetLocalDisplacement;
  computeTargetTranslationFromScreenVector(screenDeltaX, screenDeltaY,modelViewMatrix, targetLocalDisplacement);
  targetCumulatedDisplacement.data[0] += targetLocalDisplacement.data[0]; 
  targetCumulatedDisplacement.data[1] += targetLocalDisplacement.data[1]; 
  targetCumulatedDisplacement.data[2] += targetLocalDisplacement.data[2]; 
}

Note: MaxDistance is just a constant that you define with the value that you want (for example const float MaxDistance = 100.0f; )

Java Heap Space Error in virtualButtons

April 8, 2013 - 5:02am #21

Hi AlessandroB,

can i change code like below

QCAR::Vec3F targetCumulatedDisplacement(0.0f, 0.0f, 0.0f);

---

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_VirtualButtons_VirtualButtons_resetModelTranslation(
                            JNIEnv* env, jobject obj)
{
    targetCumulatedDisplacement.data[0] = 0.0f;
    targetCumulatedDisplacement.data[1] = 0.0f;
    targetCumulatedDisplacement.data[2] = 0.0f;
}

------

// Set transformations:
QCAR::Matrix44F modelViewProjection;

SampleUtils::translatePoseMatrix(0.f, 0.f, kBananaScale,&modelViewMatrix.data[0]);
SampleUtils::scalePoseMatrix(kBananaScale, kBananaScale, kBananaScale,&modelViewMatrix.data[0]);

float screenDeltaX = 0.0f;// moving to the right 2 pixels every frame
float screenDeltaY = 0.0f;

QCAR::Vec3F targetLocalDisplacement;
computeTargetTranslationFromScreenVector(screenDeltaX, screenDeltaY,modelViewMatrix, targetLocalDisplacement);

targetCumulatedDisplacement.data[0] += targetLocalDisplacement.data[0];
targetCumulatedDisplacement.data[1] += targetLocalDisplacement.data[1];
targetCumulatedDisplacement.data[2] += targetLocalDisplacement.data[2];

float distance = sqrtf( targetCumulatedDisplacement.data[0] * targetCumulatedDisplacement.data[0] +
targetCumulatedDisplacement.data[1] * targetCumulatedDisplacement.data[1] +
targetCumulatedDisplacement.data[2] * targetCumulatedDisplacement.data[2] );

if(targetCumulatedDisplacement.data[0] <= distance )
{
SampleUtils::translatePoseMatrix(targetCumulatedDisplacement.data[0],targetCumulatedDisplacement.data[1],

targetCumulatedDisplacement.data[2],&modelViewMatrix.data[0]);

SampleUtils::multiplyMatrix(&projectionMatrix.data[0],&modelViewMatrix.data[0],&modelViewProjection.data[0]);
}

its nothing changing.

was i doing wrong. suggest me.

How can we rotate the 3d Object.

Thanks in Advance.

 

Java Heap Space Error in virtualButtons

April 8, 2013 - 4:11am #20

Hi,

one way you could do it is by computing the length of targetCumulatedDisplacement.data[0], for instance:

float distance = sqrtf( targetCumulatedDisplacement.data[0] * targetCumulatedDisplacement.data[0] + 

targetCumulatedDisplacement.data[1] * targetCumulatedDisplacement.data[1] + 

targetCumulatedDisplacement.data[2] * targetCumulatedDisplacement.data[2] );

Then, based on the distance, you could implement an "if" condition to stop moving; the rest is just about C++ programming...

Java Heap Space Error in virtualButtons

April 8, 2013 - 4:01am #19

Hi AlessandroB,

How can i stop moving 3d object after some distance?

Thanks in Andvance.

Java Heap Space Error in virtualButtons

April 5, 2013 - 12:05am #18

Hi,

For Stop motion where have to change in below code.

QCAR::Matrix44F modelViewProjection;

SampleUtils::translatePoseMatrix(0.f, 0.f, kBananaScale,&modelViewMatrix.data[0]);
SampleUtils::scalePoseMatrix(kBananaScale, kBananaScale, kBananaScale,&modelViewMatrix.data[0]);

float screenDeltaX = 0.0f;// moving to the right 2 pixels every frame
float screenDeltaY = 2.0f;//

QCAR::Vec3F targetLocalDisplacement;
computeTargetTranslationFromScreenVector(screenDeltaX, screenDeltaY,modelViewMatrix, targetLocalDisplacement);

targetCumulatedDisplacement.data[0] += targetLocalDisplacement.data[0];
targetCumulatedDisplacement.data[1] += targetLocalDisplacement.data[1];
targetCumulatedDisplacement.data[2] += targetLocalDisplacement.data[2];

SampleUtils::translatePoseMatrix(targetCumulatedDisplacement.data[0],targetCumulatedDisplacement.data[1],

targetCumulatedDisplacement.data[2],&modelViewMatrix.data[0]);

SampleUtils::multiplyMatrix(&projectionMatrix.data[0],&modelViewMatrix.data[0],&modelViewProjection.data[0]);

if i changed float screenDeltaY = 2.0f then it moving towards down.

if i changed targetCumulatedDisplacment.data[0] = 20.0f and 1,2 also then model was not appearing.

Java Heap Space Error in virtualButtons

April 4, 2013 - 10:47pm #17

Hi, yes, the tutorial shows how to move an object in a plane parallel to the screen;

of course you can stop the movement at the distance you like;

if you want to control the motion from a touch and drag, you will need to detect the drag events in Java and pass the amount of motion down to C++ through a native function; the idea is to pass the amount of drag in pixels as the screenDeltaX and screeDeltaY parameters to this function:

 

computeTargetTranslationFromScreenVector(float screenDeltaX, float screenDeltaY,
        QCAR::Matrix44F & modelViewMatrix, QCAR::Vec3F & result)
{

You could teake inspiration from the GestureDetector used in ImageTargets.java for example; however, this part is just about Android programming and application logic (not Vuforia), so it is up to you how to implement that.

 

 
 
 

Java Heap Space Error in virtualButtons

April 4, 2013 - 10:36pm #16

Hi AlessandroB,

ok its Working.

When ever the image was capturing by camera then we have to show the 3d model. Then the animation part will effect. But model was going on toward to right and also if we showing the image again the 3d model was not appearing on the screen. when i did't placed the animation code in .cpp file then it showing when ever we showing the image then 3d model is appearing.

I think the 3d model was moving infinite loop how can stop 3d model object at particular distance.

And how can we integrate that one when ever touching the screen then only we have to move that 3d object.

Help me.

Thanks in advance.

 

Java Heap Space Error in virtualButtons

April 4, 2013 - 6:25am #15

Hi, if I understand correctly what you say, the second time you launch the app, the model is no longer there...

so, you need to reset the global translation values to zero;

one way you can do that is by defining a native function like the following (in ImageTargets.cpp):


JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_resetModelTranslation(
                            JNIEnv* env, jobject obj)
{
    targetCumulatedDisplacement.data[0] = 0.0f;
    targetCumulatedDisplacement.data[1] = 0.0f;
    targetCumulatedDisplacement.data[2] = 0.0f;
}

Then, declare the same function as a native method in Java (in ImageTargets.java):

private native void resetModelTranslation();

Then call the resetModeltranslation() in your onResume() method, for instance.

 

 

Java Heap Space Error in virtualButtons

April 4, 2013 - 6:11am #14

Hi AlessandroB,

Thanks,

Now It's working it moving from left to right but when we build and run then it will working.

if we run same apk it's not appearing 3d object on the screen.

what have to change for that.

Please help me.

Thanks in Advance.

Java Heap Space Error in virtualButtons

April 4, 2013 - 5:13am #13

Hi,

have you added SampleMath.cpp to your Android.mk file ?

you should see a line similar to this one:

LOCAL_SRC_FILES := ImageTargets.cpp SampleUtils.cpp Texture.cpp SampleMath.cpp

make sure that SampleMath.cpp is in the list.

 

Java Heap Space Error in virtualButtons

April 4, 2013 - 5:08am #12

Hi AlessandroB,

when i putting #include <math.h> in to cpp file that fabs error solved but when i build through ndk it showing following error:

C:/Users/ankush/Downloads/adt-bundle-windows-x86_64-20130219/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/VirtualButtons/VirtualButtons.o: in function computeTargetTranslationFromScreenVector:jni/VirtualButtons.cpp:371: error: undefined reference to 'SampleMath::Matrix44FInverse(QCAR::Matrix44F&)'

C:/Users/ankush/Downloads/adt-bundle-windows-x86_64-20130219/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/VirtualButtons/VirtualButtons.o: in function computeTargetTranslationFromScreenVector:jni/VirtualButtons.cpp:375: error: undefined reference to 'SampleMath::Vec3FTransformNormal(QCAR::Vec3F&, QCAR::Matrix44F&)'collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libVirtualButtons.so] Error 1

but i included that SampleMath.h file also.

Thanks in advance.

Java Heap Space Error in virtualButtons

April 4, 2013 - 4:28am #11

Hi,

the fabs() function is just s standard C function, perhaps you need to include this:

#include <math.h>

 

Java Heap Space Error in virtualButtons

April 4, 2013 - 4:24am #10

Hi,

That one i tried when i putting that code its showing SamplMath, fabs are not declared when i building ndk.

I found SampleMath.cpp and SampleMath.h file from videoplaback app but i don't found fabs one .

Is this correct way are wrong one.

Thanks in advance.

Java Heap Space Error in virtualButtons

April 4, 2013 - 4:07am #9

For inspiration, you can look at this tutorial which explains (with code) how to move an object from left to right, parallel to the screen plane.

https://developer.vuforia.com/forum/faq/opengl-how-can-i-move-my-3d-model-screen-plane

 

Java Heap Space Error in virtualButtons

April 4, 2013 - 3:48am #8

Hi AlessandroB,

Can we move 3d object one place to another place by coding.

Thanks in Advance.

Java Heap Space Error in virtualButtons

April 4, 2013 - 3:15am #7

Hi,

I go through your links but nothing happening. when i putting that code what he gave in https://developer.vuforia.com/resources/dev-guide/textured-plane-target this link. when i building ndk it asking to declare "trackable" how to declare that one.

if i changed that trackable to trackableResult when i running that virtual button applctaion it showing following errors.

could not find class 'android.hardware.Camera$CameraInfo'' referenced from methos Qualcomm.ar.pl.CameraPreview.getDirection

Please help me.

how come move 3d object left to right visversa.

Thanks in advance.

Java Heap Space Error in virtualButtons

April 4, 2013 - 1:08am #6

Hi, 

all the samples (VirtualButton, Image targets, etc.) contain some C++ code that manipulates matrices (typically in a function called "renderFrame", see for instance ImageTargets.cpp or VirtualButtons.cpp files), like the following:

 

SampleUtils::translatePoseMatrix

SampleUtils::scalePoseMatrix

etc.

Those functions allow to apply the transformations that you wish to have for your 3D objects (such as translation, scaling, etc.); 

note that the transformations are applied to the so-called "modelViewMatrix" which is the OpenGL transformation matrix that represents the position, orientation and scaling of the object reference frame with respect to the camera reference frame.

As you can see in the sample code, the modelViewMatrix is always set to the trackable Pose in the first place, and then subsequent translations and scaling (and optionally rotations too) are applied to it.

Some useful articles that I suggest you to read to clarify these concepts are:

https://developer.vuforia.com/resources/dev-guide/pose-matrix-explained

https://developer.vuforia.com/resources/dev-guide/positioning-3d-content

http://www.opengl.org/archives/resources/faq/technical/transformations.htm

The last one is about transformations in OpenGL, which is a MUST to initiate yourself to the world of 3D animation and transformations (in OpenGL).

 

 

Java Heap Space Error in virtualButtons

April 3, 2013 - 11:39pm #5

Hi AlessandroB,

can you give brief on moving 3d object in virtual button.

I am new to android and also vuforia.

Please help me.

Thanks in Advance.

Java Heap Space Error in virtualButtons

April 3, 2013 - 12:11am #4

Hi,

there might be other tools to get a header file from an OBJ file;

for instance, we have heard of a plugin for Blender (if you are using Blender as 3D modeling tool) that can export the Blender scene to a .h file:

http://ksolek.fm.interia.pl/Blender/

However, since this is beyond the scope of Vuforia, there might exist other tools that we are not aware of   (try searching the internet).

 

Concerning your second question (animations):

it depends a lot on the complexity of the animations you want to achieve;

if it is just about moving left/right and rotate around an axis, you could easily implement your own animations by tweaking the code in the renderFrame() function:

 QCAR::Matrix44F modelViewProjection;

        SampleUtils::translatePoseMatrix(0.f, 0.f, kObjectScale,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                     &modelViewMatrix.data[0]);

        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);

For more complex use cases, you will probably need to implement your own animation system, or consider using the Unity extension instead of programming on Android native.

 

Java Heap Space Error in virtualButtons

April 2, 2013 - 11:13pm #3

Hi AlessandroB,

Was there any other way to convert .obj file to .h file.

other than obj2openGLE.pl converter.

How can we add animations to banana or teapot images in virtual buttons.

like moving left/right/rotate.

Thanks in advance.

Java Heap Space Error in virtualButtons

April 1, 2013 - 7:48am #2

Hi, 

such a large file cannot be handled on a mobile device. 

You might split it into several smaller models, but performance-wise they might be difficult to render anyway at a decent frame rate.

Perhaps I would consider reducing the model complexity before exporting.

 

Log in or register to post comments