GLBasic forum

Main forum => GLBasic - en => Topic started by: MrPlow on 2015-Oct-02

Title: Screen skew?
Post by: MrPlow 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

Title: Re: Screen skew?
Post by: MrPlow 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


Title: Re: Screen skew?
Post by: erico on 2015-Oct-08
You could also map your image to a 3d plane to achieve that.
Title: Re: Screen skew?
Post by: MrPlow on 2015-Oct-08
Thanks Erico but I need to avoid the 3D commands - pseudo effect needed only...
:)
Title: Re: Screen skew?
Post by: erico 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.
Title: Re: Screen skew?
Post by: Ian Price 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
Title: Re: Screen skew?
Post by: MrPlow 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...

Title: Re: Screen skew?
Post by: UBERmonkeybot on 2015-Oct-10
you can really see that effect if you increase the height of the box.

Title: Re: Screen skew?
Post by: Qedo 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.
Title: Re: Screen skew?
Post by: Ian Price 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.
Title: Re: Screen skew?
Post by: Moru 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
Title: Re: Screen skew?
Post by: sf-in-sf 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. 
Title: Re: Screen skew?
Post by: Qedo on 2016-Jan-10
My example I sent 4 days ago use polyvector (see source).
Ciao
Qedo
Title: Re: Screen skew?
Post by: sf-in-sf 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.
Title: Re: Screen skew?
Post by: Qedo on 2016-Feb-17
if you see the example that I enclose polyvector (16x16 quad) I think it works pretty well
Title: Re: Screen skew?
Post by: sf-in-sf on 2016-Feb-18
Ah! Thank you for the good news.
Title: Re: Screen skew?
Post by: MrPlow on 2016-Feb-18
Quote from: Qedo on 2016-Feb-17
if you see the example that I enclose polyvector (16x16 quad) I think it works pretty well

Very nice! Might be useful to do what I need, not sure yet - as the stretching of the moving object is very dramatic - but great example :)