Tell me I'm crazy: pretending I'm in 3d using 2d

Hey guys.

I’m working on a game where the characters are composed of a physics skeleton in 3d-space. What I want to do is map 2d sprites to parts of the skeleton, and rotate/scale them to match the orientation of the part of the skeleton they represent. The reason I want to do this is to keep a cartoony feel and allow a maximum of character customization (players do not control the characters directly, so customization during the results “show” keeps the link to the character alive).

I have 4 questions about this:

  1. Is AffineTransform quick enough to be doing around 20 changes like this per character? I’m thinking of having a max of 8 characters like this, so that’s around 160 changes.

  2. How would I go about setting up a draw system for this? I was thinking of making a “view” class that gives the “body part” a translated graphics object to blt onto, since every body part has to figure out its own orientation.

  3. How does this affect caching of images (“Automatic Images”)? I have to turn and squish every frame; does this change kill the cache abilities? Does it even matter? I’d like to run in a window, so it might be moot to be worrying about it anyway.

  4. Am I completely out of my gourd?

To my knowledge, Java2D has not been very well optimized for anything but plain 'ol laying down images. If you want to be doing a lot of transformations, you may want to look at using LWJGL. Transformation math is extremely fast in OpenGL as it’s part of the rendering pipeline.

Here’s a tutorial I wrote on converting 3D polys into simple 2D polys:

http://josrts.sourceforge.net/phpwiki/index.php/OpenGL2D

Wow. Thanks! How portable is LWJGL? I assume the end-users have to download it too?

It’s currently portable to Windows and Linux with a MacOSX build winding its way through development/beta testing. As for distribution, that’s up to you. There’s a LWJGL JAR file for all systems and LWJGL library for each platform. How you want to distribute those files is up to you.

A rendering technique that may apply to this is nonphotorealistic rendering. well, it is kind of advanced, and requires some research, but may lead to true 3d cartoonish looks.
I think that you can use OpenGL to do that.
Try looking for ‘nonphotorealistic render’ at Google for more information…

Your aproach is much simpler to implement (i suppose), if it require you to model just the skeleton instead of the complete 3d model. Just take this is just a suggestion for the future :slight_smile:

The technique he’d be really interested in is cell shading which is a very cool looking way to use a fragment program in OpenGL. Might be a bit difficult/slow on cards older than a Geforce 3 though.

Cas :slight_smile:

Cel shading is easier that you’d expect, and doesn’t really need any fancy vertex or pixel shaders ;D The banded lighting can be done with a 1D texture, and the texture coords calculated in almost exatly the same way that normal diffuse lighting is calculated.

Edges are more of a problem, especially to get consistant ones without annoying poping as a model rotates. The best way I’ve found is to reverse the triangle winding order, then extend every vertex along its normal by a small amount and the colour set to whatever outline you want.

You can cut down the cpu usage though with a vertex shader though, as this kind of per-vertex op is perfect for it.

Edit: Or you can go the whole hog and use every extension known to man, and require an FX card to run: http://www-rocq.inria.fr/mirages/SYNTIM_OLD/research/decaudin/cartoon-eng.html
Shame they used shadowmaps, the texture artifacts are pretty large. Shadow volumes (as done in Jet Set Radio) tend to look much better with cel shading.

[quote]Edges are more of a problem, especially to get consistant ones without annoying poping as a model rotates. The best way I’ve found is to reverse the triangle winding order, then extend every vertex along its normal by a small amount and the colour set to whatever outline you want.
[/quote]
you cqn get the edge problem nicely solved for j3d here. Very nice and interesting solution.
http://www.j3d.org/tutorials/quick_fix/npr_line.html

That method is a hack, and a pretty ugly one as well - using the backfacing-wireframe method is something i’ve tinkered with, and it suffers exactly from the problem i mentioned - edges ‘poping’ in and out as faces make the transition between front and back facing.

The other problem with that method is visible most obviously at the ears - wide lines aren’t suitable for this method because they don’t link up totally with larger outline sizes. Extending vertices gives you more consistancy and greater control.

This old screenshot of mine (in lwjgl) is done in the way i’ve described above: http://studenti.lboro.ac.uk/~cojc5/Temp/Cel.png

Sorry, Orangy, i disagree.
The method, while not perfect, is a nice trick. It does certainly not give bad results, and is very easy to setup. About the ear problem, as the method deals with thin vectors, it can of course show up in thick volumes, as those vectors are 3d, thus they can eventually go through polygons. But your solution could also lead to such problems, where a displaced vector would get behind an adjacent polygon, thus being seen where it should not. Also, you might suffer more zbuffer problems than using thin vectors.

You might not like it, or its drawbacks, but i still think is is a nice solution, can be used in many cases. with minimal hardware requirements. and is fast. Moreover, geometry does not need to be duplicated, and you eliminate precision problems when morphing, for example.

Ok, maybe calling it an ugly hack is a bit harsh, it is a workable solution after all. But i think you’ll find that it gives less visual errors that the wireframe approach. Having said that, i agree that for thin outlines the wireframe method does look pretty good.

You still need to duplicate the geometry though, theres no getting around that unless you use weird and wonderful methods that take a hell of a lot more processing…

Hmm, i wonder if they decided against having outlines in Zelda:WW since they can give inconsistancies like these.

Thanks, guys.

I wanted to keep with sprites because I can blt source images together to form a customized character. Though this works well and good for cylindrical limbs, the torso looks different from any given angle, so I might look into cel-shading/edge drawing for that.