#10362 - Mr. GBA - Wed Sep 03, 2003 2:00 pm
Has anyone had any success in getting this to work? I mean, the "test.bin" inlcuded works but whenever I recompile the code the gba file does not appear in 3d.
Could someone please tell me what to add to the file(below) to get the mode7 effect to work: thanks
/********************************************************
*
*
* by devoto
*
*
********************************************************/
#include<math.h> //sign and cos stuff
#include"gba.h"
#include"screenmode.h"
#include"keypad.h"
#include"sprite.h"
#include"backgrounds.h"
#include "dma.h"
#include "interupts.h"
#include "sunset.h"
FIXED SIN[360]; //my LUTs for sign and cosign
FIXED COS[360];
FIXED div[160]; //a LUT table for divides
//global variables as it is kind of hard to pass variables to an interupt
int angle = 0; //rotation angle
FIXED x = 0; //x and y background scroll
FIXED y = 0;
int height = (32<<8); //height of the player
void GetInput(void);
///main entry point from the boot.asm startup file
int main(void)
{
u16 loop,loopx,loopy;
Bg bg2;
bg2.charBaseBlock = 0;
bg2.colorMode = BG_COLOR_256;
bg2.number = 2;
bg2.screenBaseBlock = 30;
bg2.wraparound = 1;
bg2.size = ROTBG_SIZE_256x256;
EnableBackground(&bg2);//this sets up my background if all the members are filled in
//and validates the tiledata and mapdata pointers
SetMode(MODE_2 | BG2_ENABLE);
//the palette is from a pcx file but I deleted all the graphics data and just put to tiles in there manualy
DMA_Copy(3,(void*)SunsetPalette,(void*)BGPaletteMem,128,DMA_32NOW); //da palette
DMA_Copy(3,(void*)SunsetDatatemp, (void*)bg2.tileData,32, DMA_32NOW); //just two tiles a black and a white
//just alternates the tiles to put blocks on the screen
for(loopy = 0; loopy<32; loopy++)
{
for(loopx = 0; loopx<16; loopx++)
{
if( loopx&1 && loopy&2)
bg2.mapData[loopy*16+loopx] = (1<<8)+1;
if( !(loopx&1) && !(loopy&2))
bg2.mapData[loopy*16+loopx] = (1<<8)+1;
}
}
//sine cos LUT
for(loop = 0; loop < 360; loop++)
{
SIN[loop] = (FIXED)(sin(RADIAN(loop)) * (float)(1<<16)); //sin and cos are computed and cast to fixed //fixed
COS[loop] = (FIXED)(cos(RADIAN(loop)) * (float)(1<<16));
}
//calculate my divide look up table so I can use the property x/y = x*(1/y) = x*div[y]
for(loop=0;loop <160;loop++)
{
div[loop] = (FIXED)( (float)( (1<<16)/loop) ); //our fixed point divide table is 8.24 (24 bits of fraction)
}
// EnableInterupts(INT_HBLANK | INT_VBLANK); //turn on my interupts...dont realy need vblank
while(1)
{
GetInput();
while(REG_VCOUNT < 160){}
}
return(0);
}
void GetInput(void)
{
static int angletemp = 0; //this to give us a bit slower change in angle. If i incremented it once per frame
//it would change 60 times a secont that is way too fast so I increment angletemp and divide by 64 before puting in angle
//. That means that angle temp has to increase
//by 64 before angle will increase by one.
if(!(*KEYS & KEY_LEFT)) //to move left and right is a simple sin of the angle...the shift is just to control how fast we move
{
y+=(SIN[angle])>>3;
x-=(COS[angle])>>3;
}
if(!(*KEYS & KEY_RIGHT))
{
y-=(SIN[angle])>>3;
x+=(COS[angle])>>3;
}
if(angle < 270) //since moving up and down we just rotate the angle by 90
angle += 90;//its okay that we destroy it because we restore it at the end of this function
else
angle-=270;
if(!(*KEYS & KEY_UP))
{
y-=(SIN[angle])>>3;
x+=(COS[angle])>>3;
}
if(!(*KEYS & KEY_DOWN))
{
y+=(SIN[angle])>>3;
x-=(COS[angle])>>3;
}
if(!(*KEYS & KEY_L))
{
angletemp--;
if(angletemp<0)
angletemp = (359<<6);
}
if(!(*KEYS & KEY_R))
{
angletemp++;
if(angletemp > (359<<6))
angletemp = 0;
}
if(!(*KEYS & KEY_A))
{
height++;
}
if(!(*KEYS & KEY_B))
{
height--;
}
if(!(*KEYS & KEY_START))
{
}
if(!(*KEYS & KEY_SELECT))
{
}
angle = angletemp>>6; //this is where I do the divide by 64
}
_________________
my dev/business site:
http://codebytesdev.afraid.org
Could someone please tell me what to add to the file(below) to get the mode7 effect to work: thanks
/********************************************************
*
*
* by devoto
*
*
********************************************************/
#include<math.h> //sign and cos stuff
#include"gba.h"
#include"screenmode.h"
#include"keypad.h"
#include"sprite.h"
#include"backgrounds.h"
#include "dma.h"
#include "interupts.h"
#include "sunset.h"
FIXED SIN[360]; //my LUTs for sign and cosign
FIXED COS[360];
FIXED div[160]; //a LUT table for divides
//global variables as it is kind of hard to pass variables to an interupt
int angle = 0; //rotation angle
FIXED x = 0; //x and y background scroll
FIXED y = 0;
int height = (32<<8); //height of the player
void GetInput(void);
///main entry point from the boot.asm startup file
int main(void)
{
u16 loop,loopx,loopy;
Bg bg2;
bg2.charBaseBlock = 0;
bg2.colorMode = BG_COLOR_256;
bg2.number = 2;
bg2.screenBaseBlock = 30;
bg2.wraparound = 1;
bg2.size = ROTBG_SIZE_256x256;
EnableBackground(&bg2);//this sets up my background if all the members are filled in
//and validates the tiledata and mapdata pointers
SetMode(MODE_2 | BG2_ENABLE);
//the palette is from a pcx file but I deleted all the graphics data and just put to tiles in there manualy
DMA_Copy(3,(void*)SunsetPalette,(void*)BGPaletteMem,128,DMA_32NOW); //da palette
DMA_Copy(3,(void*)SunsetDatatemp, (void*)bg2.tileData,32, DMA_32NOW); //just two tiles a black and a white
//just alternates the tiles to put blocks on the screen
for(loopy = 0; loopy<32; loopy++)
{
for(loopx = 0; loopx<16; loopx++)
{
if( loopx&1 && loopy&2)
bg2.mapData[loopy*16+loopx] = (1<<8)+1;
if( !(loopx&1) && !(loopy&2))
bg2.mapData[loopy*16+loopx] = (1<<8)+1;
}
}
//sine cos LUT
for(loop = 0; loop < 360; loop++)
{
SIN[loop] = (FIXED)(sin(RADIAN(loop)) * (float)(1<<16)); //sin and cos are computed and cast to fixed //fixed
COS[loop] = (FIXED)(cos(RADIAN(loop)) * (float)(1<<16));
}
//calculate my divide look up table so I can use the property x/y = x*(1/y) = x*div[y]
for(loop=0;loop <160;loop++)
{
div[loop] = (FIXED)( (float)( (1<<16)/loop) ); //our fixed point divide table is 8.24 (24 bits of fraction)
}
// EnableInterupts(INT_HBLANK | INT_VBLANK); //turn on my interupts...dont realy need vblank
while(1)
{
GetInput();
while(REG_VCOUNT < 160){}
}
return(0);
}
void GetInput(void)
{
static int angletemp = 0; //this to give us a bit slower change in angle. If i incremented it once per frame
//it would change 60 times a secont that is way too fast so I increment angletemp and divide by 64 before puting in angle
//. That means that angle temp has to increase
//by 64 before angle will increase by one.
if(!(*KEYS & KEY_LEFT)) //to move left and right is a simple sin of the angle...the shift is just to control how fast we move
{
y+=(SIN[angle])>>3;
x-=(COS[angle])>>3;
}
if(!(*KEYS & KEY_RIGHT))
{
y-=(SIN[angle])>>3;
x+=(COS[angle])>>3;
}
if(angle < 270) //since moving up and down we just rotate the angle by 90
angle += 90;//its okay that we destroy it because we restore it at the end of this function
else
angle-=270;
if(!(*KEYS & KEY_UP))
{
y-=(SIN[angle])>>3;
x+=(COS[angle])>>3;
}
if(!(*KEYS & KEY_DOWN))
{
y+=(SIN[angle])>>3;
x-=(COS[angle])>>3;
}
if(!(*KEYS & KEY_L))
{
angletemp--;
if(angletemp<0)
angletemp = (359<<6);
}
if(!(*KEYS & KEY_R))
{
angletemp++;
if(angletemp > (359<<6))
angletemp = 0;
}
if(!(*KEYS & KEY_A))
{
height++;
}
if(!(*KEYS & KEY_B))
{
height--;
}
if(!(*KEYS & KEY_START))
{
}
if(!(*KEYS & KEY_SELECT))
{
}
angle = angletemp>>6; //this is where I do the divide by 64
}
_________________
my dev/business site:
http://codebytesdev.afraid.org