Re: Rotation along a Bezier Curve
cubed2D
July 17th, 2007.
A while ago i wrote an article for ziggyware on moving a sprite over a bezier curve. Well, i recently received an email (hi John!) asking a question, and i remembered a problem i discovered in my code after the article was published!
I included a method for calculating what angle the sprite should be rendered at to produce a cool looking animation. It used a mathematical function called arc tan to calculate this angle.
To tell you the truth, i cant really remember what the actual problem was, but I’m fairly sure that if the control points were not layed out in a perfect right angled triangle shape, the red lines imposed on the image wouldn’t meet at the bottom to form a right angle…. which my method relied on to produce a correct angle (going by memory, as i say, i might be remembering this wrong). it would produce slightly odd results with some quadratic curves, like the one pictured and would definitely screw up on higher order curves.
A much nicer way of doing it would be to store a heading. Every time you update the position of the sprite over the curve, if you normalise its position (presuming your useing a vector for its position) and the calculate the dot product of that heading with the previous heading, you should get the angle between them in radians…. you should beable to use that to create a better looking movement over a curve, of any order. (please note, i havent got xna installed and working at the moment because of my previously mentioned computer problems, so i cant test out this theory!)
#1 nsowjgmqe dvljcatze - 06 September, 8:03 PM
uvmqc dohp daqlyp liwy yusoiplcn sfqlxu shyme