Nadav
Posts: 3
Joined: Sat Nov 07, 2015 9:25 pm

pi3d "Stretch" Scale

Tue Mar 22, 2016 12:36 pm

Slideshow_3d.py scales the picture to "fit" proportionally at the screen resolution.
I am trying to add an option to display the images "stretched" to the screen resolution.

I only have experience with 2D scaling - 3D scaling is ++ much for me :)
Can someone please explain what values scale expects? (it looks like it is not a direct ratio of how much to scale-by)
Can someone please explain the need for tan & radians (original code posted below)?

Original Slideshow_3d.py code:

Code: Select all

    rat = 1.0 * DISPLAY.width / tex.ix / DISPLAY.height * tex.iy
    if rat > 1.0:
      rat = 1.0
    rat *= 1000.0 * tan(radians(CAMERA.lens[2] / 2.0))
    wi, hi = tex.ix / tex.iy * rat, rat
    slide.set_draw_details(shader,[tex])
    slide.scale(wi, hi, 1.0)

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: pi3d "Stretch" Scale

Thu Mar 24, 2016 9:57 pm

I will give you a complete explanation when I get home (using phone now so very slow) but 1 the trig is simply aiming to make a quadrilateral that fills the screen at the starting distance. 2 to stretch the image to screen proportions you need something like
wi, hi = DISPLAY.width * factor, DISPLAY.height * factor
Where factor is based on similar calc involving tan etc.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: pi3d "Stretch" Scale

Tue Mar 29, 2016 3:54 pm

Sorry for the delay, this seems to work

Code: Select all

    tex = pi3d.Texture(fname, blend=True, mipmap=True) #nicer but slower 3.3MB in 4.5s
    rat = 1000.0 * tan(radians(CAMERA.lens[2] / 2.0))
    wi, hi = (DISPLAY.width  * rat) / DISPLAY.height, rat
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Nadav
Posts: 3
Joined: Sat Nov 07, 2015 9:25 pm

Re: pi3d "Stretch" Scale

Wed Apr 06, 2016 7:52 pm

Thanks so much for the working code!
(I don't have any experience in 3D work, so the "tan" & "radians" are a complete mystery to me)

Return to “Graphics programming”