#161217 - BenRK - Wed Jul 30, 2008 10:40 pm
Hello, me again. I have my game running with an Ortho view. I'm trying to make the game room 800x600 with the player viewing 256x192 of that room at any given time, easy enough to move the background around, but there's a circle on the screen that needs to move around, as well as properly move when the camera does. I know how to do both, but when I move the camera, I find that the circle loops around a 256x192 area, where the camera starts. I want to turn this off, so it will loop around the 800x600 game room when I want it to, not the fixed 256x192 area it currently does. Any help would be nice.
~BenRK
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161219 - silent_code - Wed Jul 30, 2008 11:27 pm
Well, just check if the circle's screen position is inside the screen / view area. If it is, display the circle, if it is not, don't. :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#161220 - BenRK - Thu Jul 31, 2008 12:10 am
I forgot to mention that the circle doesn't smoothly move out of the screen on the bottom and right side of the screen, but it does on the top and left side of the screen, which is another reason I want to turn it off.
Also, I'm thinking I posted this in the wrong section, so if it's possible to move it to the correct section, that would be great, as I'm very sure I haven't been here long enough to have the power to do so.
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161223 - koryspansel - Thu Jul 31, 2008 12:58 am
I'm not sure I quite understand...so hopefully this isn't way off base. This is, basically, just an elaboration of what silent_code has stated.
First, what I would do is make sure the coordinates for any objects in the room are relative to the origin of the room (which you may already do). That would also include the camera coordinates. Next, at draw time, go through your list of objects to draw (just the circle?) and transform each object's coordinates to be relative to the screen (ie. ObjPos - CameraPos). Now your coordinates are relative to the camera, so just check that they're in the correct range (0 <= X < 256 & 0 <= Y < 192) and you're all done.
EDIT: Also, if you want the object to wrap around the entire room, you'll need to handle that yourself by making sure the coordinates are in the correct range.
--
Kory
#161224 - BenRK - Thu Jul 31, 2008 1:07 am
Yes, I understand that bit (and I know I'll have to make it loop around the game room my self), but what's really getting me right now is that it doesn't smoothly exit the screen on the right and bottom sides of the screen.
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161225 - koryspansel - Thu Jul 31, 2008 1:18 am
What do you mean by "smoothly" exactly? Does it just disappear when it reaches the edge of the screen?
I assume you're drawing a textured quad? Where is the origin of the quad? If it's at the upper-left I don't see a reason why it wouldn't draw correctly at the right and bottom edges. However, if the quad is centered, you would have to account for that when checking the coordinates against the screen.
Just some thoughts.
--
Kory
#161226 - BenRK - Thu Jul 31, 2008 1:34 am
I'm actually drawing 24 triangles (12 for the circle (which is a 12-gon), and 12 for a white outline). It's origin is the exact center of it, and the radius varies.
So, by what you're saying, I'll have to make the origin the bottom left corner of the circle/12-gon, but draw the triangles and stuff elsewhere, aka, where the old origin was?
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161231 - koryspansel - Thu Jul 31, 2008 2:12 am
You could do it that way if you want to (probably make the origin the top-left though, to be consistent with the screen). However, the easiest way would be to just take into account the size of the circle when checking to see if it's on screen.
Let's say you have a circle with a radius of 10 and that you've already transformed your coordinates relative to the screen, say at (260, 96).
So, if you check the circle coordinates against only the size of the window, your program is going to cull the circle since it lies outside the bounds. But, since the circle is centered at the the coordinates, it should still be drawing a portion of it at the edge.
Assuming this is the problem, I think the best solution would be, when checking the circle coordinates, to "expand" the screen size by the radius of the circle.
So, with a radius of 10, you'd check your coordinates against X: (-5 to 261) and Y: (-5 to 197). Hopefully that is a clear enough explanation.
--
Kory
#161248 - BenRK - Thu Jul 31, 2008 8:42 am
The problem with that is that the DS is doing this automatically, with nothing being said by me.
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161259 - silent_code - Thu Jul 31, 2008 10:48 am
Now you need to give us some example binary. Maybe also some source code (the culling - which you can post here). This is getting too confusing otherwise.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#161283 - BenRK - Thu Jul 31, 2008 9:39 pm
Here's everything relevant.
Sorry for the messiness of the code.
Code: |
while (game==1)
{
if (start==0)
{
// Turn on everything
//powerON(POWER_ALL);
// Setup the Main screen for 3D
videoSetMode(MODE_0_3D);
// IRQ basic setup
irqInit();
irqSet(IRQ_VBLANK, 0);
// initialize the geometry engine
glInit();
// enable antialiasing
glEnable(GL_ANTIALIAS);
// setup the rear plane
glClearColor(0,0,0,31); // BG must be opaque for AA to work
glClearPolyID(63); // BG must have a unique polygon ID for AA to work
glClearDepth(0x7FFF);
// Set our viewport to be the same size as the screen
glViewport(0,0,255,191);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof32(0, 256, 0, 192,0,-100);
//gluPerspective(70, 256.0 / 192.0, 0.1, 100);
// Set the color of the vertices
glColor3f(1, 1, 1);
for (i=0;i<1;i++)
{
evo[i].x = 128;
evo[i].y = 96;
evo[i].radi = PA_RandMax(30)+5;
evo[i].red = PA_RandMax(255);
evo[i].green = PA_RandMax(255);
evo[i].blue = PA_RandMax(255);
evo[i].minspeed = 2;
evo[i].maxspeed = 5;
evo[i].dir = PA_RandMax(512);
evo[i].energy = 100;
evo[i].hunger = 0;
evo[i].mutation = 0;
evo[i].en0 = 10;
evo[i].hun0 = 60;
evo[i].en1 = 0;
evo[i].hun1 = 0;
evo[i].use = 1;
evo[i].move = 1;
}
start = 1;
}
scanKeys();
//input
if (keysHeld() & KEY_UP)
{
if (camy>-408)
{
camy-=1;
}
}
if (keysHeld() & KEY_DOWN)
{
if (camy<0)
{
camy+=1;
}
}
if (keysHeld() & KEY_LEFT)
{
if (camx<0)
{
camx+=1;
}
}
if (keysHeld() & KEY_RIGHT)
{
if (camx>-544)
{
camx-=1;
}
}
if (keysHeld() & KEY_A)
{
evo[0].hunger=0;
}
if (keysHeld() & KEY_B)
{
evo[0].energy=100;
}
//top screen
PA_OutputText(1,0,0,"Name: Tset");
PA_OutputText(1,0,1,"Energy: %d ", evo[0].energy);
PA_OutputText(1,0,2,"Hunger: %d ", evo[0].hunger);
PA_OutputText(1,0,3,"Mutation: %d ", evo[0].mutation);
PA_OutputText(1,0,15,"Camy: %d ",camy);
PA_OutputText(1,0,16,"Camx: %d ",camx);
PA_OutputText(1,0,17,"");
PA_OutputText(1,0,18,"");
//ds specific, several attributes can be set here
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
// Set the current matrix to be the model matrix
glMatrixMode(GL_MODELVIEW);
//Push our original Matrix onto the stack (save state)
glPushMatrix();
glLoadIdentity();
glTranslate3f32(camx,camy,0);
glBegin(GL_QUADS);
glColor3b(0,0,0);
glVertex3v16(0,0,2);
glColor3b(0,0,0);
glVertex3v16(800,0,2);
glColor3b(1,0,251);
glVertex3v16(800,600,2);
glColor3b(1,0,251);
glVertex3v16(0,600,2);
glEnd();
//update the evolites
for (i=0;i<1;i++)
{
if (evo[i].use == 1)
{
if (evo[i].move == 1)
{
evo[i].x = evo[i].x+(evo[i].minspeed*PA_Cos(evo[i].dir));
evo[i].y = evo[i].y-(evo[i].minspeed*PA_Sin(evo[i].dir));
if (evo[i].en1==evo[i].en0)
{
evo[i].energy -= 1;
evo[i].en1 = 0;
}
else
{
evo[i].en1++;
}
}
else
{
evo[i].energy++;
}
if (evo[i].energy == 100)
{
evo[i].move = 1;
}
if (evo[i].energy == 0)
{
evo[i].move = 0;
}
if (evo[i].hunger == 100)
{
evo[i].use = 0;
}
if (evo[i].hun1==evo[i].hun0)
{
evo[i].hunger += 1;
evo[i].hun1 = 0;
}
else
{
evo[i].hun1++;
}
evo[i].dir++;
}
}
//draw the evolites
for (i=0;i<1;i++)
{
if (evo[i].use==1)
{
glLoadIdentity();
DrawEvolite(evo[i].x>>8,evo[i].y>>8,evo[i].radi,evo[i].red,evo[i].green,evo[i].blue);
}
}
// Pop our Matrix from the stack (restore state)
glPopMatrix(1);
// flush to screen
glFlush(0);
//a handy little built in function to wait for a screen refresh
swiWaitForVBlank();
}
return 0;
}
void DrawEvolite(u8 x, u8 y, u8 radi, u8 red, u8 green, u8 blue)
{
glBegin(GL_TRIANGLES);
for (i=0;i<=res;i++)
{
glColor3b(255,255,255);
glVertex3v16(x,(y-radi),radi);
glColor3b(255,255,255);
glVertex3v16(x+(radi*PA_Cos((512/res)*i))/255,(y-radi)-(radi*PA_Sin((512/res)*i))/255,0);
glColor3b(255,255,255);
glVertex3v16(x+(radi*PA_Cos((512/res)*(i+1)))/255,(y-radi)-(radi*PA_Sin((512/res)*(i+1)))/255,0);
}
glEnd();
glBegin(GL_TRIANGLES);
for (i=0;i<=res;i++)
{
glColor3b(red,green,blue);
glVertex3v16(x,(y-radi),1);
glColor3b(red,green,blue);
glVertex3v16(x+(radi*PA_Cos((512/res)*i))/255,(y-radi)-(radi*PA_Sin((512/res)*i))/255,1);
glColor3b(red,green,blue);
glVertex3v16(x+(radi*PA_Cos((512/res)*(i+1)))/255,(y-radi)-(radi*PA_Sin((512/res)*(i+1)))/255,1);
}
glEnd();
} |
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161288 - Cydrak - Thu Jul 31, 2008 10:39 pm
BenRK wrote: |
The problem with that is that the DS is doing this automatically, with nothing being said by me. |
I expect it's not so much that, but the u8 arguments to DrawEvolite, which limits their position to a range of 0..255 (since 255 == 2**8 - 1).
Most computers use a fixed numeric precision, making wraparound (or roundoff, for floats) a natural consequence when the limit is exceeded.
By the way, there's another catch here. To the ARM CPU (e.g., GBA and DS), integers are always 32 bits. This means you should avoid smaller variables: far from being faster, the compiler will generate larger, slower code to simulate them! The main exception are arrays: RAM access is less restricted, so if you only need small values, you can benefit from the space savings.
#161289 - BenRK - Thu Jul 31, 2008 11:06 pm
I'm not to worried about the size or speed of the game, as it's not going to be terribly huge in the end, but that's good info to know.
What would I use instead of u8 that wont give me the limit of 255 (honestly, I'm very new to programming in anything other than GML, which, if you didn't know, handles a lot of stuff in the background that you need to worry about in C/C++)?
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161290 - Griffin - Thu Jul 31, 2008 11:07 pm
BenRK wrote: |
What would I use instead of u8 that wont give me the limit of 255 |
u16/s16/u32/s32. I would just use a plain old int though.
#161293 - Cydrak - Thu Jul 31, 2008 11:24 pm
When in doubt, "int" and "long" are fine.
"int" tends to be a convenient size--I think at least 16 bits. "long" is at least 32. It depends on the hardware; for DS, and many modern PCs, they are both 32 bits. (Google C int types and find out more than you ever cared to know.)
An integer with 32 bits has ~4 billion possible values; 16 bits give you a range of 2**16 or 65536. Signed integers, the default, split this in half (ie, s16 allows -32768 .. 32767 instead of u16's 0 .. 65536). Since ~65,000 isn't really that big, 32 bits is more popular.
If you do need a specific range or size, you can use the types provided by libnds (u8, s32, etc), or in <stdint.h> (uint8_t, int32_t...).
Last edited by Cydrak on Fri Aug 01, 2008 12:22 am; edited 1 time in total
#161294 - BenRK - Fri Aug 01, 2008 12:00 am
Well, it's working properly now.
On an unrelated question, is it possible to make a new string from an array of characters? I need to make a random name generator, and it would be best if I saved the names as strings (to make things more compatible with the game I'm "porting" from the PC).
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161295 - Griffin - Fri Aug 01, 2008 12:13 am
Quote: |
On an unrelated question, is it possible to make a new string from an array of characters? I need to make a random name generator |
Do you mean totally random like
Code: |
int name_length = rand() % 12 + 4; /* 3-14 letter long name */
char *name = malloc(length);
if(name == NULL)
/* Error */
int i;
for(i = 0; i < name_length - 1; i++)
name[i] = (rand() % 26) + 97;
name[name_length - 1] = 0; /* Terminate string */
name[0] -= 32; /* Convert the first letter to uppercase */
/* Do stuff with name */
free(name);
|
Note: Code might not actually compile.
#161296 - BenRK - Fri Aug 01, 2008 12:23 am
There would be some logic to it. Mine would come up with names like Ucofi, Lol, Yeti, etc. I've written it out in GML. A purely random string generator would come up with stuff like sdfge, hfghr, werijg, etc. Those don't seem like names at all!
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161297 - Griffin - Fri Aug 01, 2008 12:31 am
Okay.. It should be easy enough to convert it in to C code.
#161298 - silent_code - Fri Aug 01, 2008 12:32 am
Those are hackery names! :^)
Also: Take a look at <string.h>.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#161301 - BenRK - Fri Aug 01, 2008 12:38 am
It will be easy. I just have to create the array of letters and the logic stuff that puts them together in strings 3-8 characters long. I just wanted to know if I could add the letters from the array together to create the string.
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161302 - Griffin - Fri Aug 01, 2008 12:38 am
BenRK wrote: |
It will be easy. I just have to create the array of letters and the logic stuff that puts them together in strings 3-8 characters long. I just wanted to know if I could add the letters from the array together to create the string. |
You'll want to look at Code: |
char * strcat ( char * destination, const char * source ) |
It sticks stuff together
#161308 - BenRK - Fri Aug 01, 2008 12:47 am
Sorry, but I really don't know what all of that means. I can assume it's adding characters together, but I don't know how I would use it. Like I said before, I'm very new to C/C++, let alone DS homebrew, so forgive me for my lack of experience. Heck, it took me several weeks to figure out how to draw the 12-gon on the screen! I haven't even started with stylus input, sound, and I'm not even going to touch Wi-Fi till the end of development!
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161310 - Griffin - Fri Aug 01, 2008 12:54 am
Example (no error checking for the sake of brevity):
Code: |
#include <string.h>
#include <stdio.h>
int main()
{
char name[16];
char *name_starts[3] = { "Ae", "Bu", "Caa" };
char *name_ends[3] = { "gi", "up", "la" };
strcpy(name, name_starts[rand() % 3]); /* First part of name */
strcat(name, name_ends[rand() % 3]); /* Concatenate (append) the end of the name */
puts(name);
}
|
#161311 - BenRK - Fri Aug 01, 2008 1:01 am
That seems to be adding parts of words together. What I did in GML was put vowels in one array, and the rest in another one, and then added them together using a function.
GML code
Code: |
{
var n;
n="";
if floor(random(2))=1
{
for(i=0;i<2+random(4);i+=1)
{
if (i=0||i=2||i=4||i=6)
n+=v[floor(random(5))]
else
n+=c[floor(random(21))]
}
}
else
{
for(i=0;i<2+random(4);i+=1)
{
if (i=0||i=2||i=4||i=6)
n+=c[floor(random(21))]
else
n+=v[floor(random(5))]
}
}
return n;
} |
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161312 - Griffin - Fri Aug 01, 2008 1:15 am
Code: |
/* Remember to free the pointer that gets returned eg:
char *name = get_random_name();
Do stuff with name
free(name);
*/
char *get_random_name(void)
{
const char *v = { "aeiou" };
const char *c = { "bcdfghjklmnpqrstvwxyz" };
char *n = calloc(24, 1);
int i;
if(rand() & 1) {
for(i = 0; i < 2 + rand() % 4; ++i) {
if(i & 1) /* If i is even */
n[i] = v[rand() % 5];
else
n[i] = c[rand() % 21];
}
}
else {
for(i = 0; i < 2 + rand() % 4; ++i) {
if(!i & 1) /* If i is not even */
n[i] = v[rand() % 5];
else
n[i] = c[rand() % 21];
}
}
n[0] -= 32; /* Capitalise */
return n;
}
|
It would be good to remove that if-else on the rand() & 2 but I'm lazy!
First five names outputted on my laptop: Dodas, Oxus, Dok, Ihab, Ufu.
I like that name generator.
#161313 - BenRK - Fri Aug 01, 2008 1:32 am
I'm getting an error when I try to compile my game now.
Quote: |
C:\devkitPro\myProjects\evolitesDS>make clean
clean ...evolitesDS
C:\devkitPro\myProjects\evolitesDS>make
main.c
c:/devkitPro/myProjects/evolitesDS/source/main.c:305: error: expected identifier
or '(' before '{' token
make[1]: *** [main.o] Error 1
make: *** [build] Error 2
C:\devkitPro\myProjects\evolitesDS>pause
Press any key to continue . . . |
But yeah, it's a good random name generator!
Edit: Never mind. Had a ";" when I didn't need it. Now to just modify it a little so it will output the name on the DS, and all will be good.
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161314 - Griffin - Fri Aug 01, 2008 1:36 am
Edit: Oh you fixed it!
#161315 - BenRK - Fri Aug 01, 2008 1:37 am
Heh, though I can't seem to get it to output onto the DS. Any help?
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161325 - silent_code - Fri Aug 01, 2008 10:23 am
Please elaborate on the current means of outputting text in your program.
Could you post some example source code?
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#161336 - BenRK - Fri Aug 01, 2008 6:59 pm
What do I mean by outputting text on the screen? Making the letters on the screen be drawn onto it.
There's some of the source code earlier in the topic.
_________________
EvolitesDS - Possibly coming out some day... maybe...
#161351 - silent_code - Fri Aug 01, 2008 9:37 pm
I didn't ask what you mean by outputting letters, just how you do it now. ;^)
Either ask PAlib people or don't use PAlib and look up libnds' ansi console example.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#161353 - BenRK - Fri Aug 01, 2008 9:50 pm
Since I'm using PAlib for the fun, simple 2D stuff, and the random name is really going to be the only random text thing, I'll head over there and ask, and hope for a response this time.
Anyway, thanks for your help. Everyone.
_________________
EvolitesDS - Possibly coming out some day... maybe...