Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411644 Posts in 69395 Topics- by 58450 Members - Latest Member: pp_mech

May 15, 2024, 01:15:00 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Collision and 2D skeletal animation
Pages: [1]
Print
Author Topic: Collision and 2D skeletal animation  (Read 3382 times)
blundis
Level 0
**


View Profile WWW
« on: February 27, 2010, 01:40:27 AM »

I've been trying to figure out how to get a skeletal animation system working but one thing i can't figure out is how to do collision against rotated bones.

I've been using a system based on this http://gpwiki.org/index.php/OpenGL:Tutorials:Basic_Bones_System where I store bones (as opposed to joints) with relative position and rotation and then let OpenGL handle everything by recursively calling glTranslate to move and glRotate to rotate (obviously), this works fine but leaves me not knowing the "world-space" coordinates of the bones.

What I'd need for collisions is (i think) to store joints, and calculate each joint from it's parent position and rotation but I'm unsure about how to do it and the more I think about it, the more confused i get.

I've checked out a bit of matrix math, thinking that if i store the matrixes I can just multiply them for each parent bone (joint?) and get the final coordinates, but since I'm learning the math as i go along it's not really working out. I'm also unsure if i should store a matrix for each joint or each bone?

Anyone have any experience with this kind of thing?
Logged
oahda
Level 10
*****



View Profile
« Reply #1 on: February 27, 2010, 04:48:24 AM »

I have made a working 2D polygon collision system.
I could try to abstract it for you, and you would have to add the code for rotation yourself, but as long as all you pass is the vertex coördinates, it should work.

There is one problem, though. Say you have two rectangular polygons. If they cross each other, like an X, it will not work. Currently, the system only reacts if any of the vertices is within the other polygon. If this is important to you (which it really isn't for me at the moment, and thus I haven't bothered to fix it), you will have to implement that yourself as well.
Logged

increpare
Guest
« Reply #2 on: February 27, 2010, 08:24:15 AM »

You're going to have to do the rotations yourself instead of passing them off to opengl.  This isn't a big deal, though, and is handy for a lot of different reasons : )

hmm.  Could you post us pictures of what your own matrix code is doing so far?

One approach ,which might be handy, would be trying to directly replicate the functionality of the opengl translate/rotate calls and try replace calls to opengl with calls to your own stuff...this will make it easier to test out what's working/not working, and you can put in collision from there...
« Last Edit: February 27, 2010, 08:30:19 AM by increpare » Logged
blundis
Level 0
**


View Profile WWW
« Reply #3 on: February 27, 2010, 02:18:36 PM »

One approach ,which might be handy, would be trying to directly replicate the functionality of the opengl translate/rotate calls and try replace calls to opengl with calls to your own stuff...this will make it easier to test out what's working/not working, and you can put in collision from there...

Yeah, that's sort of where I was heading, but not knowing anything about matrices I don't really know where to start, guess I'll have to read up on my math! Smiley

There are a few graphic libraries (like SFML) that have function to convert local coordinates to global and vice versa, do these libs handle their own rotation and translation (as opposed to letting OpenGL do it)?
Logged
Zaphos
Guest
« Reply #4 on: February 27, 2010, 02:38:08 PM »

OpenGL does allow you to read back the current modelview matrix, so you could use that figure out the local->global conversion; it's probably still better to do it with your own code though.  I don't know what SFML et al do internally.
Logged
increpare
Guest
« Reply #5 on: February 27, 2010, 03:18:35 PM »

Yeah, that's sort of where I was heading, but not knowing anything about matrices I don't really know where to start, guess I'll have to read up on my math! Smiley
I probably shouldn't say this, but in 2d you don't *need* to do matrixy stuff as much as in 3d - you can just keep track of your accumulated 'rotation' as you traverse your skeleton.
Logged
nikki
Level 10
*****


View Profile
« Reply #6 on: February 28, 2010, 03:51:54 AM »

Not to sure if this is the answer your looking for but:

Quote
The real problem is getting the the coordinates of all joints after rotation, for instance, knowing where the bottom part of the arm is if the top part is rotated.

couldn't you use sin/cos for that ? you know the length and the angle...
You also know the parent-child relations, so you'd know wich bones to recalculatre if a parent moves.

I have once made a skeleton animation program, and just stored the start & endposition of every bone, might be wrong practice, but it worked like a charm
Logged
Golds
Loves Juno
Level 10
*


Juno sucks


View Profile WWW
« Reply #7 on: February 28, 2010, 07:13:49 AM »

In the render call for your bone, you can grab the current opengl transformation matrix, and apply that to your bone's local vertices to test collisions.

Edit: Looks like Zaphos has already suggested this.  But anyway, I've done used this technique before, and it works pretty well.
Logged

@doomlaser, mark johns
blundis
Level 0
**


View Profile WWW
« Reply #8 on: February 28, 2010, 09:17:52 AM »

Thanks guys, those are all some good ideas! Smiley If I get something working, I'll be sure to show y'all.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic