Author Topic: Puzzled by Project3D2D  (Read 6160 times)

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Puzzled by Project3D2D
« on: September 26, 2008, 05:02:51 pm »
I can't work this one out at all...

Code: [Select]
camera.setPosition(new SimpleVector(0,-100,100));
camera.lookAt(new SimpleVector(0,0,0));
world.setCameraTo(camera);
SimpleVector svp=Interact2D.project3D2D(camera,frameBuffer,new SimpleVector(0,0,0));

I expected svp to contain the center of the frameBuffer, but it returns 'null'.
What am I doing wrong?  ???

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: Puzzled by Project3D2D
« Reply #1 on: September 26, 2008, 05:28:29 pm »
The project3D2D returns null or are you getting a NullPointerException??

The project3D2S on the form you are calling projects a vertex from the world coordinates to the screen. are you sure you hace a vertex on 0,0,0 to be projected?
Nada por ahora

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Puzzled by Project3D2D
« Reply #2 on: September 26, 2008, 05:41:42 pm »
The project3D2D returns null or are you getting a NullPointerException??
It returns null...

This gets stranger - if I try;
Code: [Select]
SimpleVector svp=Interact2D.project3D2D(camera,frameBuffer,new SimpleVector(0,0.0000001,0));I get the frameBuffer center, but if I try;
Code: [Select]
SimpleVector svp=Interact2D.project3D2D(camera,frameBuffer,new SimpleVector(0,-0.0000001,0));I get svp==null!

I know everything's set up right because if I put an Object3D at 0,0,0 it renders correctly. It's a mystery to me!


Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: Puzzled by Project3D2D
« Reply #3 on: September 26, 2008, 05:45:13 pm »
The javadoc says:

Returns null if the transformation can't be done (i.e. the center is behind the viewplane)

Is the object visible when rendering and when trying to project its vertex?
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Puzzled by Project3D2D
« Reply #4 on: September 26, 2008, 06:47:19 pm »
The javadoc says:

Returns null if the transformation can't be done (i.e. the center is behind the viewplane)

Is the object visible when rendering and when trying to project its vertex?
Yes, that's exactly what happens here. Except that the object itself doesn't matter. The view plane is your screen, i.e. z coordinate 0. Everything lower than 0 is in front of the screen (virtually). You can't project that onto the screen correctly. That's why null will be returned.

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Puzzled by Project3D2D
« Reply #5 on: September 26, 2008, 06:56:18 pm »
Here's (part of) the buffer showing spheres at the origin and on the x,y,z axes;

but
Code: [Select]
SimpleVector svp=Interact2D.projectCenter3D2D(renderBuffer,originSphere);and
Code: [Select]
SimpleVector svp=Interact2D.project3D2D(camera,frameBuffer,new SimpleVector(0,0,0));both return null!

The sphere is clearly on screen so why doesn't projectCenter3D2D or project3D2D give me the screen co-ords?

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Puzzled by Project3D2D
« Reply #6 on: September 26, 2008, 08:13:24 pm »
Think I've got it - the scene has to be rendered at least once for the method to work...
Seems to work ok now!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Puzzled by Project3D2D
« Reply #7 on: September 26, 2008, 08:19:19 pm »
Looking at the code, you may be right. A call to camera.copyBackToFront() should work too. Could you please test this? If it works, i'm going to change the code to work right from the beginning. I'm using the camera's front matrix (the one that has been used for the last render) within this method...i think i remember what i had in mind when doing this...but i also think that this is bulls**t... ;)

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Puzzled by Project3D2D
« Reply #8 on: September 26, 2008, 09:24:34 pm »
Looking at the code, you may be right. A call to camera.copyBackToFront() should work too. Could you please test this? If it works, i'm going to change the code to work right from the beginning. I'm using the camera's front matrix (the one that has been used for the last render) within this method...i think i remember what i had in mind when doing this...but i also think that this is bulls**t... ;)
Yup, camera.copyBackToFront() does it too!
It would be better if project3D2D worked 'out of the box', but just a mention of this issue in the docs would be easier!  ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Puzzled by Project3D2D
« Reply #9 on: September 26, 2008, 09:57:54 pm »
Ok, i'll change this for 1.17.