Hi am just doing a little animation which moves an object from point a to point b or by angle/radians.
what I currently have is this
Point CalcMove(Point pt, double angle, int speed)
{
Point ret = pt;
ret.X = (int)(ret.X + speed * Math.Sin(DegToRad(angle)));
ret.Y = (int)(ret.Y + speed * Math.Cos(DegToRad(angle)));
return ret;
}
but it doesn’t look what i expected.
please help?
update:
oh and am using NETCF
CalcMove(Point pt, double angle, int speed)
“Point pt” is the current object location. “angle” is where the object should go. “speed” is the step.
so after days of work..
here’s what I have worked on .. Neko for Windows Mobile 6.5
Use a rotation matrix. This code will move from a point (x,y) by theta radians to a new point (px, px)
The matrix used above,
Will move a point around the circle clockwise when using graphical coordinates.
I did the exact same thing last week. You can animate this by finding the total theta that you wish to move and then divide that by the number of frames (or steps). Now, start every move at some arbitrary point (for example, (0, radius)) and increment some counter totalSteps and move always beginning from that initial point. If you simply move the point itself each frame you will accumulate some error, but if you always move from the initial point by the current increment, stopping when the increment == totalTheta, it will be perfect. Let me know if that makes sense.
Maybe I should illustrate a bit more. Let’s say you have a method “BeginMove”:
Now you have a method which updates the move every frame:
There will obviously be more logic here depending upon your exact situation, but the idea is: