• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

We're also offering banner ads on our site from just \$5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

# Mogthew

Member Since 20 Feb 2007
Offline Last Active Apr 24 2012 07:31 PM

### Chaining quaternion rotations

03 February 2012 - 05:31 PM

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.

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));

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-
glRotatef(-cameraXRotate, 1, 0, 0);
glRotatef(cameraYRotate, 0, 1, 0);

Now, when I try to multiple the two rotations together, I get weird angles. This is my rotation 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));

Any ideas? I'm really stuck on this one

Thanks!

### Super fast collision detection

07 December 2010 - 03:33 PM

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!

### SDL + OpenGL font.

08 November 2007 - 08:30 PM

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;
}

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");
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.

### Test

08 November 2007 - 08:23 PM

Not sure if this is the right way to display codeso ill give it a shot.
int initGL( GLvoid )
{

/* 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.

### Page Flipping in SDL

20 February 2007 - 01:07 AM

Hi people, I have been playing around with SDL a little (I'm moving from java to SDL) and have come across a problem with SDL's page flipping abilities. From my understanding, after creating an SDL_Surface* named screen(or anything else), and initialising it with the following line: screen = SDL_SetVideoMode( 800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); it should be able to use page flipping and yet , when I call SDL_Flip(screen) it doesn't. I know the capabilites are there, because when I was using java, a simple full-screen program could run at about 4k fps (when VSync was off). In SDL my program, which is a simple program to test framerate moderation, runs at only 80-95 FPS. When all frame rate moderation is turned off, that still remains the same. In a while(true){//render and stuff here} loop, it will go extremely slowly. When I commented out the SDL_Flip() and instead wrote the un-restrained FPS into an output-file it showed that the fps was running into the thousands (possibly tens of thousands, I dont remember) In the SDL documentation is says that if page flipping is unavailable it will use SDL_UpdateRect(blah blah blah), and when I replaced SDL_Flip() with SDL_UpdateRect() it ran at the same FPS, implying it's not page flipping propperly. SDL wont allow page flipping in my program( and yet I know my GFX card supports it - 7600gt). My question is; Why wont SDL allow my pc to use page flipping when it clearly supports it ?
void render(){
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);
}
(Yes it could be optimised, but I just want to get page flipping working propperly first). If I can't get page flipping working propperly I'll have to use another library as max CPU usage with only 90 ish FPS doing nothing is really bad. Anyone have any suggestioins ?

PARTNERS