|
Hello everyone, I've been having difficulty writing Behaviors that Manipulate the View's Transform. I use such behaviors extensively in order to manage the camera's movement in our games that are written for one of our Java3D based Engines. The problem is that if I run some of my demos for a little while, eventually the engine crashes and I get the following error: Exception occurred during Behavior
execution: As I mentioned can happen at any point. As a matter of fact, some of my demos can run perfectly without any problem. I have noticed that this occurs when the camera transform is rotating. For this matter, I left a small chance that the difficulty is related to floating point miscalculations. I finally got the chance to try to troubleshoot this problem and after testing many different cases, I realize that in some cases, there can be a Matrix4f that can be applied to an object without any difficulty, but when the very same Matrix (4f) is applied to the View Platform, the exception is thrown. In order to illustrate this scenario, I have implemented a sample app named TestUniverse that can apply a matrix to an Object's transform, or the ViewPlatform's transform. Pressing the key "S" cause the app to set the object's transform, and "C" cause the app to the ViewPlatform's transform. As you will be able to see, only the second scenario causes an exception to be thrown. In order to get a Matrix with these special values, I ran one of my demos for about 5 min and recorded the transform's data that cause the Engine to crash. Here is the transform:
1.0,
0.0,
0.0,
0 If the above data reveal an obvious problem, please let me know what is going on. If the problem is not too obvious, you should run the attached app. Please let me know if this is a BUG (or maybe floating point miscalculation, or ....). We are intending to show some of our student's projects at E3, so this problem has the highest priority on my list. I thank you in advanced, Take Care, - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - http://www.fullsail.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
/**
* Syrus Mesdaghi [EMAIL PROTECTED]
*
* This app shows a case where the values of a Matrix4f can be safely inserted into a object's Transform,
* but can cause a non-congruent transform above ViewPlatfor.
*
*/
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.Frame;
public class TestUniverse implements KeyListener{
public SimpleUniverse u;
public TransformGroup objTrans;
public BranchGroup objRoot;
private TestUniverse(){
Frame frame = new Frame();
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
frame.add(c);
frame.setSize(256,256);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
frame.addKeyListener(this);
c.addKeyListener(this);
objRoot = new BranchGroup();
objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);
objTrans.addChild(new ColorCube(0.4));
u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(objRoot);
System.out.println("Press S to set the Object's transform");
System.out.println("Press R to RESET the Object's transform");
System.out.println("Press c to set the View's transform");
frame.show();
}
public static void main(String[] args) {
new TestUniverse();
}
public void keyReleased(KeyEvent e){
if (e.getKeyCode() == KeyEvent.VK_C ){
Transform3D t3d = new Transform3D();
Matrix4d m = new Matrix4d();
m.m00 = 1.0; m.m01 = 0.0; m.m02 = 0.0; m.m03 = 0;
m.m10 = 0.0; m.m11 = 0.20792245864868164; m.m12 = 0.9781964421272278; m.m13 = 0;
m.m20 = 0.0; m.m21 = -0.9781964421272278; m.m22 = 0.20792245864868164; m.m23 = 0;
m.m30 = 0.0; m.m31 = 0.0; m.m32 = 0.0; m.m33 = 1.0;
System.out.println("====>> About to set Camera's Transform");
u.getViewingPlatform().getViewPlatformTransform().getTransform(t3d);
t3d.set(m);
u.getViewingPlatform().getViewPlatformTransform().setTransform(t3d);
}
if (e.getKeyCode() == KeyEvent.VK_S ){
Transform3D t3d = new Transform3D();
Matrix4d m = new Matrix4d();
m.m00 = 1.0; m.m01 = 0.0; m.m02 = 0.0; m.m03 = 0;
m.m10 = 0.0; m.m11 = 0.20792245864868164; m.m12 = 0.9781964421272278; m.m13 = 0;
m.m20 = 0.0; m.m21 = -0.9781964421272278; m.m22 = 0.20792245864868164; m.m23 = 0;
m.m30 = 0.0; m.m31 = 0.0; m.m32 = 0.0; m.m33 = 1.0;
/* m.m00 = 1.0f; m.m01 = 0.0f; m.m02 = 0.0f; m.m03 = 0;
m.m10 = 0.0f; m.m11 = 0.20792245864868164f; m.m12 = 0.9781964421272278f; m.m13 = 0;
m.m20 = 0.0f; m.m21 = -0.9781964421272278f; m.m22 = 0.20792245864868164f; m.m23 = 0;
m.m30 = 0.0f; m.m31 = 0.0f; m.m32 = 0.0f; m.m33 = 1.0f;
*/
System.out.println("====>> About to set Object's Transform");
objTrans.getTransform(t3d);
t3d.set(m);
objTrans.setTransform(t3d);
}
if (e.getKeyCode() == KeyEvent.VK_R ){
Transform3D t3d = new Transform3D();
Matrix4f m = new Matrix4f();
m.setIdentity();
System.out.println("====>> About to Reset Object's Transform");
objTrans.getTransform(t3d);
t3d.set(m);
objTrans.setTransform(t3d);
}
}
public void keyTyped(KeyEvent e){}
public void keyPressed(KeyEvent e){}
}
