Author Topic: project3D2D runtime errror  (Read 1337 times)

Offline neo187

  • int
  • **
  • Posts: 73
    • View Profile
project3D2D runtime errror
« on: October 11, 2011, 12:06:56 pm »
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:
Code: [Select]
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.

Code: [Select]
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)}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: project3D2D runtime errror
« Reply #1 on: October 11, 2011, 12:24:22 pm »
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)."

Offline neo187

  • int
  • **
  • Posts: 73
    • View Profile
Re: project3D2D runtime errror
« Reply #2 on: October 11, 2011, 01:53:22 pm »
brilliant. A check for a null values solved it... I really hand't seen that in the DOCs.... Thanks for your prompt help!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: project3D2D runtime errror
« Reply #3 on: October 11, 2011, 02:11:40 pm »
Yes, it's difficult to spot in the docs...i'll change that.