www.jpct.net
jPCTAE  a 3d engine for Android => Support => Topic started by: Shizzn on December 21, 2015, 08:37:04 pm

Hi guys,
I want to share my solution to the problem of positioning and rotating 3Dobjects from jPCTAE with OpenGLs ModelView Matrix (e.g. Vuforia tracking data) because I was asked to give help concerning this topic.
A picture of the ModelView Matrix and its components is attached. I created this picture as a part of my bachelor thesis.
A little warning:
I haven't used jPCTAE with Vuforia for more than 2 years ;)
Furthermore, the code snippets are simpified.
You can get the ModelView Matrix by tracking markers with the Vuforia SDK. The tracking data will be used to show 3Dobjects on the marker:
In the onDrawFrameMethod I apply the origin (position) of the Object3Dobject via a SimpleVector by using the TranslationVector of the ModelView Matrix
mSimpleVector.set(modelViewMat[12], modelViewMat[13], modelViewMat[14]);
myObject.setOrigin(mSimpleVector);
After that I apply the rotation by converting the ModelViewMatrix floatarray to a RotationMatrix:
myObject.setRotationMatrix(ArrayToMatrix(modelViewMat));
protected Matrix ArrayToMatrix(float array[]) {
// Declare variables
float[] insertDump = new float[16]; // The array holding the values in
// the new Matrix
int targetElement = 0; // Points to the next location in the insertDump
// to add data
// Loop through the rows of the Matrix3f
for (int sourceRow = 0; sourceRow < 3; sourceRow++) {
// Insert the 3 elements from the Matrix3f into the Matrix. The
// fourth element has been initialized to 0.0f.
insertDump[targetElement] = array[targetElement];
insertDump[targetElement + 1] = array[targetElement + 1];
insertDump[targetElement + 2] = array[targetElement + 2];
// Move the target ahead by four spaces
targetElement += 4;
}
// The final row consists of { 0.0f, 0.0f, 0.0f, 1.0f }, since this is a
// rotation matrix
insertDump[15] = 1.0f;
// Create the new Matrix and load in the values
Matrix output = new Matrix();
output.setDump(insertDump);
// Return
return output;
}
In my finished project I have a twodimensional array of 16 ModelView Matrices, so I can place 3DObjects on up to 16 Vuforia Markers. That's why my original code would be too complicated.
My project, which I developed as a part of my bachelor thesis, shows 3DLetters on the markers, so that the user can put them together to an existing word. (see the following YouTubeLink)
https://www.youtube.com/watch?v=NdI_7Ky8XTs (https://www.youtube.com/watch?v=NdI_7Ky8XTs)
If you have more questions concerning that topic, you can ask me. But I have to repeat my warning: I haven't used jPCTAE with Vuforia for more than 2 years :D
If any important information is missing, please tell me.
Happy coding
Shizzn

Thanks for sharing this. I made the topic sticky, so that it's easier to find for those who follow.