Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualDissipate

Posted 15 January 2013 - 12:11 AM

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


#6Dissipate

Posted 15 January 2013 - 12:04 AM

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

and here is the ::Orbit code where I calculate the movement:
// ********************************************************************* //// 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

#5Dissipate

Posted 14 January 2013 - 09:40 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())

 

 

and here is the ::Orbit code where I calculate the movement:

 

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


Thanks


#4Dissipate

Posted 14 January 2013 - 09:37 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;					// 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		// Check for user input		g_App.DetectInput();		// Render		g_App.Render();		// 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())

and here is the ::Orbit code where I calculate the movement:

// ********************************************************************* //// 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 70 and 71.

Thanks


#3Dissipate

Posted 14 January 2013 - 09:36 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;					// 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		// Check for user input		g_App.DetectInput();		// Render		g_App.Render();		// 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())
and here is the ::Orbit code where I calculate the movement:
// ********************************************************************* //// 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 70 and 71.

Thanks

#2Dissipate

Posted 14 January 2013 - 09:35 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;					// 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		// Check for user input		g_App.DetectInput();		// Render		g_App.Render();		// 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())
and here is the ::Orbit code where I calculate the movement:
// ********************************************************************* //// 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 70 and 71.

Thanks

PARTNERS