#162862 - ZeroSum - Sun Sep 14, 2008 11:32 pm
I've been using floats for my calculations so far and I got to the point where a certain amount of geometry would cause to framerate to dive. I thought I needed to add some culling so I added a simple check to see if vertexs were out of camera view. Of course, I also did this in floats and it has made my framerate even worse with fewer polys drawn!
I understand now that I should be working in fixed point, and I understand it up to a point (no pun intended). What I don't understand is how to perform the operations in the code below with fixed point numbers. At first I tried to change all floats to v16 and (obviously :p) this failed, but I'm not sure what I should be doing.
Do I need to be shifting everywhere to make everything the right format? Or am I completly wrong? It that would make the code quite ugly and hard to follow. What are the correct ways to perform add/sub/multiply/divide on fixed point numbers using libnds? I have some of my code below to give an idea of what I am trying to do.
Thanks for reading.
This is what I'm using to cull:
And this is one of my main drawing functions:
I understand now that I should be working in fixed point, and I understand it up to a point (no pun intended). What I don't understand is how to perform the operations in the code below with fixed point numbers. At first I tried to change all floats to v16 and (obviously :p) this failed, but I'm not sure what I should be doing.
Do I need to be shifting everywhere to make everything the right format? Or am I completly wrong? It that would make the code quite ugly and hard to follow. What are the correct ways to perform add/sub/multiply/divide on fixed point numbers using libnds? I have some of my code below to give an idea of what I am trying to do.
Thanks for reading.
This is what I'm using to cull:
Code: |
bool DmRenderer::CullCheck( float curX, float curZ )
{ // Divide by 10.0 to match the camera and world coords because // the world is scaled by 10.0 when drawn to fit larger maps. float camX = m_Interface.Graphics->GetCamX() / 10.0; float camZ = m_Interface.Graphics->GetCamZ() / 10.0; // Check the coords passed in are in range of visible X. if( curX < (camX - 0.6 ) ) return false; if( curX > (camX + 0.6 ) ) return false; // Check the coords passed in are in range of visible Z. if( curZ < (camZ - 0.5 ) ) return false; if( curZ > (camZ + 0.5 ) ) return false; // Passed cull check. return true; } |
And this is one of my main drawing functions:
Code: |
void Renderer::DrawFloors( Level* level, std::string texture) { // Get the size of the level. int TotalX = level->GetCellsX(); int TotalY = level->GetCellsY(); float CellWidth = 0.1; float CellHeight = 0.1; // Calculate where to start the grid so it is centered on cam 0,0,0. float StartPointX = 0.0 - (CellWidth * (TotalX / 2 )) ; float StartPointZ = 0.0 - (CellHeight * (TotalY / 2) ) ; // Current position to drawn. Incremented in loops. float currentX = StartPointX ; float currentZ = StartPointZ ; // Bind the passed in texture. TexturePool->BindTexture( texture ); // Tell the graphics class we're going to draw. Graphics->Begin(); // Loop through the grid of cells. for( int y = 0; y < TotalY; y++ ) { for( int x = 0; x < TotalX; x++ ) { // If this cell is a passageway... if( level->GetCellType(x, y) == Passage ) { // and passes the cull check... if( CullCheck( currentX, currentZ ) ) { // Draw it.. Graphics->DrawPlaneFloor( floattov16( currentX ), floattov16( 0.2 ), floattov16( CellWidth ), floattov16( CellHeight ), floattov16( currentZ ) ); } } // Every X move along one cell width. currentX += CellWidth; } // Move back to the first X pos and increment Z to drawn next row. currentX = StartPointX ; currentZ += CellHeight; } Graphics->End(); } |