• entries
246
175
• views
154350

# math2d:: matrix vector

89 views

what you see is a demo i built up to test my new vector and matrix math code. it took a while and i went through alot of dumb mistakes, but i finally have it fully working. the fortress bitmap spins one way, and the turret bitmap spins along with it, properly tagged to where you see it. the turret spins the other way at 3x the rate of the fortress, and everything works as you'd expect to see it work.

it does all of this in many less lines than i'm doing things with in space fortress. i've just printed off the source to this demo as a reference and the source to space fortress and i have to basically rewrite most of the code to use these new math tools.

don't ask me why i haven't done this yet - i don't have an answer. i didn't know enough? not really true, i made a vector class long ago. i wanted to just get into the code and do something, i guess. i don't mind though. this is at least good for practice.

[edit: was looking at the difference between a bit of code..

// take a world-space point and transform it to fortress-bitmap-space// (ship center point)math2d::vector p = shipCenter - fortressCenter;p = math2d::RotationMatrix(-(fortressAngle)) * p;p = math2d::vector(p.x + fortressBitmap->w/2, fortressBitmap->h/2 - p.y);  //// or //// // make a matrix to..// take a world-space point and transform it to fortress-bitmap-spacemath2d::matrix toFortressSpaceTransformationMatrix =        math2d::TranslationMatrix (-fortressCenter) *        math2d::RotationMatrix (-fortressAngle) *        math2d::ScalingMatrix (math2d::vector(1,-1)) *        math2d::TranslationMatrix (math2d::vector(fortressBitmap->w/2, fortressBitmap->h/2)); math2d::vector p = toFortressSpaceTransformationMatrix * shipCenter;

hmm! reversing the process is alot easier to code [grin]]

There are no comments to display.

## Create an account

Register a new account