Puzzled by Project3D2D

Started by Hrolf, September 26, 2008, 05:02:51 PM

Previous topic - Next topic

Hrolf

I can't work this one out at all...


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?  ???

Melssj5

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

Hrolf

Quote from: Melssj5 on September 26, 2008, 05:28:29 PM
The project3D2D returns null or are you getting a NullPointerException??
It returns null...

This gets stranger - if I try;
SimpleVector svp=Interact2D.project3D2D(camera,frameBuffer,new SimpleVector(0,0.0000001,0));
I get the frameBuffer center, but if I try;
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!


Melssj5

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

EgonOlsen

Quote from: Melssj5 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?
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.

Hrolf

Here's (part of) the buffer showing spheres at the origin and on the x,y,z axes;

but
SimpleVector svp=Interact2D.projectCenter3D2D(renderBuffer,originSphere);
and
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?

Hrolf

Think I've got it - the scene has to be rendered at least once for the method to work...
Seems to work ok now!

EgonOlsen

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... ;)

Hrolf

Quote from: EgonOlsen 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... ;)
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!  ;)

EgonOlsen