# Mogthew

Member

16

122 Neutral

• 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. ## Chaining quaternion rotations

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. ## Super fast collision detection

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.