Jump to content
Sign in to follow this  
  • entries
  • comments
  • views

math2d:: matrix vector

Sign in to follow this  


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-space
math2d::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]]
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!