Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1057514 Posts in 42962 Topics- by 34899 Members - Latest Member: emeap

October 26, 2014, 01:32:24 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Collision and 2D skeletal animation
Pages: [1]
Print
Author Topic: Collision and 2D skeletal animation  (Read 2272 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
Prinsessa
Level 10
*****


═sjaki


View Profile WWW Email
« 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

dum mak gam
Vatnsmyrkr, deep sea exploration: Devlog

http://royalrailway.com
RoyalRailway @ Twitter, Tumblr, Bandcamp & Facebook

Ava
blundis
Level 0
**


View Profile WWW
« Reply #2 on: February 27, 2010, 07:48:25 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.

Thanks, but the actually collision handling isn't the core of my problem (sorry, was a bit unclear in my first post). For that I'll probably just end up using SAT.

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.
Logged
Prinsessa
Level 10
*****


═sjaki


View Profile WWW Email
« Reply #3 on: February 27, 2010, 08:00:22 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.

Thanks, but the actually collision handling isn't the core of my problem (sorry, was a bit unclear in my first post). For that I'll probably just end up using SAT.

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.
Oh. Simply, you would want to know where one end of a line that's x pixels long would end up, if the line were to be rotated y degrees/radians with the other end as the axis?
Logged

dum mak gam
Vatnsmyrkr, deep sea exploration: Devlog

http://royalrailway.com
RoyalRailway @ Twitter, Tumblr, Bandcamp & Facebook

Ava
increpare
Guest
« Reply #4 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 #5 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 #6 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 #7 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 Email
« Reply #8 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 8
*


Juno sucks


View Profile WWW
« Reply #9 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

blundis
Level 0
**


View Profile WWW
« Reply #10 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