Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Oct 2011
Offline Last Active Today, 01:55 PM

Topics I've Started

Skeletal animation with COLLADA

13 April 2015 - 12:37 PM

Hello. I'm trying to implement skeletal animation and loading my model and animation from COLLADA files. I've read all the data from the file and I've got my bones and vertex weights set up. Currently I set all the bones' transformation matrices to the identity matrix and then translate the root bone to see that that works.


I apply all the bone transformations with the vertex weights in my vertex shader (GLSL):

mat4 animationTransformation = TRANSFORM_Root        * vertexWeights0 +
                               TRANSFORM_Head        * vertexWeights1 +
                               TRANSFORM_Shoulder_L  * vertexWeights2 +
                               TRANSFORM_Arm_L       * vertexWeights3 +
                               TRANSFORM_Shoulder_R  * vertexWeights4 +
                               TRANSFORM_Arm_R       * vertexWeights5 +
                               TRANSFORM_Upper_Leg_R * vertexWeights6 +
                               TRANSFORM_Leg_R       * vertexWeights7 +
                               TRANSFORM_Upper_Leg_L * vertexWeights8 +
                               TRANSFORM_Leg_L       * vertexWeights9;

gl_Position = vertexTransformation * animationTransformation * vec4(vertexPosition, 1.0);

And then I modify the TRANSFORM_Root matrix and upload it:

animation.getJoints().get("Root").setTransform(new Matrix4(new float[][] {
    new float[] { 1.0f, 0.0f, 0.0f, 3.0f * (float)Math.sin(t) },
    new float[] { 0.0f, 1.0f, 0.0f, 0.0f },
    new float[] { 0.0f, 0.0f, 1.0f, 0.0f },
    new float[] { 0.0f, 0.0f, 0.0f, 1.0f }
shader.updateUniform("TRANSFORM_Root", animation.getJoints().get("Root").getMatrix(), true);

This works fine and the whole model translates nicely along the x-axis.


What I don't understand is what data to actually use for what from the COLLADA file.


Each bone has it's own transform in the skeleton definition (visual_scenes). Further I have a bind shape matrix (read from bind_shape_matrix) which is just the identity matrix in my case, a "skin bind-pose" matrix for each bone (read from library_controllers -> skin). They are specified as "inverse bind matrices". I also have animations for each bone, specified by a list of times and matrices. I understand I should interpolate between these different animation matrices.


But how do I put all these matrices together for uploading to the graphics card? I've read a couple of tutorials and they are quite unclear on how to do this (or don't use COLLADA at all), most just have a "bone transform" which is used to transform the vertices. But how do I calculate this transform from the bones' transformations, the skin bind-pose matrices and the animation matrices?

Here's the COLLADA file if anyone wants to take a closer look: https://gist.github.com/anonymous/da2c3f57140c1a5beb1b
Sorry for the nasty code.

Thanks in advance!

Feedback on turn-based combat system

19 May 2013 - 11:22 AM



I'm thinking a bit about a simple turn-based combat system, nothing fancy but at least something out of the ordinary. It's planned to be implemented in a roguelike game. The game is based around a lower health means greater power mechanic, so the lower your health, the better your character performs. Health can never be recovered, only temporarily fortified.


First of all, there is no character stats. You do not have strength, agility or anything that really changes the combat. All weapons inflict the same amount of damage, but they work in different ways. There's four types of weapons; Short weapons, medium weapons, long weapons and ranged weapons.


Short weapons can attack any adjacent cell.



Medium weapons can attack any adjacent cell and the two cells next to it. It can hit up to 3 opponents.



Long weapons can attack any adjacent cell and the next cell behind it. It can hit up to 2 opponents.



Ranged weapons can attack any cell in the field of view. The first enemy on the projectiles path is hit and does not continue.




When you attack something, a random number is generated with normal distribution, with the mean at the base damage for all weapons. The two red lines indicate that everything between them is a hit and everything outside is a miss. These lines depends on the opponents armour class. The lower the armour class, the closer the red lines are to the mean and the harder the opponent is to hit. If the attack is considered a hit, the random number generated is the damage output.




The higher the amour class though, the more damage is reduced from the incoming damage.


Lets set up a scenario:


The character is using a medium weapon and there's two enemies adjacent to her. She attacks them and one roll is made for each opponent. She hits one but misses the other. Since there was two potential targets, the damage done is halved.


Lets say the damage output for the opponent we hit was 10. The damage is halved, so there's 5 damage sent to the opponent. That opponent has a high armour class so the damage is reduced by 3, the damage inflicted on the opponents health is 2.



Instead of having a lot of different weapons with different damage and magic attributes, the game features power-ups instead. A power-up might heighten the players damage in different ways (changing the mean and standard deviation in the damage roll), or increase the players effective health. You can increase your armour class by using heavier armour, this will of course make you easier to hit but the incoming damage is reduced more. 


I'd love to hear your opinions on this idea, does it sound anything like fun? Will the lack or different weapons become dull and boring?

Textures for a tile-based game

02 November 2012 - 03:22 PM


I've worked on a tile-based on and off for a while. I have three classes, TileManager, TileLayer and Tile. The first one contains a list of TileLayers and really only handles the layers (add, remove, deactivate etc). The TileLayer contains a 2-dimensional array of Tile. The Tile class is abstract and other classes inherit from it.

Now, the first way I did this was that each class that inherits from the Tile class has a Vector2 which contains the position of its texture in a spritesheet. The TileManager together with the TileLayer class handeled the drawing of the classes. To structure this a little more I now want each tile to have its own Texture2D. And my question is how do I get the Tiles to load the textures on its own?

I don't want any code examples I just want to know in which way you would have done this. Should I pass the ContentManager down to the Tile in order for it to load the texture? Should I have another class (TileManager I suppose) load all the textures and then pass it to the Tiles?

Maybe I shouldn't even go this way and keep the old way? What do you think is the best way to solve this?

Thanks in advance!

Disposing of ContentManager increases memory usage

04 June 2012 - 11:24 AM


I'm trying to wrap my head around how memory management works in XNA 4.0
I've created a screen management test and when I close a screen, the ContentManager created by that screen is unloaded.
I have used ANTS Memory Manager to look at how the memory usage is altered when I do this, and it gives me some results which makes me scratch my head.

The game starts with loading two textures (435kB and 48,3kB) which puts the usage at about 61MB. Then, when I delete the screen and runs Unload on the ContentManager, the memory usage drops to 56,5MB but instantly after goes up to 64,8MB.
Posted Image

Am I doing something wrong or is this usual for XNA games? Do I have to dispose of everything the ContentManager loads seperatly or do I need to do something more to the ContentManager?

Thanks in advance!