gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > BIOS calls

#24905 - lordmetroid - Fri Aug 13, 2004 1:33 pm

I'm currently in need of finding out the angle between 2 points...
I notice there is an atan2 function through the bios, do you know how slow it is?

Is there any better way to find out an angle... i've been trying to make up a system using the scalar product aka dot product however as the vectors wouldn't be normalized I would need a divide to utilise it... And I've been trying to figure out a way to not make that divide. However without success.
_________________
*Spam*
Open Solutions for an open mind, www.areta.org

Areta is an organization of coders codeing mostly open source project, but there is alot of sections like GBA dev, Language learning communities, RPG communities, etc...

#24908 - ScottLininger - Fri Aug 13, 2004 2:22 pm

I assume you mean that you have three points? An origin point and then two arbitrary locations "elsewhere" on the screen?

#24911 - NoMis - Fri Aug 13, 2004 2:45 pm

I don't know how fast these bios functions actually are but there is a huge overhad in calling them wich is like 50 cycles as far as i know.

Here is an old thread about this topic that may be helpfull:
http://forum.gbadev.org/viewtopic.php?t=3692&start=0&postdays=0&postorder=asc

NoMis

#24917 - ecurtz - Fri Aug 13, 2004 4:38 pm

I recently posted an atan2 in assembly I'm trying to get people to test. Check this thread for the implementation and this thread for a discussion of the algorithm.

It should be MUCH faster than the BIOS, assuming you have about 400 bytes of IWRAM to spare.

#24952 - lordmetroid - Fri Aug 13, 2004 8:33 pm

Yeah of course three points... the origo (camera), the angle I want to test it against and the point for testing
_________________
*Spam*
Open Solutions for an open mind, www.areta.org

Areta is an organization of coders codeing mostly open source project, but there is alot of sections like GBA dev, Language learning communities, RPG communities, etc...

#24956 - ScottLininger - Fri Aug 13, 2004 9:12 pm

Three points in 3-D space or 2-D?

(I'm just curious what you're trying to implement.)

#24968 - lordmetroid - Fri Aug 13, 2004 10:54 pm

2D... Even though it's a 3D engine, there is no height in the tilemap system I uses...
And so the world becomes 3D only through the polygons the "tiles" or rather 'cubes' contains... What I'm trying to do is a fast way to cull all cubes not in my frustum...
_________________
*Spam*
Open Solutions for an open mind, www.areta.org

Areta is an organization of coders codeing mostly open source project, but there is alot of sections like GBA dev, Language learning communities, RPG communities, etc...

#24969 - ecurtz - Fri Aug 13, 2004 11:10 pm

I'm not up on my 3D, but you can doing culling by testing just the sign of the dot (I think) product of your point and the frustum plane. That will be a lot faster than calculating the actual angle. You don't need to normalize the vectors since you only care about the sign. (Somebody will correct me if I'm wrong here...)