It is currently Thu Apr 25, 2019 2:43 am

 All times are UTC - 7 hours

 Page 1 of 4 [ 46 posts ] Go to page 1, 2, 3, 4  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: Sprite shearing to fake rotationPosted: Sun Jan 06, 2013 2:40 pm

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21324
Location: NE Indiana, USA (NTSC)
A radian is the angle whose arc length is the same length as the circle's radius. For example, if something moves through an arc of 0.4 radians, it'll have moved through a distance 40% of that to the center. If your game has 16-direction movement, there's a gap of (2*Pi/16) = about 0.4 radians between positions. For example, if something has 16 frames of rotation and a lever arm 20 pixels long, the end will move by 8 pixels between one angle and the next.

In this figure, an angle close to 22.5 degrees or 0.4 radians is marked in red, and a distance of 40 percent of the radius is marked in green.

Attachment:

0.4_radians.png [ 3.76 KiB | Viewed 9085 times ]

Now say I have something spinning on an off-center axis, such as a ball on a chain or a character swinging on a trapeze. From the axis of rotation to the active part is 20 pixels. But with 16 frames of animation (8 stored, 8 flipped), that's still about 0.4 radian per frame. So when the object rotates through 1/16 of a circle, its active part instantly moves about 8 pixels, enough to confuse collision detection, eject the object the wrong way, and cause it to glitch through a wall.

Attachment:

all16frames.gif [ 2.14 KiB | Viewed 9085 times ]
Attachment:
File comment: Onion skinned: previous frame semitransparent

all16onion.gif [ 2.88 KiB | Viewed 9085 times ]

I could try shearing the rotating sprite by sliding the 8-pixel strips. This is analogous to how games use "Y offset per column" background modes of the Super NES PPU and Sega Genesis VDP to fake rotation; psycopathicteen could tell you more about these modes. Sliding each strip by 1 pixel works for up to 1/8 radian (7.16 degrees) either way.

Attachment:
File comment: With one frame of shear before and after each

all48framesfast.gif [ 6.26 KiB | Viewed 9085 times ]
Attachment:

all48framesslow.gif [ 6.26 KiB | Viewed 9085 times ]

Or I could try decoupling the collision position from the display position so that the active part moves smoothly despite discrete angle changes in the sprite.

_________________
Pin Eight | Twitter | GitHub | Patreon

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Sun Jan 06, 2013 10:58 pm

Joined: Sun May 27, 2012 8:43 pm
Posts: 1342
This is neat, but in the context of the Famicom/NES what would be the best way to set about implementing the idea without eating a lot of cycles figuring out how to position sprites that compose a larger meta-sprite in order to achieve the smoother rotation? To slide individual rows could be done I suppose, but vertical strips of pixels would mean eating up a lot more CHR in order to fit these modified tiles, unless you propose modifying CHR-RAM directly for this purpose, though such an operation would not be very quick, I would presume.

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 12:13 am

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 4158
I'm guessing you simply use tables.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 9:17 am

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
mikejmoffitt wrote:
This is neat, but in the context of the Famicom/NES what would be the best way to set about implementing the idea without eating a lot of cycles figuring out how to position sprites that compose a larger meta-sprite in order to achieve the smoother rotation? To slide individual rows could be done I suppose, but vertical strips of pixels would mean eating up a lot more CHR in order to fit these modified tiles, unless you propose modifying CHR-RAM directly for this purpose, though such an operation would not be very quick, I would presume.

Yeah, it wouldn't make much sense to do this if it requires new graphics anyway. If this was e.g. moving the individual tiles of the sprite separately, it'd make more sense (indeed Treasure did this on Yuu Yuu Hakusho, albeit for scaling).

EDIT: I always keep up mixing the names of the two Yuu Yuu Hakusho games on the system -_-'

Last edited by Sik on Mon Jan 07, 2013 10:46 am, edited 1 time in total.

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 9:23 am

Joined: Wed May 19, 2010 6:12 pm
Posts: 2842
You could use the CPU to do software vertical scrolling, while doing horizontal scrolling with the oam x coordinates. Of course, you'll need enough vblank time to write the sprite patterns to vram.

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 10:49 am

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
psycopathicteen wrote:
You could use the CPU to do software vertical scrolling, while doing horizontal scrolling with the oam x coordinates. Of course, you'll need enough vblank time to write the sprite patterns to vram.

Try doing the horizontal scrolling thing with several sprites and you'll see how messy it gets (and you'll probably run out of cycles if you try to use a general approach, you'll need to impose some special restrictions). Also that assumes the use of CHR-RAM, if you use CHR-ROM it won't work since you can't generate graphics on the fly (obviously).

Also wouldn't software horizontal line scrolling be faster than software vertical line scrolling? May as well do both in the CPU.

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 11:07 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21324
Location: NE Indiana, USA (NTSC)
mikejmoffitt wrote:
in the context of the Famicom/NES what would be the best way to set about implementing the idea without eating a lot of cycles figuring out how to position sprites that compose a larger meta-sprite in order to achieve the smoother rotation? To slide individual rows could be done I suppose, but vertical strips of pixels would mean eating up a lot more CHR in order to fit these modified tiles, unless you propose modifying CHR-RAM directly for this purpose, though such an operation would not be very quick, I would presume.

