-------------General class Problems--------------
1 j2me table method using trigonometric functions
CLDC and MIDP do not provide trigonometric functions, and there is no floating-point number in the CLDC1.0, so our choice is to check the table. Use the sin and Cos tables with 8-bit fixed-point numbers. The following is the code in the WTK demo, which provides only a limited number of angles, which are used to refine the angle value as needed.
//Sines of angles 0, a, m, 90,all *256
private static final int[] Sines =< br>
{0, N, 128, 165, 196, 222, 241, 252, 256};
//angle is in DEGREES/10, i.e. 0..36 for full circle
private static int sineTimes256 (int angle)
br> {
angle%= 36; 360 degrees
if (angle <= 9)//0..90 degrees
{
return sines[angle];
}
Else if (angle <=)//90..180 degrees
{
return sines[18-angle];
br>}
Else if (angle <=)//180..270 degrees
{
return-sines[angle-18];
}
Else//270..360 degrees
{
Return-sines[36-angle];
}
}
//angle is in DEGREES/10, i.e. 0..36 to Full circle
private static int C osineTimes256 (int angle)
{
return sineTimes256(angle + 9); i.e. add degrees
}
(2006.5 Note: Some algorithms can generate trigonometric values so that you can save some data by generating a function table when the game is loaded)
2 J2ME Generates random numbers between 0~n with a random number of
:
(Ran.nextint () >>>1)%n
or
(Ran.nextint () &0x7f FFFFFF)%n
produces random numbers between-n~0:
(Ran.nextint () | 0x80000000)%n