Jump to content

  • Log In with Google      Sign In   
  • Create Account


-1.#IND00 in my debug text out


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Dissipate   Members   -  Reputation: 323

Like
0Likes
Like

Posted 14 January 2013 - 09:16 PM

Hi,

I am displaying -1.#IND00 as the m_fX and m_fY positions of a square that is supposed to orbit. The code works but I only get the error output to my debug textout function when I create the object before 1 second (ie the FPS is caculated). The Orbit Code calculates the required movement needed by observing the amount of frametime passed.

Is there a work around or correction or should I wait 1 second before drawing anything...?

The Game Loop:

 

// Game loop
    while (g_App.GetD3DStatus())
    {
        // If there are any window messages, process them
        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        // Quit if message recieved
        if (msg.message == WM_QUIT)
        break;
        if (KEY_DOWN(VK_ESCAPE)) PostMessage(hWnd, WM_DESTROY, 0, 0);
        if (KEY_DOWN(VK_MBUTTON)) PostMessage(hWnd, WM_DESTROY, 0, 0);

        // Read the Performance Counter, which may be divided by the
        // counter frequency to determine the time in seconds
        __int64 iiCurrentTimeStamp = 0;
        QueryPerformanceCounter((LARGE_INTEGER*)&iiCurrentTimeStamp);
        float dt = (iiCurrentTimeStamp - iiPrevTimeStamp) * fSecondsPerCount;

        // Increment the frame count.
        iNumberOfFrames++;

        // Accumulate how much time has passed.
        fTimeElapsed += dt;

        // Has one second passed?--we compute the frame statistics once
        // per second.  Note that the time between frames can vary so
        // these stats are averages over a second.
        if( fTimeElapsed >= 1.0f )
        {
            // Frames Per Second = numFrames / timeElapsed,
            // but timeElapsed approx. equals 1.0, so
            // frames per second = numFrames.
            g_uFPS = (UINT)iNumberOfFrames;

            // Average time, in milliseconds, it took to render a single frame.
            g_dMilliSecPerFrame = 1000.0f / g_uFPS;

            // Save the framerate to tell CApplication, sprites and meshes
            g_uFrameRate = g_uFPS;
        
            strcat_s(c, "\n");
            fputs(c, pFile);
            
            // debug text out framerate before it's reset
            g_Text->SetRowEx(TXT_FRAMERATE, "FPS = ", g_uFrameRate);
            g_Text->SetRowEx(TXT_FRAMETIME, "FrameTime = ", g_dMilliSecPerFrame);

            // Reset time counter and frame count to prepare for computing
            // the average stats over the next second.
            fTimeElapsed    = 0.0f;
            iNumberOfFrames = 0;
            iFrameCycles    = 0;

            // Increase the number of seconds passed
            iNumSecs++;
        } // end if


        //g_App.DetectPicking();                // Detect mouse over mesh & turn off lighting

        // Check for user input
        g_App.DetectInput();

        // Render
        g_App.Render();

        g_Text->SetRowEx(TXT_DELTA, "delta = ", fDelta);

        // Prepare for next iteration: The current time stamp becomes
        // the previous time stamp for the next iteration.
        iiPrevTimeStamp = iiCurrentTimeStamp;

        iFrameCycles++;

    } // end while (g_App.GetD3DStatus())


 

// ********************************************************************* //
// Name: Orbit															 //
// Description: Calculate a circular motion 		  					 //
// ********************************************************************* //
void CShape::Orbit(float fX, float fY, float fZ)
{
	float fU = (float) g_uFrameRate / g_dMilliSecPerFrame;

	// Calc xyz velocity's cirular points
	m_fXV = 0.0f; //(float)(sin(fX) * 12.0f) * 800.0f;
	m_fYV = 0.0f;
	m_fZV = 0.0f; //(float)(cos(fZ) * 25.0f) * 800.0f;

	// Ensure XYZ is within the limits otherwise flip the direction headed
	BoundsCheck();

	// Stop movement if required
	if (m_uDirection & SHAPE_NONE)
	{
		m_fXV = 0.0f;
		m_fYV = 0.0f; // No movement
		m_fZV = 0.0f;
		m_uDirection = 0; 
		g_Text->SetRowEx(TXT_SHAPEDIR,  "m_uDirection = ", m_uDirection);
	}

	// Move on X-axis
	if (m_uDirection & SHAPE_LEFT)
	{
		m_fXV = -m_fV; // Going left
		m_uDirection |= SHAPE_LEFT;
		m_uDirection &= ~SHAPE_RIGHT;
		g_Text->SetRowEx(TXT_SHAPEDIR,  "m_uDirection = ", m_uDirection);
	}
	else if (m_uDirection & SHAPE_RIGHT)
	{
		m_fXV = m_fV; // Going right
		g_Text->SetRowEx(TXT_SHAPEDIR,  "m_uDirection = ", m_uDirection);
	}

	// Move on Y-axis
	if (m_uDirection & SHAPE_UP)
	{
		m_fYV = -m_fV; // Going up
		g_Text->SetRowEx(TXT_SHAPEDIR,  "m_uDirection = ", m_uDirection);
	}
	else if (m_uDirection & SHAPE_DOWN)
	{
		m_fYV = m_fV; // Going down
		g_Text->SetRowEx(TXT_SHAPEDIR,  "m_uDirection = ", m_uDirection);
	}

	// Move on Z-axis
	if (m_uDirection & SHAPE_FORWARD)
	{
		m_fZV = -m_fV; // Going forward
		g_Text->SetRowEx(TXT_SHAPEDIR,  "m_uDirection = ", m_uDirection);
	}
	else if (m_uDirection & SHAPE_BACKWARD)
	{
		m_fZV = m_fV; // Going backward
		g_Text->SetRowEx(TXT_SHAPEDIR,  "m_uDirection = ", m_uDirection);
	}

	// Units per second over frames per second
	m_fX += m_fXV / fU;
	m_fY += m_fYV / fU;
	m_fZ += m_fZV / fU;

	g_Text->SetRowEx(TXT_SHAPEXYZ,  "m_fX = ", m_fX);
	g_Text->SetRowEx(TXT_SHAPEXYZ2, "m_fZ = ", m_fZ);
	//g_Text->SetRowEx(TXT_SHAPEDIR,  "m_uDirection = ", m_uDirection);
	
	// Apply this to a matrix
    D3DXMatrixTranslation(&m_matTranslate, m_fX, m_fY, m_fZ);
}// Orbit

 

 