A metasprite in such an engine is stored either as a set of 8xn pixel columns (if it is wider than tall) or as a set of nx8 pixel rows (if it is taller than wide). A shear of +1/8 or -1/8 would slide an individual row or column of 8x8 pixel sprites by one pixel. They'd be slid around in OAM, not in CHR RAM, which means this technique would work as well with CHR ROM assuming fine-grained bank switching. Compare to what's done in the first two levels of Battletoads. The walkers' legs in level 1 are sheared for smooth movement, as is the rope in level 2.

Shall I draw another illustration of this?

_________________
Pin Eight | Twitter | GitHub | Patreon

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 1:39 pm

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
So what you want seems to be what I mentioned: move around the individual sprites to make the illusion of a smoother animation (even though the actual amount of graphics is smaller).

Something like in here? (but possibly with intersecting sprites so gaps aren't obvious)

Or heck, something like the swinging wires here:

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 2:03 pm

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7412
So you're suggesting to shear a sprite into two or more sprites as a tween between two key sprites that are rotations of each other? I guess it's possible, but without hardware support it sounds like it would take up a lot of probably-precious sprite resources. On the NES you can do shearing of background tiles via scrolling, perhaps.

In the example you provided pictures of, I'd say the 8-directions worth of sprites for the two components (with flipping I guess it's really 3 sprites each) are probably what I'd stick with. I would leave the inner sprite where it is, coarsely sticking to those 8 directions, and the outer sprite can move smoothly in a circle. Even though it would only have 8 rotations, the motion of its position can be very smooth. With sprites that are carefully drawn to work with a varying amount of overlap, it can look pretty good, and the smoothness of motion might make up for the lack of rotation granularity. I'm also reminded of the common vectorball technique, where sprite rotations are abandoned entirely, but the motion is quite smooth. (Edit: I just remembered the NES port of the vectorball example.)

I guess Sik is suggesting the same thing.

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 2:34 pm

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
8 directions usually looks ugly, it's better to stick to 16 =P (which with flipping gets reduced to 5) Also even with 16 it can be quite noticeable, it depends on how fast the sprite rotates (if it spins quite fast it probably won't be very noticeable, if it spins slowly it will still be quite blatant).

EDIT: and before I forget, that dragon example has 16 rotations, not 8 =P

EDIT 2: also if the sprite is constantly spinning in a given direction you probably don't care if the sprite ever ends up aligned to the axes, so you can shift the rotation such that you only would need 4 sprites instead of 5.

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 2:45 pm

Joined: Wed May 19, 2010 6:12 pm
Posts: 2842
Sik wrote:
psycopathicteen wrote:
You could use the CPU to do software vertical scrolling, while doing horizontal scrolling with the oam x coordinates. Of course, you'll need enough vblank time to write the sprite patterns to vram.

Also wouldn't software horizontal line scrolling be faster than software vertical line scrolling? May as well do both in the CPU.

Vertical tile scrolling is just a matter of loading and storing bytes.

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 3:02 pm

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7412
Sik wrote:
EDIT: and before I forget, that dragon example has 16 rotations, not 8 =P

EDIT 2: also if the sprite is constantly spinning in a given direction you probably don't care if the sprite ever ends up aligned to the axes, so you can shift the rotation such that you only would need 4 sprites instead of 5.

Yes, Dragon Breed has 16 rotation sprites, none of them flipped. I wasn't referring to its sprite count, just that it is using the sprite position to get extra smoothness between the rotation sprites, and the overlap between sprites allows visual continuity between segments even though the positions are shifting irregularly.

Not aligning to the axes can have an aesthetic appeal as well, so that's a good suggestion not just for extra smoothness, but breaking up the look of 8-pointy things.

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 4:57 pm

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21324
Location: NE Indiana, USA (NTSC)
Sik wrote:
8 directions usually looks ugly, it's better to stick to 16 =P (which with flipping gets reduced to 5)

That depends on how symmetric the object is. If it isn't left-right symmetric, you need 8 anyway to produce 16, as only half of them can be computed through vh-flipping. Flipping only vertically or only horizontally produces a sprite facing the other direction.

_________________
Pin Eight | Twitter | GitHub | Patreon

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 8:03 pm

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 4018
Location: A world gone mad
Another game to look at for this, by the way, is Syvalion. Compare, say, the Amiga or SNES version to that of the arcade (arcade is a lot smoother but can't figure out if the sprites are significantly different), and look at the Chinese dragon's segments during movement.

Yeah, the game is similar to Dragon Breed (which I own :-) ) in that it has a Chinese dragon. HAI I LIEK DAGRONS. I give them milk and sugar and in return they give me good luck and the ability to manipulate water. (This line added just to try and get Tepples to go on a link spree, probably involving pictures of Spyro or strange child-like dragons with baseball hats carrying bento boxes while fishing).

Top

 Post subject: Re: Sprite shearing to fake rotationPosted: Mon Jan 07, 2013 8:19 pm

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
psycopathicteen wrote:
Sik wrote:
psycopathicteen wrote:
You could use the CPU to do software vertical scrolling, while doing horizontal scrolling with the oam x coordinates. Of course, you'll need enough vblank time to write the sprite patterns to vram.

Also wouldn't software horizontal line scrolling be faster than software vertical line scrolling? May as well do both in the CPU.

Vertical tile scrolling is just a matter of loading and storing bytes.

This was on the assumption of scrolling each column of pixels separately. Then you're moving individual bits.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 4 [ 46 posts ] Go to page 1, 2, 3, 4  Next

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 3 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki