Questions about scaling, camera and screen size

Hi,

I would like to do the following: I would like to make an intro animation where a filled 2D square comes from the background “flying” into the front. The 2D square should fill out the window completly at the end. This 2D plane is then used to display title, author, date and such stuff. After showing this data the 2D “flys” back into the background and disappears at the horizont (give or take X various effects :wink: )

To do so I need to find out when the 2D plane fills out completly the window to stop there. Currently I can “guess” it out, finding the right scaling and positioning dependent on the screen size manually (try and error).

But thats probably silly, and it brings me to the point that I don’t know the basics how the scaling within the 3D world and the corresponding mapping into the “Windows Window” is done. Haven’t found any documentation about it, maybe I’ve taken the wrong keywords.

I see two approaches:

  • I could try to find out how large the 2d square is in pixels - and if the pixel size is the same than the screen resolution then it probably fits :wink:
  • I could have a abstract approach like "set the camera to 0,0,0 and the 2d screen to 0,-0.01,0 and the 2d screen widht and height to X & Y then the screen is filled…

For the last approach I haven’t any idea or function how to find out what “X” and “Y” would be correct - besides finding it out manually.

Arg… I bet I have big misunderstanding or knot in my brain…

Any pointers would be very helpful…

Andrew

Andrew, the simple answer to 3D scaling is that an object that is twice as far away covers half the width/height on the screen. So if the object only fills the screen halfway across you need to move it to exactly half the distance.

You can figure out the exact distance directly using basic trigonometry. The projection of the right (or left) half of an object with a width of W at distance D will fill a half field-of-view (FOV) angle of A according to the equation

tan(A) = (W/2) / D

so solving for D gives

D = (W/2) / tan(A)

Remember that this is only half of the FOV, so take whatever FOV you are using with your camera and divide by two before plugging in for A. W is just the full width of the 2D rectangle. The same equation will work for object height and vertical FOV, but you’ll probably need to decide whether to fill the screen vertically or horizontally unless you use and object that matches the aspect ratio of the window exactly.

To keep things simple it would probably be best to put your camera at the origin, looking down Z as you said, and keep the 2D rectangle also centered on the Z axis as well.

Hi Arkaein,

thanks for the reply. I understood basically what’ve wrote (I haven’t dealt with sin, cos and tan since 15 years… :wink: ) and I tried to implement it.

But I have now another very basic question: what is the size (width, depht, lenght) of an object? As I tried out your formula with various objects (.egg files) I found out that ScaleX, ScaleY and ScaleZ seems to be relative to the original size defined in the .egg file.

I haven’t found a method to define or find out the absolute size of an object. Having a 3d surface of course there is no “this is size X,Y,Z” - but if one draws a box around an object you get the maximum X, Y and Z values.

Any ideas?

Regards,
Andrew

Andrew, according to the manual entry for the pview utility you can load a model and press Shift-B to report the model’s bounding volume:

panda3d.org/manual/index.php/Previ … s_in_Pview

Make sure to adjust for any scaling you apply to the base model.

Panda has some commands to get the bounding volume of an object…
Some of them are used with collision detection, so take a look at the manual there.

But doesn’t Panda have commands to draw your own polygons?

I think your best bet is to create a new 3D camera specifically for this purpose. You can intentionally set the aspect ratio of the camera to 1:1, and set the viewing angle to 90 degrees, just to make the math simple. That way, an object that’s 1 unit from the camera, and 2x2 units in size, will exactly fill the screen.