Please do also suggest if I am doing all this correctly. I did have the formulae for circular movement in the first few lines of commented out code in the CShape::Orbit function but I didnt know how to apply it to the calculated Units per second calculation.

I worked out that Movement per frame would be = Units per second / (FPS / FrameTime)
Error is produced from Lines

g_Text->SetRowEx(TXT_SHAPEXYZ,  "m_fX = ", m_fX);	g_Text->SetRowEx(TXT_SHAPEXYZ2, "m_fZ = ", m_fZ);

at the end of the function.

EDIT** initialised the FPS to something I saw currently as well as the milliseconds per frame as it was a divide by zero error

Thanks


Edited by Dissipate, 15 January 2013 - 12:11 AM.


Sponsor:

#2 slicer4ever   Crossbones+   -  Reputation: 3416

Like
2Likes
Like

Posted 15 January 2013 - 01:39 AM

</p><pre>
float fU = (float) g_uFrameRate / g_dMilliSecPerFrame;</pre>

creates a division by 0 until g_uFramerate != 0. (not certain if your edit is referring to this, and if your problems are fixed?)

 

their's also an issue with your time-step code: http://gafferongames.com/game-physics/fix-your-timestep/

 

        if( fTimeElapsed >= 1.0f ){
            fTimeElapsed    = 0.0f;
        }

instead of resetting to 0, subtract by 1. this is very important for maintaining consistent frame times.


Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#3 Dissipate   Members   -  Reputation: 323

Like
0Likes
Like

Posted 15 January 2013 - 02:32 AM

creates a division by 0 until g_uFramerate != 0. (not certain if your edit is referring to this, and if your problems are fixed?)

I sorted the div/0 by pluggin in numbers initially so they are not zero to begin with.

 

I am reading the article now...

 

 

instead of resetting to 0, subtract by 1. this is very important for maintaining consistent frame times.

I dont understand... what is the effect of subtracting by 1. Oh I see maybe the overflow is kept for the next second (?) What I mean is the bit left over after 1 sec (eg. 1.000463 - 1 = 0.000463) which can accumulated towards the next second.

So the so called seconds that go by aren't really real seconds, as they roll over continuosly..?

 

I dont think I am correctly moving by a certain Unit Per Second as when I add Sleep(5) to the Render() function The Square moves even faster. How should I be doing this?



#4 slicer4ever   Crossbones+   -  Reputation: 3416

Like
2Likes
Like

Posted 15 January 2013 - 03:01 AM

creates a division by 0 until g_uFramerate != 0. (not certain if your edit is referring to this, and if your problems are fixed?)

I sorted the div/0 by pluggin in numbers initially so they are not zero to begin with.

 

I am reading the article now...

 

 

instead of resetting to 0, subtract by 1. this is very important for maintaining consistent frame times.

I dont understand... what is the effect of subtracting by 1. Oh I see maybe the overflow is kept for the next second (?) What I mean is the bit left over after 1 sec (eg. 1.000463 - 1 = 0.000463) which can accumulated towards the next second.

So the so called seconds that go by aren't really real seconds, as they roll over continuosly..?

 

I dont think I am correctly moving by a certain Unit Per Second as when I add Sleep(5) to the Render() function The Square moves even faster. How should I be doing this?

 

 

what you appear to be doing right now(i may be wrong, as i've not given a heavy look at your code), is trying to do a delta time step, to run at variable frame's per second.  this is fine and dandy if you really want that, but instead, i'd recommend trying to target a specefic frame-rate, a locked frame rate across all your builds makes making things consistant much easier.

 

the idea of the time step is to update the program more frequently if it's falling behind(and well hopefully stabilize quickly), essentially by subtracting by 1(or w/e your time step is, such as 1/60th a second or 1/30th a second are very common), you are preserving that "roll over" seconds, so that the program can consistently update itself at a fixed time-step, this is important considering that many modern os's can switch back to your program in ~16ms(which this is important to know for how sleep works, since sleep does not guarantee that you well return in the amount of time you request to sleep for), and makes it very important for preserving "roll over seconds", otherwise if you don't preserve these missed second you'll get estatic fps changes.

 

so, here you are, you have a time step, now forget about passing that delta time to other objects, and instead update the object by one "step" when you are inside your timestep, subtract, and wait for another step to come around.  this makes programming object interaction across different computer's very consistent, because they don't move at variable speeds, and instead each object well move at the same speed on all computers, even if the computer begins to fall behind which that computer well just try to take more steps(because your preserving that "roll over" by subtracting instead of resetting it.)

 

hopefully this comes across coherently(i have a sneaking suspicion being up this late is making me ramble on at the moment.)


Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS