Mogthew

Members
  • Content count

    16
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Mogthew

  • Rank
    Member
  1. Quaternion Object Rotation

    How do you render the objects - are you converting them back into Euler angles and then using glRotatef with them? AFAIK your general idea is correct, if you want to represent a bunch of rotations, you make them, and then combine then (and you're right, order matters). I think that the order you multiply them by should be the same order as the one you render them in, for example if you're multipling x * y * z, then when you convert to Euler angles you should rotate around the X axis, then Y then z. I'm still trying to get my head around Quaternions, but I _think_ this is correct. It's how they're being represented in my game at the moment anyway, and I'm doing a space themed game too ;p
  2. Hey all, I'm trying to convert two axis rotations into Quaternion rotations. When I constrain the rotations to one axis i can get it to work properly, but it requires I multiply it by a second quaternion of 90degres to get it to work. Note, this code doesn't compile, I will have the whichever two I'm not using commented out when running. [CODE] if(cameraXRotate > 180) { mult = -1; } /* rotation around the x axis*/ Quaternion cameraX = new Quaternion(mult * cameraXRotate * (float)(Math.PI / 180.0), new XYZ(1,0,0)); Quaternion camera = new Quaternion(90 * (float) (Math.PI / 180.0), new XYZ(0, 1, 0)); /* Rotation around the y axis*/ Quaternion cameraY = new Quaternion(-cameraYRotate * (float) (Math.PI / 180.0), new XYZ(0, 1, 0)); Quaternion camera = new Quaternion(90 * (float) (Math.PI / 180.0), new XYZ(1, 0, 0)); /* rotation around the z axis*/ Quaternion cameraZ = new Quaternion(cameraZRotate * (float)(Math.PI / 180.0), new XYZ(0,0,1)); Quaternion camera = new Quaternion(90 * (float) (Math.PI / 180.0), new XYZ(1, 0, 0)); [/CODE] Now, firstly, I'm not sure why I have to multiply by 90 to get all these to work, and I'm not sure why I have to reverse the rotation on the X axis if it's greater than 180. All I know, is that these seem to work properly on single axis rotation. This is the standard rotation code in openGL for the cameraX and Y, the negative cameraX is deliberate- [CODE] glRotatef(-cameraXRotate, 1, 0, 0); glRotatef(cameraYRotate, 0, 1, 0); [/CODE] Now, when I try to multiple the two rotations together, I get weird angles. This is my rotation code: [CODE] /* x axis rotation */ Quaternion cameraX = new Quaternion(mult * cameraXRotate * (float)(Math.PI / 180.0), new XYZ(1,0,0)).mul(new Quaternion(90 * (float)(Math.PI / 180.0), new XYZ(1,0,0))); /* y axis rotation */ Quaternion cameraY = new Quaternion(cameraYRotate * (float) (Math.PI / 180.0), new XYZ(0, 1, 0)).mul(new Quaternion(90 * (float)(Math.PI / 180.0), new XYZ(1,0,0))); Quaternion result = Quaternion.IDENTITY.mul(cameraX.mul(cameraY)); [/CODE] Any ideas? I'm really stuck on this one [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] Thanks!
  3. Super fast collision detection

    Yes, all ships have the same width / height, which makes this work. I'm not entirely sure how you manage to do "one comparison per object if you're lucky", how is this achieved? The sorting doesnt take too long, the memory is initialized at start up and then only modified at a later time, it's not created or deleted. Again, the code you posted is specific to check for object vs object collisions, there's nothing there that shows how to cull the object collision pairs down. Could you explain further?
  4. Super fast collision detection

    Quote:Original post by Atrix256 "As for the vsync, that's a good point, i'd not thought of that. Most systems these days use LCD's so yeah. Maybe 60fps should be my goal. " For the record vsync existed before LCD's, there's nothing special about LCD's and vsync... it was on CRT's too :P Haha, I know that :p My point was simply that LCD's have a default VSYNC of 60. whereas CRT's where higher, and therefore 60fps should be perfectly sufficient. @Net-Ninja, I didn't realise you could do that (with the sqrt) but I've been using the separate axis idea for a bit. The current operation works like this: Sort the list of ships by their X values. Get a bullet. Get the index of the minimum X value, using a binary search, that will collide with the bullet Get the index of the maximum X value, using a binary search, that will collide with the bullet Using the two indices in the array, do a brute force comparison between the two array indices Code looks like this: double width = baddies[0].getClipBoundsWidth(); double height = baddies[1].getClipBoundsHeight(); int xMinIndex = BSearch.min(xSort, (int)locationX, (int)width); int xMaxIndex = BSearch.max(xSort, (int)locationX, (int)width); if(xMinIndex == -1) return null; if(xMaxIndex < 0) xMaxIndex = xMinIndex; //System.out.println("Searching between " + xMinIndex + " and " + xMaxIndex); for(int x = xMinIndex;x <= xMaxIndex;++x) { if(baddies[xPtrs[x]].dgetY() + width > locationY && baddies[xPtrs[x]].dgetY() - width < locationY) { return baddies[xPtrs[x]]; } } return null; FYI: I use java to do spikes, if they look promising I port them into my game. I have a simple framework set up to do tests on multiple different collisions detection schemes and report the results. Also, I found that the collision detection like this was bound by calls to getX() and getY(), so I extracted the xvalues into an array (which is what the bsearch operates on).
  5. Super fast collision detection

    Hmm, alot of excellent suggestions. I'll definitely go and look at either setting up a grid or making some sort of tree. As for the vsync, that's a good point, i'd not thought of that. Most systems these days use LCD's so yeah. Maybe 60fps should be my goal. I've considered grids and spatial hashing, but haven't tried to implement. That'll be my goal now I think. Thanks for all the suggestions, I should be able to get where I want to go now :D
  6. Super fast collision detection

    I probably should've mentioned, but it's for a 2d game. Can you still use a binary space partition for 2d stuff? My knowledge of BSP tree's is veery limited, but if it's the next step I guess I don't have much choice. EDIT: In this game, there's no closed areas. It's totally open, basically a gigantic flat area. Are BSP tree's still applicable?
  7. Hey people, Currently, I'm working on a space scroller shoot-em-up and need some really fast collision detection algorithms. Basically, it needs to be able to handle about 1,000 ships and 1,000 bullets. Currently, my code offers only 50fps when this is happening, and I'd like it to be closer to 100 at least. The algorithm I'm using at the moment gets a ship and does a binary search to find all bullets within the range of colliding with the ship. By itself, it takes ~15ms(by itself it seems to run in 8ms, not sure why there's so much difference. Probably cache or something?) to run, then there's the updating of ships and the AI and other stuff to do. Basically, I just want to know if there's anything out there right now I can use to increase the throughput? Thanks!
  8. SDL + OpenGL font.

    Im not sure why the subtraction is there, it explains it in the tutorial so who knows. Also, the tutorial compiles and works as expected, so the code is how its supposed to be. " AFAIK, you cannot draw 2D with OpenGL. You must create a texture and render a quad to the screen as if 2D." Thats pretty much what im doing.
  9. SDL + OpenGL font.

    I have looked at ttf, but I'm not sure how the performance aspect would be, creating surfaces, blitting text, converting to texture and then rendering it on screen. I plan on using numbers that will change so static text isn't an option. The rendering function is as follows: bool MenuInterface::renderInterface(){ drawImage(sun, 0, 0, 1152, 864); Font::drawText("test...", 100, 100); return true; } EDIT: Also, for some reason when I change the glColor3f(1.0f,1.0f,1.0f); call to something other than 1.0 for the arguments, it shades the screen a different colour.
  10. SDL + OpenGL font.

    EDIT: Excuse the bad formatting, I don't know how to do the code windows :( Hi guys, I'm trying to get some text onto the screen for a test app. Using SDL as a wrapper for OpenGL. Currently I have them working together propperly, ie I have a texture drawn onto the screen. The current rendering code just renders a background image, and then tries to render text. The initialisation code for the font class i made is here (borrowing heavily from nehe tutorials): Font::Font(){ SDL_SysWMinfo window_info; SDL_GetWMInfo(&window_info); HWND window = window_info.window; HDC hDC = GetDC(window); HFONT font; // Windows Font ID HFONT oldfont; // Used For Good House Keeping list = glGenLists(96); // Storage For 96 Characters font = CreateFont( -12, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch "Courier New"); // Font Name oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want wglUseFontBitmaps(hDC, 32, 96, list); // Builds 96 Characters Starting At Character 32 SelectObject(hDC, oldfont); // Selects The Font We Want DeleteObject(font); initialised = true; DebugOutputFile::write("Successfully loaded font.\n"); } And is called via the following function: void Font::drawText(char *text, int x, int y){ if(!initialised) Dialog::errorBox("Font not initialised before use\n"); glLoadIdentity(); glColor3f(1.0f,1.0f,1.0f); glRasterPos2i(400,400); glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits glListBase(list - 32); // Sets The Base Character to 32 glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text glPopAttrib(); } Only the image shows up when the program runs, the text is no where to be seen. Is there something I've missed? If any of you could help me out here, it would be greatly appreciated :) Thanks for your time.
  11. Test

    Not sure if this is the right way to display codeso ill give it a shot. int initGL( GLvoid ) { /* Enable smooth shading */ glShadeModel( GL_SMOOTH ); /* Set the background black */ glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); /* Depth buffer setup */ glClearDepth( 1.0f ); /* Enables Depth Testing */ glEnable( GL_DEPTH_TEST ); /* The Type Of Depth Test To Do */ glDepthFunc( GL_LEQUAL ); /* Really Nice Perspective Calculations */ glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); buildFont( ); return( TRUE ); } EDIT: Didnt quite work as i expected, trying to get it to show it in a window with syntax highlighting.
  12. Page Flipping in SDL

    Vsync was off. If my app was doing nothing and using all cpu, thats pretty silly. Doesn't leave any room for actual calculations in the game. As for vysnc, I have the refresh rate override, so it would be capped at 100, it never _usually_ goes above 95. EDIT: After compiling the New source code for the app, my computer runs it for about 2 seconds, then quits. Also, theres a segfault somewhere oO Fixed the segfault, the App still runs at 100 fps in fullscreen mode (with vysnc off) I have a 3800 dual core, this shouldn't be happening (it maxes out 1 core at 95FPS). [Edited by - Mogthew on February 20, 2007 6:31:24 PM]
  13. Page Flipping in SDL

    The array has to be Unicode size for some reason, as pressing any of the arrow keys results in some value around 275. Fixed some memory leaks, but that's not where the performance degrading is happening. Even with all those problems, when I cover certain parts of the window (with other windows) the framerate jumps up to about 2k. The performance should still be way above what it is now. Thanks again for the heads up again, I didn't know that the TTF_Render_Text_solid() actually created a new copy of the surface, but come to think of it, makes alot of sense.
  14. Page Flipping in SDL

    My pc should run it fine, it's still fairly new. I'm kinda new so I don't know exactly how to put the code snippets in without just pasting them, so bare with me. Also this code is kinda messy, hadn't planned on cleaning it up for a bit, as it is still my first SDL app. #include "SDL/SDL.h" #include <string> #include <SDL/SDL_image.h> #include <SDL/SDL_ttf.h> #include <SDL/SDL_rotozoom.h> #include <windows.h> #include <cstdlib> #import "HRTimer.cpp" #import "Entity.cpp" #import "map.cpp" #import <fstream.h> //very messy I know. void getAndProcessEvents(); void render(); void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ); void apply_surface( int x, int y,int width, int height, SDL_Surface* source, SDL_Surface* destination ); void itoa(int x, char **pointer); void update(); SDL_Surface *load_image( std::string filename ) ; SDL_Surface *backgrounds; SDL_Surface *screen; SDL_Surface *tile; SDL_Event event; int xOffset = 0; int yOffset = 0; bool quit = false; int fpsMain = 0; SDL_Color textColor = { 255, 255, 255 }; TTF_Font* font = NULL; SDL_Surface *framerate = NULL; bool *keyArray; SDL_Surface *temp = NULL; char *fpschar; ofstream *log_file; int main( int argc, char* args[] ) { temp = new SDL_Surface(); log_file = new ofstream("log_file.txt"); int width = 256; int height = 256; char *pathArray[width]; *pathArray = new char[width]; for(int x = 0;x < height;x++) pathArray[x] = (char*)malloc(sizeof(char)*width); FILE *fp = fopen("out.txt","r"); char c; int x = 0; for(int x = 0;x < height;x++) for(int y = 0;(c = (char)fgetc(fp)) != EOF && y < width;y++) pathArray[x][y] = c; Map *map = new Map(pathArray,height, width); keyArray = new bool[65536]; // dont quit without reason :) if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return 1; } if( TTF_Init() == -1 ) { return false; } screen = SDL_SetVideoMode( 800, 600, 32,SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF ); temp = SDL_CreateRGBSurface( SDL_HWSURFACE, 800, 600, 32, 0, 0, 0,0); HRTimer *hr = new HRTimer(); double fpsTime =hr->currentTimeMS(); double baseTime = fpsTime; int fps = 0; font = TTF_OpenFont( "lazy.ttf", 32); backgrounds = load_image("background.png"); tile = load_image("tile.jpg"); while( quit == false ) { if(hr->currentTimeMS() - fpsTime > 1000){ fpsMain = fps; fps = 0; fpsTime = hr->currentTimeMS(); itoa(fpsMain, &fpschar); framerate = TTF_RenderText_Solid( font, fpschar, textColor ); *log_file << fpsMain; } //While there's an event to handle //update(); render(); getAndProcessEvents(); // commented out all the sleep functions so it runs as fast as possible. //double sleepTime = (baseTime+2.09999) - hr->currentTimeMS(); //if(sleepTime > 0) // Sleep(sleepTime); baseTime+=2.09999; fps++; } log_file->close(); return 0; } void getAndProcessEvents(){ while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } if(event.type == SDL_KEYDOWN){ int keyCode = event.key.keysym.sym; keyArray[keyCode] = true; } if(event.type == SDL_KEYUP){ int keyCode = event.key.keysym.sym; keyArray[keyCode] = false; } } if(keyArray[SDLK_LEFT]) xOffset--; if(keyArray[SDLK_RIGHT]) xOffset+=2; if(keyArray[SDLK_UP]) yOffset--; if(keyArray[SDLK_DOWN]) yOffset++; if(keyArray[SDLK_ESCAPE]) quit = true; } void render(){ SDL_Rect rect; rect.x = 450; rect.y = 450; //SDL_Rect offset; //offset.w = 50; //offset.h = 50; /*for(int x = -1;x < 17;x++) for(int y = -1;y < 13;y++){ offset.x = x*50 + (xOffset%50); offset.y = y*50 + (yOffset%50); SDL_BlitSurface( tile, NULL, temp, &offset ); }*/ //SDL_Rect rect; rect.x = 450; rect.y = 450; rect.w = 40; rect.h = 40; SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0,0xFF)); SDL_BlitSurface( framerate, NULL,screen, &rect ); SDL_Flip(screen); } SDL_Surface *load_image( std::string filename ) { SDL_Surface* loadedImage = NULL; SDL_Surface* optimizedImage = NULL; loadedImage = IMG_Load( filename.c_str() ); if( loadedImage != NULL ) { optimizedImage = SDL_DisplayFormat( loadedImage ); SDL_FreeSurface( loadedImage ); if(optimizedImage != NULL){ Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ); SDL_SetColorKey( optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey ); } } return optimizedImage; } void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { SDL_Rect offset; offset.x = x; offset.y = y; SDL_BlitSurface( source, NULL, destination, &offset ); } void itoa(int x, char **pointer){ if(x == 0){ *pointer = new char[2]; pointer[0][0] = '0'; pointer[0][1] = '\0'; return; } int tempy = x; int length = 0; while(tempy != 0){ tempy/=10; length++; } *pointer = new char[length+1]; for(int i = length-1;x != 0;i--){ pointer[0][i] = x%10 +48; x/=10; } // patch it up :) pointer[0][length] = '\0'; return; } // lol ignore this. void update(){ for(int x = 0;x < 1000;x++){ for(int y = 0;y < 1000;y++){ int temp = x*y; temp+=50000; } } }
  15. Page Flipping in SDL

    I just tested it in fullscreen and the same thing happened, 90 FPS. This is so frustrating, it should work without any issues at all. My pc shouldn't be struggling to get 100fps in software mode when its doing nothing. It still uses all my CPU as well. Looks like I'll have to move onto something else which is annoying because I thought SDL would be good. Thanks for the heads up on the Software in windowed mode thingy though, I didn't know about that.