kitfox
Junior Member  
Java games rock!
|
 |
«
Posted
2005-11-01 21:59:37 » |
|
I'm having trouble extracting the frustum planes from a combined modelView and projection matrix. While the below code seems to work for perspective projections centered on the origin, when I shift the view to the right by 10 units, all of a sudden my planes are all skewed to the right. Shouldn't they have the same normals as before, and just have new offsets from the origin?
package com.kitfox;
import javax.vecmath.*;
import com.xith3d.scenegraph.*; import com.xith3d.spatial.bounds.*; /** * * @author kitfox */ public class ExtractPlanes { /** Creates a new instance of ExtractPlanes */ public ExtractPlanes() { }
public static void main(String[] args) { Transform3D projectionMtx = new Transform3D(); Transform3D modelView = new Transform3D(); Matrix4f modelViewProj = new Matrix4f(); Matrix4f identity = new Matrix4f(); identity.setIdentity(); Frustum frustum = new Frustum(); // xform.ortho(0, 4, 0, 4, 0, 4); //Perspective frustum centered on origin projectionMtx.perspective((float)Math.toRadians(90), 1, 1, 1000); modelView.setIdentity();
modelViewProj.set(modelView.getMatrix4f()); modelViewProj.mul(projectionMtx.getMatrix4f()); System.err.println("" + modelViewProj); frustum.extract(modelViewProj, identity); System.err.println("" + frustum);
//Perspective frustum shifted 10 units to the left projectionMtx.perspective((float)Math.toRadians(90), 1, 1, 1000); modelView.setIdentity(); modelView.setTranslation(new Vector3f(10, 0, 0));
modelViewProj.set(modelView.getMatrix4f()); modelViewProj.mul(projectionMtx.getMatrix4f()); System.err.println("" + modelViewProj); frustum.extract(modelViewProj, identity); System.err.println("" + frustum);
} }
|