Author Topic: 3D Model shows up before finding the imagetarget from vuforia  (Read 2974 times)

Offline angelo

  • byte
  • *
  • Posts: 5
    • View Profile
3D Model shows up before finding the imagetarget from vuforia
« on: November 13, 2013, 10:56:30 pm »
Hi,

Im a bit of a beginner with jpct-ae.  Im just having a problem with the 3D model that loads up and blocks the camera. Could it be because of the size?  Im trying to integrate it with vuforia. if the model is small i dont have a problem.  The thing is, if it didnt find the image target from vuforia yet, then the 3D model shouldnt show up yet, please correct me if im wrong.

it only becomes a problem if i change the size using mainBody.scale(2);

If im wrong could you help me with the code to remove or delay the 3D object from showing up if it didnt find the image target yet.

THanks so much!

------------------------------------------------------------------------------------------------------------

Solved it. but if someone has a better way, please share. Thanks

Code: [Select]
//ImageTargets.cpp
JNIEXPORT void JNICALL
Java_com_theoretics_ToyotaAR_ImageTargetsRenderer_renderFrame(JNIEnv *env, jobject obj)
{

const QCAR::CameraCalibration& cameraCalibration = QCAR::CameraDevice::getInstance().getCameraCalibration();
QCAR::Vec2F size = cameraCalibration.getSize();
QCAR::Vec2F focalLength = cameraCalibration.getFocalLength();
float fovyRadians = 2 * atan(0.5f * size.data[1] / focalLength.data[1]);
float fovRadians = 2 * atan(0.5f * size.data[0] / focalLength.data[0]);
float trackableIndex = 0;

jclass activityClass = env->GetObjectClass(obj);
jfloatArray modelviewArray = env->NewFloatArray(16);
jmethodID updateMatrixMethod = env->GetMethodID(activityClass, "updateModelviewMatrix", "([F)V");

jmethodID fovMethod = env->GetMethodID(activityClass, "setFov", "(F)V");
jmethodID fovyMethod = env->GetMethodID(activityClass, "setFovy", "(F)V");
jmethodID trackableIDMethod = env->GetMethodID(activityClass, "setTrackableId", "(F)V");


// test
jclass newClass = env->GetObjectClass(obj);
jmethodID updateCameraMethod = env->GetMethodID(newClass, "updateCamera", "()V");

// Clear color and depth buffer
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Get the state from QCAR and mark the beginning of a rendering section
QCAR::State state = QCAR::Renderer::getInstance().begin();
// Explicitly render the Video Background
QCAR::Renderer::getInstance().drawVideoBackground();
// Did we find any trackables this frame?
for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
{
// Get the trackable:
const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
const QCAR::Trackable& trackable = result->getTrackable();
// const QCAR::ImageTarget& imageTarget = (const QCAR::ImageTarget&) trackableResult->getTrackable();
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());

if (strcmp(trackable.getName(), "pg1") == 0)
{
trackableIndex = 5;
}
else if (strcmp(trackable.getName(), "pg2") == 0)
{
trackableIndex = 6;
}
else
{
trackableIndex = 7;
}
}
QCAR::Renderer::getInstance().end();

for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
{
// Get the trackable:
const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
const QCAR::Trackable& trackable = result->getTrackable();
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());

SampleUtils::rotatePoseMatrix(180.0f, 1.0f, 0, 0, &modelViewMatrix.data[0]);
// Passes the model view matrix to java
env->SetFloatArrayRegion(modelviewArray, 0, 16, modelViewMatrix.data);
env->CallVoidMethod(obj, updateMatrixMethod , modelviewArray);
env->CallVoidMethod(obj, updateCameraMethod);
env->CallVoidMethod(obj, fovMethod, fovRadians);
env->CallVoidMethod(obj, fovyMethod, fovyRadians);
env->CallVoidMethod(obj, trackableIDMethod, trackableIndex);

}
if(state.getNumTrackableResults() == 0){
env->CallVoidMethod(obj, trackableIDMethod, 8);
}
env->DeleteLocalRef(modelviewArray);

}

//ImageTargetsRenderer.java
public void setTrackableId(float tid_) {
System.out.println("ANGELO TRACKABLE ID:" + tid_);
tid = tid_;
if (tid == 5.0f) {
innerCab.setVisibility(true);
seats.setVisibility(true);
} else
innerCab.setVisibility(false);
seats.setVisibility(false);
}


the innerCab and seats of the car was blocking the camera
« Last Edit: November 14, 2013, 05:22:51 am by angelo »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 3D Model shows up before finding the imagetarget from vuforia
« Reply #1 on: November 14, 2013, 07:49:47 am »
I didn't really understand the problem here, but if it's solved... ;)

Offline angelala

  • byte
  • *
  • Posts: 4
    • View Profile
Re: 3D Model shows up before finding the imagetarget from vuforia
« Reply #2 on: November 15, 2013, 07:27:23 am »
How do you code for the multiple markers, multiple object? I can only render 1 object on a marker.
Can you share your code here?
thanks

Offline angelo

  • byte
  • *
  • Posts: 5
    • View Profile
Re: 3D Model shows up before finding the imagetarget from vuforia
« Reply #3 on: November 15, 2013, 09:00:51 pm »
The code is already there... in fragments ;)

Offline angelala

  • byte
  • *
  • Posts: 4
    • View Profile
Re: 3D Model shows up before finding the imagetarget from vuforia
« Reply #4 on: November 18, 2013, 01:53:43 am »
How about the code in java side? I cannot pass the model to render on the marker.
Thanks