• ### Popular Now

• 9
• 10
• 9
• 10
• 10

#### Archived

This topic is now archived and is closed to further replies.

# Max Speed configuration

This topic is 6697 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Thats a wierd way of spelling velocity....

##### Share on other sites
I know now I spelled it wrong, but that still doesn't answer my question ...

##### Share on other sites
Actually, the sin and cos functions are probably more likely to slow it down than a few multiplications, but overall if this is only done once every game loop it should not make a lot of difference. There's a few optimisations you could make to your function no doubt, and you could use a lookup table for sin and cos if you wanted to speed that up. You could also precalculate 10 * 3.14159 / 180, if your compiler doesn't automatically do this. Post a reply if you need any help with these concepts.

Anyhow, the way I usually think about the speed of things is by comparing them to a software blitter for an image. In this case I suspect that the time it takes for your ship to be drawn onscreen is a lot longer than for this little calculation - though there's still room here for improvement.

Good luck

Starfall

##### Share on other sites
Okay, thanks. I am going to precalculate 10*3.14159/180. I'll try the look-up for sin and cos, but I'm still a little unsure on how to do this. Just hold the different values in an array and use the one based on Player.direction?

##### Share on other sites
Don't bother, the compiler already precalculated that for you.

Sin and cosine lookup will help the most, try to minimize the size of the table so it caches better (like store only 90 degrees of the table, which has all the values you need.)

But don't go crazy on this yet, just keep it simple for now, and then profile later to see if this is an area taking a huge chunk out of performance (and I'm guessing it probably won't be.)

##### Share on other sites
Surprisingly enough, not all compilers do precalculate those things, which is why I suggested it.

Regards

Starfall

if(Player.x_vol*Player.x_vol+Player.y_vol*Player.y_vol < Player.Max_Speed*Player.Max_Speed) { Player.x_vol += ((float)sin((Player.Direction-1)*10 * 3.14159/180)*Player.Acceleration); Player.y_vol -= ((float)cos((Player.Direction-1)*10 * 3.14159/180)*Player.Acceleration); }