Sign in to follow this  
asdqwe

math library?

Recommended Posts

I'm trying to make a 2D game but I got stuck at objects' moving routines. For example, I know how to move a sprite in a straight horizontal or vertical line, but not in an angled line (if I know the angle). Or: how to move something in a sinusoidal pattern, a spiral pattern, a circle pattern... Or calculate things like radians <-> degrees, hex <-> bin <-> dec. For all of these, isn't there a math library like there are physics libraries or image or sound libraries? (I know I COULD do a research for all these on the net, but I'd much prefer to have it all centralised and ready for use and, not least, bug-tested much better than I ever could...).

Share this post


Link to post
Share on other sites
Some of this stuff is already covered.

Look up sin, cos, and tan again and google cmath, the C++ standard library. With these, you should be able to get Xs and Ys from angles. Look into polar vectors to help with spirally things. (Basically, you change the angle and magnitude, then compute the rectangular vector to get the X and Y.)

The C++ trig funcs use only radians, so be aware. But, you don't need to use degrees, anyway. Radians are fine.

BTW: PI rad = 180 degs. PI/2 = 180/2 degs.

The hex <-> bin <-> dec, just Google and do it yourself. It's stuff every computer scientist should know. That's becoming less true, I think, but it's still good knowledge. And, your right, there might be bugs. Your code might not be the most optimized or clean. But, if you're not willing to write your own code on the simple stuff, what makes you think you're prepared for the harder stuff?

Share this post


Link to post
Share on other sites
I strongly recommend you learn this stuff, and then use a math library (such as CML).

Quite a lot of what you've listed requires little more than the trigonometry that would be covered in an introductory high school class, to be honest (and, frankly, some of it wouldn't really be helped by a math library).

Share this post


Link to post
Share on other sites

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

Sign in to follow this