Thank you AeroShark333 and EgonOlsen for your time.
As I am new to JPCT and 3D programming it will take some more time for me to understand these components.
I had searched on this forum and found some code related to my problem as below:
private Point[] get2DVertices(SimpleVector[] vertices3d, Camera theCamera, FrameBuffer buffer) {
Point[] vertices = new Point[vertices3d.length];
for (int i = 0; i < vertices.length; i++) {
SimpleVector point = Interact2D.project3D2D(theCamera, buffer, vertices3d[i]);
vertices[i] = new Point((int)(point.x+.5f), (int)(point.y+.5f));
}
return vertices;
}
public float[] get2DBounds(Camera theCamera, FrameBuffer buffer) {
System.out.println("get2DBounds");
object3D.enableLazyTransformations();
PolygonManager polyManager = object3D.getPolygonManager();
SimpleVector[] vertices3d = new SimpleVector[polyManager.getMaxPolygonID()*3];
int currentPoly = 0;
int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, minZ = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE, maxZ = Integer.MIN_VALUE;
for (int i = 0; i < vertices3d.length; i+=3) {
vertices3d[i] = polyManager.getTransformedVertex(currentPoly, 0);
vertices3d[i+1] = polyManager.getTransformedVertex(currentPoly, 1);
vertices3d[i+2] = polyManager.getTransformedVertex(currentPoly++, 2);
}
Point[] vertices = this.get2DVertices(vertices3d, theCamera, buffer);
for (int i = 0; i < vertices.length; i+=3) {
if (minX > vertices[i].x)
minX = vertices[i].x;
if (minX > vertices[i+1].x)
minX = vertices[i+1].x;
if (minX > vertices[i+2].x)
minX = vertices[i+2].x;
if (maxX < vertices[i].x)
maxX = vertices[i].x;
if (maxX < vertices[i+1].x)
maxX = vertices[i+1].x;
if (maxX < vertices[i+2].x)
maxX = vertices[i+2].x;
if (minY > vertices[i].y)
minY = vertices[i].y;
if (minY > vertices[i+1].y)
minY = vertices[i+1].y;
if (minY > vertices[i+2].y)
minY = vertices[i+2].y;
if (maxY < vertices[i].y)
maxY = vertices[i].y;
if (maxY < vertices[i+1].y)
maxY = vertices[i+1].y;
if (maxY < vertices[i+2].y)
maxY = vertices[i+2].y;
}
object3D.disableLazyTransformations();
// return new float[](minX, minY, (int)Math.abs(maxX-minX), (int)Math.abs(maxY-minY));
return new float[]{minX, minY, maxX, maxY};
}
This code goes over my mind..
I think this one is the second solution as discussed by AeroShark333 and EgonOlsen.
But this code is quite expensive to run multiple times. It takes about 2 seconds to execute. May be there is another way for this method.
I even tried FOV method as below:
double height = Math.max(getSize(object3D).x, getSize(object3D).z);
double fov = world.getCamera().getFOV();
double distance =(height/2)/Math.tan(fov/2);
world.getCamera().setPosition(0,0,-distance);
But this gave wired results.
May be this method has something to do with type of camera.
I know I donot have concepts on 3D programming but I am trying to learn. It will take some time for me.
Thank you for your support.