1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - FX -
3   File:     fx_trig.h
4 
5   Copyright 2003-2008 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-09-18#$
14   $Rev: 8573 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 
19 #ifndef NITRO_FXTRIG_H_
20 #define NITRO_FXTRIG_H_
21 
22 #include <nitro/fx/fx.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 //----------------------------------------------------------------------------
29 // Type definition
30 //----------------------------------------------------------------------------
31 #ifdef SDK_FX_DYNAMIC_TABLE
32 extern fx16 FX_SinCosTable_[];
33 #else
34 extern const fx16 FX_SinCosTable_[];
35 #endif
36 
37 //----------------------------------------------------------------------------
38 // Declaration of function
39 //----------------------------------------------------------------------------
40 
41 // deg must be in fx32/fx16 format
42 #define FX_DEG_TO_RAD(deg)            ((fx32)((FX64C_TWOPI_360 * (deg) + 0x80000000LL) >> 32))
43 #define FX_DEG_TO_IDX(deg)            ((u16) ((FX64C_65536_360 * (deg) + 0x80000000000LL) >> 44))
44 
45 // rad must be in fx32/fx16 format
46 #define FX_RAD_TO_DEG(rad)            ((fx32)((FX64C_360_TWOPI * (rad) + 0x80000000LL) >> 32))
47 #define FX_RAD_TO_IDX(rad)            ((u16)((FX64C_65536_TWOPI * (rad) + 0x80000000000LL) >> 44))
48 
49 #define FX_IDX_TO_RAD(idx)            ((fx32)((FX64C_TWOPI_65536 * (idx) + 0x80000LL) >> 20))
50 #define FX_IDX_TO_DEG(idx)            ((fx32)((FX64C_360_65536 * (idx) + 0x80000LL) >> 20))
51 
52 SDK_DECL_INLINE fx16 FX_SinIdx(int idx);
53 SDK_DECL_INLINE fx16 FX_CosIdx(int idx);
54 
55 u16     FX_AtanIdx(fx32 x);
56 u16     FX_Atan2Idx(fx32 y, fx32 x);
57 
58 fx16    FX_Atan(fx32 x);
59 fx16    FX_Atan2(fx32 y, fx32 x);
60 
61 u16     FX_AsinIdx(fx32 x);
62 u16     FX_AcosIdx(fx32 x);
63 
64 fx64c   FX_SinFx64c(fx32 rad);
65 fx64c   FX_CosFx64c(fx32 rad);
66 
67 //----------------------------------------------------------------------------
68 // Implementation of inline function
69 //----------------------------------------------------------------------------
70 
71 /*---------------------------------------------------------------------------*
72   Name:         FX_SinIdx
73 
74   Description:  Obtain approximation of sine by table reference
75 
76   Arguments:    idx        treat (2 * pi / 65536) as 1
77 
78   Returns:      approximated sine value in fx16 format
79  *---------------------------------------------------------------------------*/
FX_SinIdx(int idx)80 SDK_INLINE fx16 FX_SinIdx(int idx)
81 {
82     SDK_MINMAX_ASSERT(idx, 0, 65535);
83 
84     return FX_SinCosTable_[((idx >> 4) << 1)];
85 }
86 
87 /*---------------------------------------------------------------------------*
88   Name:         FX_CosIdx
89 
90   Description:  Obtain approximation of cosine by table reference
91 
92   Arguments:    idx        treat (2 * pi / 65536) as 1
93 
94   Returns:      approximated cosine value in fx16 format
95  *---------------------------------------------------------------------------*/
FX_CosIdx(int idx)96 SDK_INLINE fx16 FX_CosIdx(int idx)
97 {
98     SDK_MINMAX_ASSERT(idx, 0, 65535);
99 
100     return FX_SinCosTable_[((idx >> 4) << 1) + 1];
101 }
102 
103 #ifdef __cplusplus
104 }/* extern "C" */
105 #endif
106 
107 #endif
108