d1ff1cul1010

10-11-2014, 12:00 PM

Hello guys. I'm learning about how to make a triangle move in a circle and I'm trying to decipher the coding, but having a hard time understanding the math used in these functions.

.arcsynthesis.org/gltut/Positioning/Tutorial%2003. www and com

first:

void ComputePositionOffsets(float &fXOffset, float &fYOffset)

{

const float fLoopDuration = 5.0f;

const float fScale = 3.14159f * 2.0f / fLoopDuration;

float fElapsedTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;

float fCurrTimeThroughLoop = fmodf(fElapsedTime, fLoopDuration);

fXOffset = cosf(fCurrTimeThroughLoop * fScale) * 0.5f;

fYOffset = sinf(fCurrTimeThroughLoop * fScale) * 0.5f;

}

I dont understand what the purpose of fScale is, and I don't get what the purpose of finding the modulus of the the "fElapsedTime and the fLoopDuration, do the milliseconds keep counting upwards indefinitely and the fCurrentTimeThroughLoop is just calculating what part of each current "five second cycle" we are at?

I have a somewhat decent understanding of it, probably enough to move on in the book assuming it will go into more detail on these types of functions later, but I feel I can understand more, if anyone could elaborate more on some of the code here that would be great.

thanks

.arcsynthesis.org/gltut/Positioning/Tutorial%2003. www and com

first:

void ComputePositionOffsets(float &fXOffset, float &fYOffset)

{

const float fLoopDuration = 5.0f;

const float fScale = 3.14159f * 2.0f / fLoopDuration;

float fElapsedTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;

float fCurrTimeThroughLoop = fmodf(fElapsedTime, fLoopDuration);

fXOffset = cosf(fCurrTimeThroughLoop * fScale) * 0.5f;

fYOffset = sinf(fCurrTimeThroughLoop * fScale) * 0.5f;

}

I dont understand what the purpose of fScale is, and I don't get what the purpose of finding the modulus of the the "fElapsedTime and the fLoopDuration, do the milliseconds keep counting upwards indefinitely and the fCurrentTimeThroughLoop is just calculating what part of each current "five second cycle" we are at?

I have a somewhat decent understanding of it, probably enough to move on in the book assuming it will go into more detail on these types of functions later, but I feel I can understand more, if anyone could elaborate more on some of the code here that would be great.

thanks