Sprite pinch (edit : "stretch")

  ... the case you feel the need for a new feature or want to submit one.

Sprite pinch (edit : "stretch")

Postby orabig » Tue Jun 11, 2013 11:18 pm

Hi all,

For one of my projects, I had to extend the Sprite class, and make it "pinchable".
I mean, being able to distord the sprite like in the screenshot below.
This is working right now, but I'll have to add some comments and clean the code before releasing to the public. So I will do it only if I feel this could be of any use to someone else. Maybe I missed some point in the API, and did all this for nothing, but I wasn't able to find a way to do it with the current version. :roll:

EDIT : The code is now on github, at https://github.com/Orabig/AndEngineSpriteStretch
Attachments
pinch.png
pinch.png (10.14 KiB) Viewed 1535 times
Last edited by orabig on Sat Jun 22, 2013 10:39 am, edited 3 times in total.
orabig
 
Posts: 7
Joined: Thu May 30, 2013 10:23 am

Re: Sprite pinch

Postby nazgee » Wed Jun 12, 2013 3:05 pm

Looks interesting. I do not like the idea of being forced to actually pinch, though. Is there an API to use it in a diferent way (i.e. without having to touch the screen)?
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: Sprite pinch

Postby orabig » Thu Jun 13, 2013 2:05 pm

Hum, I'm sorry, I did not myself clear, and I think that's because I did not choose the word "pinch" very wisely... Maybe I should change the term "pinch" to "stretch".

This effect has nothing to do with user interaction. Actually, this is solely a way to distord the shape, and make the standard rectangle look like a trapezoid. This behaviour is controlled by method calls on the object, not user interactions.

Anyway, I've already improved my object, because it appeared to have an unwanted perspective effect when the pinch was close to 0. So, I managed to change the shaders code, to fix this, and have the mapping behave just like it should.

Ok, to be clear, here is a screenshot. The old (incorrect) version was behaving like the trapezoid on the right, while the new one is shown on the left.
trapezoid.png
trapezoid.png (191.28 KiB) Viewed 1525 times


As you can see, when the top border's size tends toward 0, the texture looked awful :
trapezoid2.png
trapezoid2.png (180.29 KiB) Viewed 1525 times


I'll release the code when it's ready (tm)
orabig
 
Posts: 7
Joined: Thu May 30, 2013 10:23 am

Re: Sprite pinch (edit : "stretch")

Postby yhyang » Fri Jun 14, 2013 9:11 am

This looks cool and useful, thanks for your kindly releasing it.
This looks like 'perspective' and/or 'envelope' effects that I usually do in Inkscape, with this, I probably can skip much graphics work. Thanks again!
yhyang
 
Posts: 115
Joined: Thu Nov 22, 2012 9:46 am
Location: Taiwan

Re: Sprite pinch (edit : "stretch")

Postby e.r. » Fri Jun 14, 2013 9:37 am

This is extremely useful, and it is actually the solution to my question back then in this thread : )
http://www.andengine.org/forums/post52467.html#p52467

So i think you are playing with the scaling center and the actual value of the scale?
User avatar
e.r.
 
Posts: 557
Joined: Sun Sep 09, 2012 1:41 pm

Re: Sprite pinch (edit : "stretch")

Postby orabig » Fri Jun 14, 2013 10:40 pm

Well, no, it has nothing to do with some "scaling center".
In facts, both results are made with very different shader algorithms.

My first try was to use the standard texture2DProj() SGL function, which gives the "perspective" effect. (like it's explained here : http://home.xyzw.us/~cass/qcoord/) But that was not the effect that I wanted.

Then I found another algorithm, which is very different (and more easy to adapt on arbitrary coordinates, which is a good thing), and it gave the right result...

The code is not finished yet.

By the way, I don't know yet what API I can implement, and it may depend on your ideas, people...

I can provide some "setStretchX(0-1)" and "setStretchY(0-1)" methods,
... or maybe setTopLeftPosition(x,y), setTopRightPosition(x,y)...
... or setCorners (x1,y1, x2,y2, x3,y3, x4,y4)

What do you think could be the more useful ?
orabig
 
Posts: 7
Joined: Thu May 30, 2013 10:23 am

Re: Sprite pinch (edit : "stretch")

Postby e.r. » Mon Jun 17, 2013 1:10 am

I Would say go with the stretchY stretchX...same method as skew and scale maybe same overloading types, since this way we will be more familiar with them : )
Thanks again
User avatar
e.r.
 
Posts: 557
Joined: Sun Sep 09, 2012 1:41 pm

Re: Sprite pinch (edit : "stretch")

Postby orabig » Thu Jun 20, 2013 4:00 pm

The code is now working, but needs further documentation, and maybe a sample projet.

I will be busy for some days, so I edited my first post to add a preview of the code. Those being interrested will thus be able to have a look and try it. :geek:
orabig
 
Posts: 7
Joined: Thu May 30, 2013 10:23 am

Re: Sprite pinch (edit : "stretch")

Postby orabig » Sat Jun 22, 2013 10:42 am

Ok, the code is now on github.

Feel free to fork it or use it at will (maybe I'll take some time to add a license notice and some screenshots :roll: )
orabig
 
Posts: 7
Joined: Thu May 30, 2013 10:23 am

Re: Sprite pinch (edit : "stretch")

Postby naizirk » Fri Jul 12, 2013 3:12 am

seems to be great work, i'll try it out to create some PerspectiveEntitys (aka cubes) to get a little pseudo 3d into the 2d world ;-)

in fact, this seems easier than the skew approach i tried before :?

thanks for the effort
naizirk
 
Posts: 1
Joined: Sat Jun 23, 2012 6:18 pm


Return to Features

Who is online

Users browsing this forum: No registered users and 4 guests