Hello,
I’m trying to calculate the bounding boxes of my objects. Four cubes.
If the cube is located at positive coordinates all is OK. If the object is located in a negative coordinate then the bounding box looks like the image below
[ATTACH=CONFIG]1441[/ATTACH]
Topleft cube is ok.
In the other cubes the negatives coordinates of the bounding box are changed to zero…why?
Inside the everyframe render method, this is the code when I arrange the matrix to rotate-translate the bounding box
....
....
float bbMatrix[]=new float[16];
Matrix.setIdentityM(bbMatrix,0);
Matrix.translateM(bbMatrix, 0, mesh.x, mesh.y, mesh.z);
Matrix.rotateM(bbMatrix, 0, mesh.ax, 1, 0, 0);
Matrix.rotateM(bbMatrix, 0, mesh.ay, 0, 1, 0);
Matrix.rotateM(bbMatrix, 0, mesh.az, 0, 0, 1);
Matrix.translateM(bbMatrix, 0, 0, 0, 0);
mesh.getBoundingBox().transformMinsAndMax(bbMatrix);
....
....
I pass the matrix to this method. The points of bounding box are rotated and the minimum and maximum coordinate values are calculated:
public void transformMinsAndMax(float[] vMatrixArray) {
float pointTransformed[]=new float[4];
Log.d(TAG,"yMin="+ymin+", yMax="+ymax);
for(int i=0;i<p.length;i++) {
Matrix.multiplyMV(pointTransformed, 0, vMatrixArray, 0, p[i].asFloat(), 0);
pc[i]=new Point(pointTransformed[0],pointTransformed[1],pointTransformed[2],1,1,0);
}
xmin=Float.MAX_VALUE;ymin=Float.MAX_VALUE;zmin=Float.MAX_VALUE;
xmax=Float.MIN_VALUE;ymax=Float.MIN_VALUE;zmax=Float.MIN_VALUE;
for(int i=0;i<p.length;i++) {
//x
if(pc[i].x<xmin){
xmin=pc[i].x;
}
if(pc[i].x>xmax){
xmax=pc[i].x;
}
...
...
p array contains the original points of the bounding box. The points are calculated one time when the cube is loaded.
p[i].asFloat return an array with the point coordinates (x,y,z,1)
pc array contains the bounding box points.
What is wrong? Can you help me please?
Thanks.