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.

Beginners > sin cos undeclared?

#10636 - goro - Thu Sep 11, 2003 10:11 am

Hi,

I'm doing GBA Junkie's tutorial on maps and BG's and I get
Code:
C:/PROJECTS/GBA/4/4.cpp:243: `sin' undeclared (first use this function)
C:/PROJECTS/GBA/4/4.cpp:243: (Each undeclared identifier is reported only once
   for each function it appears in.)
C:/PROJECTS/GBA/4/4.cpp:244: `cos' undeclared (first use this function)


when I try to compile :-
Code:

#include"gba.h"         //GBA register definitions
#include"bg.h"          //background definitions
#include<math.h>

#include"exptiles.h"
#include"128128map.c"

//Rotation variables (don't worry about them here) done in later chapter
FIXED angle = 0;
FIXED zoom = 1<<8;  //zoom is a fixed point number

FIXED SIN[360]={0x0000, edited to save forum space, 0xFFFFFB88,}; 
                 
FIXED COS[360]={0x10000,edited to save forum space, 0xFFF6,};     
             
char RotIndexCounter = 0;  //global to keep track of rotation indexes used

void EnableBackground(Bg* bg)
{edited to save forum space}

void UpdateBackground(Bg* bg)
{edited to save forum space}

void RotateBackground(Bg* bg, int angle,int center_x, int center_y, FIXED zoom)
{

   center_y = (center_y * zoom)>>8;
   center_x = (center_x * zoom)>>8;

   bg->DX = ((bg->x_scroll<<8)-center_y*SIN[angle]-center_x*COS[angle]);
   bg->DY = ((bg->y_scroll<<8)-center_y*COS[angle]+center_x*SIN[angle]);

   bg->PA = (COS[angle]*zoom)>>8;  //cos&sin are LUTs that are .8 fixed numbers
   bg->PB = (SIN[angle]*zoom)>>8;  //zoom is also fixed
   bg->PC = (-SIN[angle]*zoom)>>8;
   bg->PD = (COS[angle]*zoom)>>8;
}

Bg bg2;

void WaitForVsync()
{   while((volatile u16)REG_VCOUNT != 160){}}

void GetInput()
{edited to save forum space}

int main()
{
   int index = 0;  //generic loop variables
   u16 loop;
   u16* temp;      //temporary storage pointer

   //compute my Look up tables (Rotation stuff again)
   for(loop = 0; loop < 360; loop++)
   {
                  SIN[loop] = (FIXED)(sin(RADIAN(loop)) * 256);  //sin and cos are computed and cast to fixed                     //fixed
      COS[loop] = (FIXED)(cos(RADIAN(loop)) * 256);
   }

   //set mode 2 and enable sprites and 1d mapping
   SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);

   -edited to save forum space
   
                //Main Game loop
   while(1)
   {
      GetInput();    //check for input
      RotateBackground(&bg2,angle,119,79,zoom);       WaitForVsync();               UpdateBackground(&bg2);
   }
   return(0);
}


I've tried creating a make.bat file and adding -lm but that doesn't work either. please help

#10638 - consolecoder - Thu Sep 11, 2003 11:51 am

Your source is a cpp file and surely need to know that sin and cos are in a c lib.

Try to add prototypes starting with : extern "C"

#10639 - goro - Thu Sep 11, 2003 12:31 pm

Ok. I don't quite understand but I'm experiencing a similar problem with my bg palette data.

the header file (that I have included) has in it :-
Code:
extern const u16 backgroundPalette[256];


I have included palOut.cpp in my project (this contains the palette array)

but I still get
Code:

undefined reference to `backgroundPalette'


I understand that it is probably not seeing palOut.cpp.

How do I make it see it. The compiler I'm using is MS Visual Studio.

Edit : If I edit make.bat to include the .cpp files, I think it goes a step further but then says
Code:
 palOut.cpp:4:syntax error before '=' token


here is the code in palOut.cpp (line 4)
Code:
const u16 backgroundPalette[256]ALIGN4 = {
0x0000,0x7e6a,0x7463,0x7f52,0x7d44,0x352c,0x


What should I do to fix this!?!

#10664 - jenswa - Thu Sep 11, 2003 8:02 pm

You prolly shoud link palout.cpp in your makefile for visual studio
(i use make.bat, so i don't know exactly if i am right) and somewhere in the main source you should have it declared as extern.
_________________
It seems this wasn't lost after all.

#10677 - yaustar - Fri Sep 12, 2003 3:20 am

I dont think it likes the 'ALIGN4' bit brfore the '=' sign.

cant see why it doesnt recognise 'sin' or 'cos', you have the right header file for it...
_________________
[Blog] [Portfolio]

#10679 - tepples - Fri Sep 12, 2003 5:58 am

There seems to be another thread in the graphics section that gives the solution to the ALIGN4 issue.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#10706 - yaustar - Sat Sep 13, 2003 1:30 am

I dont understand a part of your code..

if you have already decleared the values in
Code:
FIXED SIN[360]={0x0000, edited to save forum space, 0xFFFFFB88,};
                 
FIXED COS[360]={0x10000,edited to save forum space, 0xFFF6,};   


why recalculatte them later in
Code:
//compute my Look up tables (Rotation stuff again)
   for(loop = 0; loop < 360; loop++)
   {
                  SIN[loop] = (FIXED)(sin(RADIAN(loop)) * 256);  //sin and cos are computed and cast to fixed                     //fixed
      COS[loop] = (FIXED)(cos(RADIAN(loop)) * 256);
   }

_________________
[Blog] [Portfolio]

#10718 - goro - Sat Sep 13, 2003 10:10 am

I really couldn't tell you cos I'm a noobie. It's from GBA Junkies tutorial.
I've moved onto mode0 animating/updating/scrolling tile backgrounds but I'll get back to mode1/rotation when I get everything else working properly.

#10730 - cooky - Sat Sep 13, 2003 3:31 pm

Goro you seem to have every problem I have. I'll point you in the right direction later.

Edit: this might be what is wrong. (Although I carn't garentee it. My make file consistently tries and wins at confusing me)

http://forum.gbadev.org/viewtopic.php?t=2001

#10746 - yaustar - Sun Sep 14, 2003 1:16 am

THing is, in gbajunkies' tutorials, this
Code:

FIXED SIN[360]={0x0000, edited to save forum space, 0xFFFFFB88,};
                 
FIXED COS[360]={0x10000,edited to save forum space, 0xFFF6,};   


is written as
Code:
FIXED SIN[360];
                 
FIXED COS[360];


Also, do you have the latest DevKitAdv?
If all else fails, you can use my precalculated headers for SIN and COS at http://www31.brinkster.com/yaustar/dev/gba.html
_________________
[Blog] [Portfolio]