Propeller - An Example SGDK-Based Game Engine
Moderator: BigEvilCorporation
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
For starters, I remember you mentioning that you had a method to generate cos tables. Also, I had been skimming some articles about raster transformations (http://www.catalase.com/optrot3d.htm) and was curious if something along these lines have been implemented for 2d sprite rotation, seeing how goplanes had a rotating sprite.
I see that was done by having separate images, which I kind of figured. I think it would be kind of cool to not have to draw the rotations but either do so on the fly (expensive) or somehow pre-render these into VRAM.
Eventually, I want to put together a more comprehensive game/demo, when I get time (???)
I see that was done by having separate images, which I kind of figured. I think it would be kind of cool to not have to draw the rotations but either do so on the fly (expensive) or somehow pre-render these into VRAM.
Eventually, I want to put together a more comprehensive game/demo, when I get time (???)
Yes it is very easy. This is a bit more fancy generator and is only 31 lines of code. It generates fixed point integer tables.
I think everything should be self explanatory. The only thing that may confuse some too lazy to look at the source code is the divider parameter. What this does is lets you set how much of a sine you want. For example using a value of four would result in 1/4 of a full sine period which is 2*pi or 360 degrees. This allows you to do code size/speed tradeoffs. For example if you use a divider of four you can take advantage of symmetry and reflection with simple conditional statements. Using a divider of one removes the need for conditional statements.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* Compile gcc main.c -O2 -o sinetab -lm */
int main(int argc,char**argv){
long n,i;
double mul,div;
FILE*fp;
if(argc!=5){
/* Divider refers to how much of the sine is stored for example to do 0-90 degrees use a value of 4 */
printf("Usage %s amount multiplier divider outputfile\n",argv[0]);
return 1;
}
n=strtol(argv[1],0,0)-1;
if(n<=0){
puts("Cannot have less than or equal to one sine entry");
return 1;
}
mul=strtod(argv[2],0);
div=strtod(argv[3],0);
fp=fopen(argv[4],"w");
fputc('\t',fp);
for(i=0;i<n;++i){
fprintf(fp,"%d,",(int)round(sin((double)i/(double)n*M_PI*2.0/div)*mul));
if((i&15)==15)
fputs("\n\t",fp);
}
fprintf(fp,"%d\n",(int)round(sin((double)i/(double)n*M_PI*2.0/div)*mul));
fclose(fp);
return 0;
}
I recalled that goplanes had a rotating main sprite, I thought there was a chance something like sprite transformation ( prerendering or on the fly) might be implemented in propeller. There isnt, which is kind of expected.
Also, I like to see how other people implement random stuff to see if I get any ideas in general.
Also, I like to see how other people implement random stuff to see if I get any ideas in general.
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
I updated Propeller to SGDK 1.00.
https://dl.dropboxusercontent.com/u/173 ... .1.0.3.zip
Let me know if you see any problems.
https://dl.dropboxusercontent.com/u/173 ... .1.0.3.zip
Let me know if you see any problems.
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
Re: Propeller - An Example SGDK-Based Game Engine
Hi,
I updated the links.
thanks,
djcc
I updated the links.
thanks,
djcc