Recently encountered a camera rotation constraint issue
Would have preferred to directly compare the Euler value solution, but the value of Eulerian angle is 0-360 of the interval, such as the current angle is 1, the range is 350-10, will be wrong. Need to make a circle-wide judgment.
Of course it can be converted into vectors to compare, but it's too expensive to calculate.
That means you need to write a clamp of the ring, like this one
Mathematics is not good, directly hard to write:
Public Static floatAngleclamp (floatMinfloatMaxfloatvalue) { if(Min > Max && (value < Max | | value >min)) { returnvalue; } if(Value > Min && value <max) { returnvalue; } Value= value = =0? the: value; Min= min = =0? the: Min; Max= max = =0? the: Max; varA1 = the-Value +min; varB1 = Math.Abs (Min-value); varC1 = A1 < B1?a1:b1; varA2 = the-Value +Max; varb2 = Math.Abs (Max-value); varC2 = A2 < b2?a2:b2; if(C1 <C2) { if(Value < min | | value >max) { returnmin; } } Else { returnMax; } return float. NaN;}
Angleclamp
Test Case:
There are a number of similar problems, but most of them can be directly written to the dead numerical judgment
A hard-written rotation constraint problem Resolution