how to transform child elements position into a world position
Posted
by
MrGreg
on Game Development
See other posts from Game Development
or by MrGreg
Published on 2012-06-21T20:49:05Z
Indexed on
2012/06/21
21:24 UTC
Read the original article
Hit count: 283
So Im making a 2d space game and I have a bunch of spaceships that have turrets. Objects have a position and orientation, the ships being in world coordinates while the turrets are children and coordinates are relative to their parents.
How do I efficiently calculate the position of a turret in world coordinates (i.e. when it fires and I need to know where to place a bullet in the world)? Calculating the turrets orientation is trivial - I just add the turrets relative angle to its parents. For position though, I guess I could do a bunch of trigonometry but this MUST be a common problem with a good/fast general solution?
Should I be relearning how to do matrix math again? :)
btw - Im creating the game in javascript+canvas but its the math/algorithm im interested in here
Cheers, Greg
© Game Development or respective owner