Konvertering fra C++ til Delphi
Dette er et lille converterings spørgsmål. Koden vist nedenfor har givet mig problemer de sidst par dage. Der er én af linierne jeg ikke forstår (resten har jeg stort set gættet mig til. HVis nogen kunne kunne hjælpe med en forklaring/konvertering ville jeg blive lykkelig. Skulle der mangler noget (koden er ikke komplet), så bare spørg:void GenerateSquareWorldMap();
int *WorldMapArray;
float YRangeDiv2, YRangeDivPI;
float *SinIterPhi;
WorldMapArray = (int *) malloc(XRange*YRange*sizeof(int));
SinIterPhi = (float *) malloc(2*XRange*sizeof(float));
for (i=0; i<XRange; i++)
{
SinIterPhi[i] = SinIterPhi[i+XRange] = (float)sin(i*2*PI/XRange);
}
srand(Seed); // RandSeed(Seed)
for (j=0, row=0; j<XRange; j++)
{
WorldMapArray[row] = 0;
for (i=1; i<YRange; i++) WorldMapArray[i+row] = INT_MIN;
row += YRange;
}
/* Define some "constants" which we use frequently */
YRangeDiv2 = YRange/2;
YRangeDivPI = YRange/PI;
if (ProjectionType == MERCATOR)
{
for (a=0; a<NumberOfFaults; a++)
{
GenerateMercatorWorldMap();
}
}
else
{
for (a=0; a<NumberOfFaults; a++)
{
GenerateSquareWorldMap();
}
}
/* Copy data (I have only calculated faults for 1/2 the image.
* I can do this due to symmetry... :) */
index2 = (XRange/2)*YRange;
for (j=0, row=0; j<XRange/2; j++)
{
for (i=1; i<YRange; i++)
{
WorldMapArray[row+index2+YRange-i] = WorldMapArray[row+i];
}
row += YRange;
}
void GenerateSquareWorldMap()
{
float Alpha, Beta;
float TanB;
float Result, Delta;
int i, row, N2;
int Theta, Phi, Xsi;
unsigned int flag1;
flag1 = rand() & 1; /*(int)((((float) rand())/MAX_RAND) + 0.5);*/
/* Create a random greatcircle... */
Alpha = (((float) rand())/MAX_RAND-0.5)*PI; /* Rotate around x-axis */
Beta = (((float) rand())/MAX_RAND-0.5)*PI; /* Rotate around y-axis */
TanB = (float)tan(acos(cos(Alpha)*cos(Beta)));
row = 0;
Xsi = (int)(XRange/2-(XRange/PI)*Beta);
for (Phi=0; Phi<XRange/2; Phi++)
{
Theta = (int)(YRangeDivPI*atan(*(SinIterPhi+Xsi-Phi+XRange)*TanB))+YRangeDiv2; <-- Det er denne her line jeg ikke forstår
if (flag1)
{
/* Rise northen hemisphere <=> lower southern */
if (WorldMapArray[row+Theta] != INT_MIN)
WorldMapArray[row+Theta]--;
else
WorldMapArray[row+Theta] = -1;
}
else
{
/* Rise southern hemisphere */
if (WorldMapArray[row+Theta] != INT_MIN)
WorldMapArray[row+Theta]++;
else
WorldMapArray[row+Theta] = 1;
}
row += YRange;
}
}