Jump to content
  • Advertisement
Sign in to follow this  
Grimfate126

Custom trig functions needed.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi. im working on a 2D game, and im using a very good library, thich supports rotation, distortion, etc. BUT, it has one major flaw: it has no trig functions. :( (which is kinda weird) in my game, i will need the following functions: sin cosin atan2 so, my question is, is there ANY way to handwrite these functions and have them return a value?? cause im stumped.. if there is, could someone please share a way to do it? thanks!!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by jyk
What language and library are you using?


im using C++, programming for the PSP. im using a library called OSLIB (old-school library) google it for more info. its actually a very nice library. can hanlde a lot, (i actually had 400 circles bouncing around the screen, rotation, changing size, all at around a 50 -60 FPS. (psp only allows 60 max, dunno why not any more.))

thanks!

Share this post


Link to post
Share on other sites
If its on a PSP then just make a precomputed trig table. When you call sin(.3595), or whatever number, have it look up the closest return value to that number. You can make the trig table for like every 5 degress and come off fine.

Share this post


Link to post
Share on other sites
I don't know anything about PSP programming either, but my best guess is the PSP does not have the C Standard Library, so using math.h is not an option.
I will do some research into this, and hopefully reply soon with a more helpful answer.

:)

-edit: beat by dpadam450. yes, i believe a precomputed table works well, and if I'm not mistaken, that would work much faster than even the cslib trig functions.

Share this post


Link to post
Share on other sites
Or, if you want full precission, you can use a CORDIC algorithm.

If you have rotations, you could also rotate (1,0) by a certain angle alpha, and the resulting vector is (cos(alpha),sin(alpha)).


Share this post


Link to post
Share on other sites
ok, thanks for all the realies! the reason why ic ant use math.h (yes, PSP does have one) is because its part of the standard library, and i cant use it without using the PSP SDK's standard files (basic I/O, and all the operating files) when i use those, i cant use OSLIB, (they both have theyre own systems, which interfere with another, resuling in 50 pages of error.) about the trig tables, i dont really understand what youre saying, can anyone explain more?

ALSO, if anyone want more deatil, here is what im trying to get it:

ok, i have a bullet, and i want to shoot it based on a cursor. (cross hair) im using this technique:

find the angle between the player and cursor:

angle = atan2(cursor_y - player_y, cursor_x - player_x)

then make a trajectory based on that angle:

traX = cos(angle) * speed
traY = sin(angle) * speed


and this work fine and dandy. but in my game, i need a player which rotates, and ive tried numerous rotation althogrims, which kill my FPS. OSLib is the only lib which does it using hardware and GU accleration. so, now i have the problem of using the trig functions.

Share this post


Link to post
Share on other sites
You don't need trig to do that:
scalefactor = speed / sqrt(sqr(cursor_x - player_x) + sqr(cursor_y - player_y));
traX = (cursor_x - player_x) * scalefactor;
traX = (cursor_y - player_y) * scalefactor;


Of course, which is faster depends on whether cos and sin beat sqrt and sqr. But the chances are they don't.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bob Janova
You don't need trig to do that:
scalefactor = speed / sqrt(sqr(cursor_x - player_x) + sqr(cursor_y - player_y));
traX = (cursor_x - player_x) * scalefactor;
traX = (cursor_y - player_y) * scalefactor;


Of course, which is faster depends on whether cos and sin beat sqrt and sqr. But the chances are they don't.




hmm, thats a good concept, never really thought about that. linear interpolation right? square root is a very expensive operation, but square is nothing. cos and sin are equal. ill try that. run a debug test.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!