jPCT-AE - a 3d engine for Android > Support

Vuforia - Position and Rotate Objects with Model-View Matrix

(1/1)

Shizzn:
Hi guys,

I want to share my solution to the problem of positioning and rotating 3D-objects from jPCT-AE with OpenGLs Model-View Matrix (e.g. Vuforia tracking data) because I was asked to give help concerning this topic.
A picture of the Model-View Matrix and its components is attached. I created this picture as a part of my bachelor thesis.

A little warning:
I haven't used jPCT-AE with Vuforia for more than 2 years ;)
Furthermore, the code snippets are simpified.


You can get the Model-View Matrix by tracking markers with the Vuforia SDK. The tracking data will be used to show 3D-objects on the marker:

In the onDrawFrame-Method I apply the origin (position) of the Object3D-object via a SimpleVector by using the Translation-Vector of the Model-View Matrix

--- Code: ---mSimpleVector.set(modelViewMat[12], modelViewMat[13], modelViewMat[14]);
myObject.setOrigin(mSimpleVector);

--- End code ---

After that I apply the rotation by converting the Model-View-Matrix float-array to a RotationMatrix:

--- Code: ---myObject.setRotationMatrix(ArrayToMatrix(modelViewMat));

--- End code ---



--- Code: ---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;
}

--- End code ---


In my finished project I have a two-dimensional array of 16 Model-View 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 3D-Letters on the markers, so that the user can put them together to an existing word. (see the following YouTube-Link)

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 jPCT-AE with Vuforia for more than 2 years :D
If any important information is missing, please tell me.

Happy coding
Shizzn

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

Navigation

[0] Message Index

Go to full version