Author Topic: Screen skew?  (Read 7204 times)

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1810
    • View Profile
Screen skew?
« on: 2015-Oct-02 »
Hi Guys

Anyone ever do a virtual screen with skew so that bottom or top section of the screen is wider than the other?

It's for a fake persective effect I am thinking about...would Polyvector accomplish this?

G

Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1810
    • View Profile
Re: Screen skew?
« Reply #1 on: 2015-Oct-08 »
Bump!

Guys I tried this with a Polyvector but triangular working of the command make the image wonky instead of skewed...where adjust is an amount I want to skew the image...
...Any ideas?

Code: (glbasic) [Select]
  STARTPOLY 99
   POLYVECTOR adjust,0,0,0,0xFFFFFF
   POLYVECTOR 0,0+ssy,0,basey,0xFFFFFF
   POLYVECTOR 0+ssx,0+ssy,basex,basey,0xFFFFFF
   POLYVECTOR 0+ssx-adjust,0,basex,0,0xFFFFFF
  ENDPOLY

« Last Edit: 2015-Oct-08 by MrPlow »
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4450
    • View Profile
    • FUED
Re: Screen skew?
« Reply #2 on: 2015-Oct-08 »
You could also map your image to a 3d plane to achieve that.

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1810
    • View Profile
Re: Screen skew?
« Reply #3 on: 2015-Oct-08 »
Thanks Erico but I need to avoid the 3D commands - pseudo effect needed only...
:)
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4450
    • View Profile
    • FUED
Re: Screen skew?
« Reply #4 on: 2015-Oct-08 »
With polyvector, what if you add more points to each side of the square? like 4 points per side.
Won´t the wonky effect go away? just a loose shot here.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4176
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Screen skew?
« Reply #5 on: 2015-Oct-08 »
Here's an example that doesn't quite work. It seems fine for a short while, but then fails miserably.

Code: (glbasic) [Select]
SETSCREEN 640,480,0

// Create character sprite
CREATESCREEN 1,50,32,32

USESCREEN 1

DRAWRECT 0,0,32,32,RGB(255,255,255)

// Create virtual screen
CREATESCREEN 2,100,640,480

LOCAL x%=320, y%=400, dir%=0

WHILE TRUE

USESCREEN 2

DRAWRECT 0,0,640,480,RGB(0,0,128)

DRAWSPRITE 50,x,y


// Move char
IF dir=0 THEN INC x,2
IF dir=1 THEN  DEC x,2

// Limit char
IF x>608 AND dir=0 THEN dir=1
IF x<0 AND dir=1 THEN dir=0

USESCREEN -1

 STARTPOLY 100
  POLYVECTOR 540,0, 640,0
  POLYVECTOR 100,0, 0,0
  POLYVECTOR 0,480, 0,480
  POLYVECTOR 640,480, 640,480
 ENDPOLY

 SHOWSCREEN

WEND
I came. I saw. I played.

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1810
    • View Profile
Re: Screen skew?
« Reply #6 on: 2015-Oct-09 »
Yep Ian!
My attempt was the same - the poly cuts through the screen at a diagonal - like 2 triangles of the screen are being merged or something...

Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Offline UBERmonkeybot

  • Mr. Polyvector
  • ***
  • Posts: 243
    • View Profile
Re: Screen skew?
« Reply #7 on: 2015-Oct-10 »
you can really see that effect if you increase the height of the box.


Offline Qedo

  • Dr. Type
  • ****
  • Posts: 382
  • to program what I have do how should programming?
    • View Profile
Re: Screen skew?
« Reply #8 on: 2016-Jan-06 »
Hi
 i have prepared an example. It is not perfect but work.
Simply the initial polygon is divided into sub polygons. For defaul 256, 16 rows x16 columns but you can change it by modifing the variable division_n=4 (4^4) to another value. Caution higher values increase the number of polygons with growing power of 4. Subsequently POLYVECTOR fills
You can use it  and any improvement and optimization is welcome.
It considers that still needs to be finished.
It is a starting point
let me know.
Ciao
Qedo
P.S. Remember to move the 4 Whitecheckpoint.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4176
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Screen skew?
« Reply #9 on: 2016-Jan-06 »
That's not correct either - there's an awful lot of distortion in that, which is really noticable if you move the white squares. It is indeed better

I'm guessing that the POLYVECTOR commands weren't desinged for this sort of thing (X,Y but no Z). A 3D plane will probably be the only guaranteed option, which I know Mr Plow wanted to avoid.

Wonder if he still needs/wants to do he skew effect.
I came. I saw. I played.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Re: Screen skew?
« Reply #10 on: 2016-Jan-07 »
I also tried this around version 7, having some faint memory of it being fixed in a later version but can't find it right now.

I guess it would be way too slow to paint each row separately as squares with polyvector commands? You can set the start and end position of the texture in each corner, right?

Like this, every row of xxx is a polyvector box:
Code: (glbasic) [Select]
xx
xxx
 xxx
  xxx

Offline sf-in-sf

  • Mr. Drawsprite
  • **
  • Posts: 93
  • Artist F.P. Brixey
    • View Profile
    • My computed art project
Re: Screen skew?
« Reply #11 on: 2016-Jan-10 »
Yes, why not using polyvector -grabsprite doesn't with openGL-ES. I hope you get some results if you start the division in 4 like the image, first to find the "perspective center". Next you will need perhaps to use that center to further divide the rectangle in 8. Good luck and please show us how it goes. 
On the day the atom is a cube I will start believing in the square pixel.

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 382
  • to program what I have do how should programming?
    • View Profile
Re: Screen skew?
« Reply #12 on: 2016-Jan-10 »
My example I sent 4 days ago use polyvector (see source).
Ciao
Qedo
« Last Edit: 2016-Jan-10 by Qedo »

Offline sf-in-sf

  • Mr. Drawsprite
  • **
  • Posts: 93
  • Artist F.P. Brixey
    • View Profile
    • My computed art project
Re: Screen skew?
« Reply #13 on: 2016-Feb-16 »
Hi!
  I realize it is not really possible, because polyvector does some linear interpolations, and the perspective effect means non-linear. It could work as an approximation if the image is noisy, not too geometrical. You can see that C1 > C2  > C3 > C4, it's a non-linear progression, and the same same thing happens inside each square. Polyvector does NOT do any non-linear interpolations. So, it looks that the only way is to use many sub-divisions -at least 8x8 or 16x16- in order to get some acceptable approximation. It's easier to use 3D commands for that, and the result is very clean with true perspective. I don't believe the 3D job should consume much more resource than polyvector, as the surface to draw is the same, and they both do (more or less) a pixel interpolation (?).   Check how it goes in practice on an old machine and please share the result with us.
On the day the atom is a cube I will start believing in the square pixel.

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 382
  • to program what I have do how should programming?
    • View Profile
Re: Screen skew?
« Reply #14 on: 2016-Feb-17 »
if you see the example that I enclose polyvector (16x16 quad) I think it works pretty well