Drawing a frustum

Just wondering if anyone has code for drawing a camera frustum. If not does anyone have any idea how to construct the points needed for displaying a frustum based on the methods available? Im a bit fuzzy at this point on how to get the points via the getFrustumLeft/Right/Near/Far etc methods.



Thanks in advance.

first here is a method that creates a frustum from a, array of vector3f.



private Geometry createFrustum(Vector3f[] pts,AssetManager assetManager){

WireFrustum frustum = new WireFrustum(pts);

Geometry frustumMdl = new Geometry(“f”, frustum);

frustumMdl.setCullHint(Spatial.CullHint.Never);

frustumMdl.setShadowMode(ShadowMode.Off);

frustumMdl.setMaterial(new Material(assetManager, “Common/MatDefs/Misc/WireColor.j3md”));

frustumMdl.getMaterial().setColor(“m_Color”, ColorRGBA.White);



return frustumMdl;

}



then, to build the array you can use the ShadowUtil.updateFrustumPoints2(viewCam, points), where viewCam is your cam and points an Array of 8 Vector3f in which the result will be stored

Thanks nehon that seems to be working. The reason I want to show the frustum is that Im trying to implement a multiple object picker. You know the usual drag a box on the screen and select all units under that box. I’m building a perspective camera then colliding the frustum against the scene to see who’s inside.



For some reason though my frustum is stretched far to the right. Here’s basically what Im doing.



[java]

// Get the size of the selection box from screen space co-ords

Vector2f[] points = box.getPoints();

Vector2f size = points[1].subtract(points[0]);



// Get the center of the box in screen space

Vector2f center = new Vector2f(size.getX(),size.getY());

center.scale(0.5f);

center = center.add(points[0]);



Camera viewingCamera = getCamera();

Camera pickingCamera = createCamera();

pickingCamera.resize((int)size.getX(),(int)size.getY());

pickingCamera.setFrustumPerspective(90f, size.getX()/size.getY(),1.0f, 500.0f);

pickingCamera.setXYZ(viewingCamera.getWorldCoords(center,500.0f)); // The center of the box in world space

pickingCamera.setUp(viewingCamera.getUp()); // Same as the viewing camera

pickingCamera.setDirection(viewingCamera.getDirection());// Same as the viewing camera

pickingCamera.setLeft(viewingCamera.getLeft());// Same as the viewing camera



// collide picking camera against the scene

[/java]

The only weird thing that i see here is the 90f fovy angle.

look at this thread : http://www.gamedev.net/community/forums/topic.asp?topic_id=512105&whichpage=1&

it seems that a 90° fov result in distortions…try a 45° fov and see if it helps.



Maybe, you should look at the ShadowUtil class. There are some convenient methods that helps to determine if an object bounding box is in a frustum.

Of course it’s for shadow purpose, but it can give you some ideas about what you are trying to do

I figured this out. It seems a frustum is not “ready” until it’s camera has been assigned to the renderer via setCamera(). I’m just working on the fine details and will post a snippet for others that want an efficient drag select box which uses frustum culling. This is great when you have a large number of objects to test against.