project3D2D runtime errror

Started by neo187, October 11, 2011, 12:06:56 PM

Previous topic - Next topic

neo187

Hey Egon

I can't find a way to get round this.... So I'm using Interact2D.project3D2D to calculate the screen coordinates of a 3D object, and if those coordinates are inside the frameBuffer I blit a 2D image on it....

As I move around the world and the object falls far behind the camera, this check inevitably gives a NullPointerexception and a runTime error, right about when the coordinates get towards 20000 or 20000.... I am not blitting anything at those coordinates, the runtime error comes only from the check:

SimpleVector v = ew.getLightPos(frameBuffer);
System.out.println("" + v.x + ", " + v.y + "panel: " + this.renderPanel.getWidth());
if(v.x < this.renderPanel.getWidth() && v.y < this.renderPanel.getHeight()){
  frameBuffer.blit(bulb, 0, 0, (int) v.x, (int) v.y, 128, 128, 50, 50, 10, false, null);
}


The runtime error points at the third line.


public SimpleVector getLightPos(FrameBuffer fb){
SimpleVector arr = Interact2D.project3D2D(camera, fb, lights.elementAt(selectedLight).getPosition());
return arr;
}


Anything springs to mind?

Exception in thread "main" java.lang.reflect.InvocationTargetException
   at java.awt.EventQueue.invokeAndWait(Unknown Source)
   at javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
   at Editor.loop(Editor.java:229)
   at Editor.main(Editor.java:543)
Caused by: java.lang.NullPointerException
   at Editor.render(Editor.java:206)
   at Editor$2.run(Editor.java:240)
   at java.awt.event.InvocationEvent.dispatch(Unknown Source)
   at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
   at java.awt.EventQueue.access$000(Unknown Source)
   at java.awt.EventQueue$1.run(Unknown Source)
   at java.awt.EventQueue$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)}

EgonOlsen

That's by design. You can't project a point into 2D that lies behind the camera. It's not defined, so the method returns null. Like the docs say: "Returns null if the transformation can't be done (i.e. the vertex is behind the viewplane)."

neo187

brilliant. A check for a null values solved it... I really hand't seen that in the DOCs.... Thanks for your prompt help!

EgonOlsen

Yes, it's difficult to spot in the docs...i'll change that.