void CProjectile::Update(const float dt, float screenWidth, float screenHeight) { if (pos.x < 0 || pos.x > screenWidth || pos.y < 0 || pos.y > screenHeight) { Reset(); } if (active) { pos = pos + (vel * dt); CalcBound(); } }
/* Determines smallest rectangle around nonMv values. * The border value can be added around this rectangle. * Returns x0, y0 , nrRows and nrCols for out. */ static int SmallestNonMVRect( REAL8 *X0out, /* write-only X0 */ REAL8 *Y0out, /* write-only Y0 */ size_t *nrRows, /* write-only nr of rows */ size_t *nrCols, /* write-only nr of columns */ MAP **in, /* read-only pointer in maps */ int borderValue, /* border value */ size_t nrMaps, /* number of input maps */ CSF_VS valueScale, /* value scale of output map */ REAL8 cellSize, /* cellSize of map */ REAL8 angle, /* angle of output map */ CSF_PT projection, /* projection of output map */ BOOL contract) /* map should be contracted */ { size_t i; POINT2D leftUpperC, leftLowerC, rightUpperC, rightLowerC; REAL8 upperB=0, leftB=0, rightB=0, belowB=0; /* ^- shut up about use before def */ for(i = 0; i < nrMaps; i++) { MAP *X = in[i]; BOOL first = TRUE; POINT2D polygon[4]; size_t r, c; size_t nrR = RgetNrRows(X); size_t nrC = RgetNrCols(X); for(r = 0; r < nrR; r++) for(c = 0; c < nrC; c++) { INT4 int4Val; REAL8 real8Val; if((AppIsClassified(valueScale) && RgetCell(in[i], r, c, &int4Val) && int4Val != MV_INT4) || (!AppIsClassified(valueScale) && RgetCell(in[i], r, c, &real8Val) && (IsMV(in[i], &real8Val) == FALSE))) { if(first || c < leftB) leftB = c; if(first || c > rightB) rightB = c; if(first || r > belowB) belowB = r; if(first || r < upperB) upperB = r; first = FALSE; } } /* Get coordinates of corners */ RrowCol2Coords(X, upperB, leftB, &polygon[0].x, &polygon[0].y); RrowCol2Coords(X, upperB, rightB + 1 - EPSILON, &polygon[1].x, &polygon[1].y); RrowCol2Coords(X, belowB + 1 - EPSILON, leftB, &polygon[2].x, &polygon[2].y); RrowCol2Coords(X, belowB + 1 - EPSILON, rightB + 1 - EPSILON, &polygon[3].x, &polygon[3].y); /* Rotate all corners of map */ if(angle != 0) { for(c = 0; c < 4; c++) polygon[c] = *RotPoint(polygon + c, angle); } /* Determine boundaries of rotated output map */ for(c = 0; c < 4; c++) { if(polygon[c].y > belowB || (i == 0 && c == 0)) belowB = polygon[c].y; if(polygon[c].y < upperB || (i == 0 && c == 0)) upperB = polygon[c].y; if(polygon[c].x > rightB || (i == 0 && c == 0)) rightB = polygon[c].x; if(polygon[c].x < leftB || (i == 0 && c == 0)) leftB = polygon[c].x; } } leftUpperC.x = leftB; rightUpperC.x = rightB; leftLowerC.x = leftB; rightLowerC.x = rightB; if(projection == PT_YINCT2B) { leftUpperC.y = upperB; rightUpperC.y = upperB; leftLowerC.y = belowB; rightLowerC.y = belowB; } else { leftUpperC.y = belowB; rightUpperC.y = belowB; leftLowerC.y = upperB; rightLowerC.y = upperB; } CalcBound(X0out, Y0out, nrRows, nrCols, &leftUpperC, &rightUpperC, &leftLowerC, &rightLowerC, borderValue, cellSize, angle, projection, contract); return 0; }
/* Determines the smallest fitting rectangle around input maps. * The bordervalue is added. * Returns x0, y0, nrRows and nrCols for out. */ static int SmallestFittingRectangle( REAL8 *X0out, /* write-only X0 */ REAL8 *Y0out, /* write-only Y0 */ size_t *nrRows, /* write-only nr of rows */ size_t *nrCols, /* write-only nr of columns */ MAP **in, /* read-only pointer to input maps */ int borderValue, /* bordervalue */ size_t nrMaps, /* number of input maps */ REAL8 cellSize, /* cell size of output map */ REAL8 angle, /* angle of output map */ CSF_PT projection, /* projection of output map */ BOOL contract) /* map should be contracted */ { size_t i; REAL8 upperB=0, leftB=0, rightB=0, belowB=0; /* ^- shut up about use before def */ POINT2D leftUpperC, rightUpperC, leftLowerC, rightLowerC; /* determine the boundaries for every map */ for(i = 0; i < nrMaps; i++) { MAP *X = in[i]; int c; POINT2D polygon[4]; /* rectangle */ REAL8 X0 = RgetX0(X); REAL8 Y0 = RgetY0(X); REAL8 nrR = (REAL8) RgetNrRows(X); REAL8 nrC = (REAL8) RgetNrCols(X); /* transform corners of map into x- and y-coordinates */ polygon[0].x = X0; polygon[0].y = Y0; RrowCol2Coords(X, 0.0, nrC - EPSILON, &polygon[1].x, &polygon[1].y); RrowCol2Coords(X, nrR - EPSILON, nrC - EPSILON, &polygon[2].x, &polygon[2].y); RrowCol2Coords(X, nrR - EPSILON, 0.0, &polygon[3].x, &polygon[3].y); /* Rotate all corners of map */ if(angle != 0) for(c = 0; c < 4; c++) RotPoint(polygon + c, angle); /* Determine boundaries of rotated output map */ for(c = 0; c < 4; c++) { if((i==0&&c==0)||polygon[c].y > belowB) belowB = polygon[c].y; if((i==0&&c==0)||polygon[c].y < upperB) upperB = polygon[c].y; if((i==0&&c==0)||polygon[c].x > rightB) rightB = polygon[c].x; if((i==0&&c==0)||polygon[c].x < leftB) leftB = polygon[c].x; } } /* Put boundaries in corners of the rotated map */ leftUpperC.x = leftB; rightUpperC.x = rightB; leftLowerC.x = leftB; rightLowerC.x = rightB; if(projection == PT_YINCT2B) { leftUpperC.y = upperB; rightUpperC.y = upperB; leftLowerC.y = belowB; rightLowerC.y = belowB; } else { leftUpperC.y = belowB; rightUpperC.y = belowB; leftLowerC.y = upperB; rightLowerC.y = upperB; } /* calculate the boundary of the output map */ CalcBound(X0out, Y0out, nrRows, nrCols, &leftUpperC, &rightUpperC, &leftLowerC, &rightLowerC, borderValue, cellSize, angle, projection, contract); return 0; }