Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / The creation of 2D on the fly polgyons

Author
Message
Gil8ert
8
Years of Service
User Offline
Joined: 10th Jul 2016
Location:
Posted: 11th Jul 2016 00:24
Say I have the co-ordinates for the corner points of a star.
Then I connect up those points with drawline.
Can I convert the resulting outline into a fillable sprite?

Is 6 the maximum number of points I can have for that polygon?

Is there any way of cycling through the polygonal corner coordinates within a sprite?

Many thanks chaps!

Gil8ert
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 11th Jul 2016 12:45 Edited at: 11th Jul 2016 15:28
Quote: "Is there any way of cycling through the polygonal corner coordinates within a sprite?"

You can make a sprite with an image and make an image with RenderToImage or better GetImage for you purpose.
But the resulting sprite will always have four corners/vertices no matter what image you are using.
If you are speaking of physics sprite shapes then you can get collision/contact points and all but cannot obtain the corner points jet.
So you need to save the coordinates of the corners by yourself.

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 11th Jul 2016 14:26
Quote: "Can I convert the resulting outline into a fillable sprite?"

Not with any built in commands, but you could probably write your own memblock floodfill routine to fill the shape in?
Gil8ert
8
Years of Service
User Offline
Joined: 10th Jul 2016
Location:
Posted: 11th Jul 2016 16:29
Thanks for the replies Chaps!

Basically I was looking to create light and shadow effects in a 2D environment, as described on this webpage: http://ncase.me/sight-and-light/

I have gotten to the point where I can cast out 50 rays in all directions, and draw a line with a circle on the end to visibly show the paths. It works perfectly.

Then suddenly I was hit with the prospect of having to turn these points into a polygon. So I would either need to create a whole polygon of many points, or create many triangle polygons to create the effect I wanted. But it looks as though this is not possible within AppGameKit?

What is a memblock floodfill routine? Are there any demonstrations you could point me to?

Or do you think I should give up on this idea immediately, and just work with basic shaders?

Many thanks for your time!!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 11th Jul 2016 17:17
You can always define your own physics shape, adding the lines one by one - that way you could store the data. It might be worth adapting that data though, as vector rotation isn't really something you'd want to mess with if you don't have to. I mean, the physics shape could be stored as angles and radius rather than 2D X and Y, and that would make it real easy to calculate positions for rotated or scaled sprites. When you define your own physics shape, there is no hard limit on the number of lines/points you can add. I have used this in a game that relied on line to line intersection for collisions, works pretty well but really you need some sort of editor to do it properly.

To then draw the shape, you'd plot lines on a memblock and flood fill from the centre. This means that all your sprites would need to be convex, which is typically the case anyway. Sadly, flood fill routines are notoriously difficult to explain, to learn it, it's better to experiment and make your own - but if you just need it working then I'm sure I can knock up a line and fill memblock example for you. By doing it this way, you'd be able to control alpha levels, add a little anti-aliasing, stuff that might be tricky with other methods. You could use the shape data for the collision and physics, and use the same data to draw the shape in solid colour.

Remember though, you can just colour a sprite black and a bit transparent (like 0,0,0,128) and it'll be a shadow - all the pixels would be black with 50% alpha transparency. This is a good, cheap way to make a shadow version of a sprite. If you use pixelated sprites and filtered shadow versions it does look cool, tried this in an old project and it ended up looking far better than I expected.
The code is dark and full of errors
Gil8ert
8
Years of Service
User Offline
Joined: 10th Jul 2016
Location:
Posted: 11th Jul 2016 18:00
Thanks for all the replies chaps, I really appreciate it!

In essence I am just trying to create lighting and shadows in a 2D environment. So I started working through the methodology I found on this page: http://ncase.me/sight-and-light/

I can do everything absolutely fine up until the point I need to create a whole polygon from the ray cast points.

I totally understand how to offset a black semi transparent copy of a sprite to create a shadow - but it's not really the option I'm after.

So the flood fill/mem fill option look like I just need to create an piece of code to fill my shape on a pixel by pixel basis? Anyone have an example code of this?

I think I understand this, it's a similar (not identical) problem to pathfinding.


Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Jul 2016 08:00
I see - sadly a flood fill routine would be far too slow for this. You are right, pathfinding can be tackled in the same way as a flood fill, starting from a point and spreading that point out into the desired shape by 'combing' the area in different directions.

I'm sure I've seen an AppGameKit demo that does this, but it may have been just for squares... like grid based.
The code is dark and full of errors
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 12th Jul 2016 13:23 Edited at: 12th Jul 2016 14:42
Don't use flood-fill, I tried to accomplish exactly the same from the same website.
I tried to create the shadow polygon with triangle fill algorithm which should be faster.
maybe you can gain speed if you draw everything in one memblock..

Dynamic light

Using AGKv2 Tier1
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jul 2016 17:50
Since you're wanting to create a casted light cone, which from the link I only see 3 and 4 sided polygons, why not just use a sprite and move the vertices into the desired shape?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 15th Jul 2016 10:29
I wrote a filled polygon routine a while back for use in a game I started working on called "Biker Glow"... I dropped development as it was too similar to other games I'd seen and have since lost the source code I remember it used memblocks and would fill with a repeated stencil texture from any image. I hate losing code! It'll be on a backup somewhere. If I find it, I'll post it.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Jul 2016 10:50
I'm not sure you can move the vertices on a sprite Phaelax, just the UV coords.

The only idea I have left on how you could do this, is using a mesh memblock, preloaded polygons that you adjust each loop. You'd have to know the maximum number of polygons you'd need at any point, because you can't really add more polygons to the mesh as you go, you'd have to put the unused polygons off screen. This method might be tricky to align with 2D sprites though, and it's not exactly straightforward.
The code is dark and full of errors
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Jul 2016 02:41 Edited at: 19th Jul 2016 03:51
Quote: "I'm not sure you can move the vertices on a sprite Phaelax, just the UV coords."

Challenge accepted!

*starts tinkering*


The mouse controls for the demo are taking me longer than the actual product...

Ok, this is taking longer than I thought. The UV data isn't behaving like I expect it would.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 19th Jul 2016 18:40 Edited at: 19th Jul 2016 18:41
As you know me, Shaders are the answer for me ...like so often

You can manipulate the vertices in the vertex shader of the sprite, it works I tested it, but I don't know how to obtain the right vertices jet.
Another solution is to use 3D object planes and change the shader to use orthographic projection and simulate a sprite... then you just use the mesh vertex manipulation commands from AGK.

Using AGKv2 Tier1

Login to post a reply

Server time is: 2024-11-25 03:34:44
Your offset time is: 2024-11-25 03:34:44