IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New What I'm up to.
I'm rewriting "Asteroids" as part of a school project, forthehellofit.

While vector math is plain simple for most of the critters, figuring in ship thrust and getting it right is tricky. As a bonus, I'm implementing a "turtle" to do all the animation for the various objects, so the rocks will lazily spin as they work their way across the screen - no prerendered graphics at all.

Very simple graphics, mind you...
Tired of lying in the sunshine staying home to watch the rain.
You are young and life is long and there is time to kill today.
And then one day you find ten years have got behind you.
No one told you when to run, you missed the starting gun.
New Simple optimization:
Which happens more, new position calculation or thrusting?

If it's thrusting, use the method you've currently come up with.

If it's position calculation, then model your speed/direction vector as an X/Y tuple instead of direction/speed, and add/subtract to X and Y when thrust is applied. This way you're only doing the sin and cos calcs when thrust is applied (probably infrequently) instead of every movement tick.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New That's exactly what I'm doing.
Vectors are an x/y pair, complete with math. I just wanted a function to construct a vector out of a speed/angle pair.

In fact, what I'll probably end up doing to save comp time is to save the last used vector calc, check to see if the angle has changed, and if it hasn't, just reuse the last used vector. Not that I'm terribly concerned about performance, as this will be running on some seriously meaty computers.
Tired of lying in the sunshine staying home to watch the rain.
You are young and life is long and there is time to kill today.
And then one day you find ten years have got behind you.
No one told you when to run, you missed the starting gun.
New And now I'm thinking of...
...just building a lookup table with all 360 angles.
Tired of lying in the sunshine staying home to watch the rain.
You are young and life is long and there is time to kill today.
And then one day you find ten years have got behind you.
No one told you when to run, you missed the starting gun.
New 360?
You only need 90... ;-)
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Probably worth it
instead of modulo-ing angles - plus you get an unambiguous arctan without fuss.
-drl
New A computational alternative.
There is no reason to have a more precise result than a human can notice.

Use the sine expansion:

sin( x ) = x - ( x3/3! ) + ( x5/5! ) - ...

and the cosine expansion:

cos ( x ) = 1 - (x2/2!) + (x4/4!) - ...

Of course the angle x has to be in radians (360 degrees is 2 PI radians) and you need to keep x small (i.e. no more than say PI/2 and THIS IS IMPORTANT!). That just means you have to know what quadrant you're in and supply the proper sign to the values. If you want to be less than 1 percent off, take each series to 4 terms (i.e sine term with 7! divisor and cosine term with 6! divisor.

The factorials can be precomputed constants. Save and compute each power from the prior power of x:

x = ?
x2 = x * x
x3 = x2 * x

etc.

Obviously, all floating point variables.

What this approach does is probably the same as what the library function does, but it quits much earlier and gives a less accurate but acceptable result.
Alex

Honor has not to be won; it must only not be lost. -- Arthur Schopenhauer (1788-1860), German philosopher
New This suddenly got much easier.
I, at most, want a person to take a full second to rotate the ship a full 360 degrees. Since there are sixty heartbeats per second in this system (FPS maxes out at 60 for this project) I'll only need 60 "positions" out of the 360 that are actually there - at 0, 6, 12, etc.

Building the table will take less than a second at startup, even on slower computers. And it will help slower computers run it.
Tired of lying in the sunshine staying home to watch the rain.
You are young and life is long and there is time to kill today.
And then one day you find ten years have got behind you.
No one told you when to run, you missed the starting gun.
New That might not be how the library does it...
I've heard that at least some libraries find that it is faster and more efficient to have a partial table of sin's and cos's, then use the addition identities to fill in any one that they want:

sin(x + y) = sin(x)cos(y) + sin(y)cos(x)
cos(x + y) = cos(x)cos(y) - sin(x)sin(y)

Cheers,
Ben
To deny the indirect purchaser, who in this case is the ultimate purchaser, the right to seek relief from unlawful conduct, would essentially remove the word consumer from the Consumer Protection Act
- [link|http://www.techworld.com/opsys/news/index.cfm?NewsID=1246&Page=1&pagePos=20|Nebraska Supreme Court]
     Geometry q - (inthane-chan) - (14)
         Without Trig? -NT - (mmoffitt)
         Do you mean the X and Y components? - (Another Scott) - (2)
             Yeah, that's it. - (inthane-chan)
             Heh, he said Geometry. You used Trigonometry. - (mmoffitt)
         Re: Geometry q - (deSitter)
         What I'm up to. - (inthane-chan) - (8)
             Simple optimization: - (admin) - (7)
                 That's exactly what I'm doing. - (inthane-chan) - (6)
                     And now I'm thinking of... - (inthane-chan) - (5)
                         360? - (admin) - (1)
                             Probably worth it - (deSitter)
                         A computational alternative. - (a6l6e6x) - (2)
                             This suddenly got much easier. - (inthane-chan)
                             That might not be how the library does it... - (ben_tilly)

Due to a vast miscalculation, it was accidentally swallowed by a small dog.
159 ms