Skip to main content
Known Participant
August 26, 2016
Answered

Strange AngleParam value

  • August 26, 2016
  • 1 reply
  • 582 views

Anyone know if there's some special way to handle an AngleParam?

Currently I'm having to divide the value by some ridiculous number (about 3753600) to make it usable as degrees.

Here's the function I'm feeding it into (as "rot"):

static PF_PixelFloat rotateY(PF_FpLong rot, PF_PixelFloat inVec){

  PF_FpLong tmpX = inVec.red;

  PF_FpLong tmpZ = inVec.blue;

  inVec.red = tmpX*cosf(rot) + tmpZ*sinf(rot);

  inVec.blue = tmpZ*cosf(rot) - tmpX*sinf(rot);

  return inVec;

}

I figured it would just be a matter of converting degrees to radians, but apparently not.

This topic has been closed for replies.
Correct answer françois leroy

Hi,

angle params return a 'Fixed' value.

So if you want to convert it to float, you do have to divide it or just use the FIX_2_FLOAT macro like this.

myAngleInDegrees = FIX_2_FLOAT(params[myAngle]->u.ad.value);

And if you need it in radians (your function using cos and sin probably need it), multiply it by PF_RAD_PER_DEGREE

Cheers,

François

1 reply

françois leroy
françois leroyCorrect answer
Inspiring
August 26, 2016

Hi,

angle params return a 'Fixed' value.

So if you want to convert it to float, you do have to divide it or just use the FIX_2_FLOAT macro like this.

myAngleInDegrees = FIX_2_FLOAT(params[myAngle]->u.ad.value);

And if you need it in radians (your function using cos and sin probably need it), multiply it by PF_RAD_PER_DEGREE

Cheers,

François

Known Participant
August 26, 2016

Ah, I thought I was missing a step. I was multiplying by PF_RAD_PER_DEGREE, but that obviously didn't work.

Thanks again!

Inspiring
August 26, 2016

Don't forget PF_AngleParamSuite1, which will return your angle param value as a floating point number. This result is still in radians so you'll still need to multiply by PF_RAD_PER_DEGREE, but it bypasses the horrible fixed-point maths.

Page 108 of the SDK guide.