static bool AddAnchor_Original_Method(EERIE_BACKGROUND * eb, EERIE_BKG_INFO * eg, Vec3f * pos) { long found = 0; long best = 0; long stop_radius = 0; float best_dist = 99999999999.f; Cylinder testcyl; Cylinder currcyl; Cylinder bestcyl; bestcyl.height = 0; bestcyl.radius = 0; for (long rad = 0; rad < 20; rad += 10) for (long ang = 0; ang < 360; ang += 45) // 45 { float t = glm::radians((float)ang); // We set our current position depending on given position, radius & angle. currcyl.radius = 40; currcyl.height = -165; currcyl.origin.x = pos->x - std::sin(t) * (float)rad; currcyl.origin.y = pos->y; currcyl.origin.z = pos->z + std::cos(t) * (float)rad; stop_radius = 0; found = 0; long climb = 0; while ((stop_radius != 1)) { testcyl = currcyl; testcyl.radius += INC_RADIUS; if (ANCHOR_AttemptValidCylinderPos(testcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_ANCHOR_GENERATION)) { currcyl = testcyl; found = 1; } else { if ((testcyl.origin.y != currcyl.origin.y) && (glm::abs(testcyl.origin.y - pos->y) < 50)) { testcyl.radius -= INC_RADIUS; currcyl = testcyl; climb++; } else stop_radius = 1; } if (climb > 4) stop_radius = 1; if (currcyl.radius >= 50.f) stop_radius = 1; } if (found) { float d = glm::distance(*pos, currcyl.origin); if (currcyl.radius >= bestcyl.radius) { if (((best_dist > d) && (currcyl.radius == bestcyl.radius)) || (currcyl.radius > bestcyl.radius)) { bestcyl = currcyl; best_dist = d; best = 1; } } } } if (!best) return false; if(CylinderAboveInvalidZone(bestcyl)) return false; // avoid to recreate same anchor twice... if (0) for (long k = 0; k < eb->nbanchors; k++) { ANCHOR_DATA * ad = &eb->anchors[k]; if ((ad->pos.x == bestcyl.origin.x) && (ad->pos.y == bestcyl.origin.y) && (ad->pos.z == bestcyl.origin.z)) { if (ad->radius >= bestcyl.radius) return false; if (ad->radius <= bestcyl.radius) { ad->height = bestcyl.height; ad->radius = bestcyl.radius; return false; } } } eg->ianchors = (long *)realloc(eg->ianchors, sizeof(long) * (eg->nbianchors + 1)); eg->ianchors[eg->nbianchors] = eb->nbanchors; eg->nbianchors++; eb->anchors = (ANCHOR_DATA *)realloc(eb->anchors, sizeof(ANCHOR_DATA) * (eb->nbanchors + 1)); ANCHOR_DATA * ad = &eb->anchors[eb->nbanchors]; ad->pos = bestcyl.origin; ad->height = bestcyl.height; ad->radius = bestcyl.radius; ad->linked = NULL; ad->nblinked = 0; ad->flags = 0; eb->nbanchors++; return true; }
static void AnchorData_Create_Phase_II_Original_Method(EERIE_BACKGROUND * eb) { Vec3f pos; float count = 0; long lastper = -1; long per; float total = static_cast<float>(eb->Zsize * eb->Xsize); for(long j = 0; j < eb->Zsize; j++) for(long i = 0; i < eb->Xsize; i++) { per = count / total * 100.f; if(per != lastper) { LogInfo << "Anchor Generation: %" << per << " (Pass II)"; lastper = per; } count += 1.f; EERIE_BKG_INFO * eg = &eb->fastdata[i][j]; pos.x = (float)((float)((float)i) * (float)eb->Xdiv); pos.y = 0.f; pos.z = (float)((float)((float)j) * (float)eb->Zdiv); Cylinder currcyl; currcyl.radius = 30; currcyl.height = -150.f; currcyl.origin = pos; if(eg->nbpolyin) { long ok = 0; for(long kkk = 0; kkk < eg->nbpolyin; kkk++) { EERIEPOLY * ep = eg->polyin[kkk]; if (ep->type & POLY_PRECISE_PATH) { ok = 1; break; } } if(!ok) continue; float roof = GetTileMinY(i, j); float current_y = GetTileMaxY(i, j); while(current_y > roof) { long added = 0; for(float pposz = 0.f; pposz < 1.f; pposz += 0.1f) for(float pposx = 0.f; pposx < 1.f; pposx += 0.1f) { currcyl.origin.x = pos.x + pposx * eb->Xdiv; currcyl.origin.z = pos.z + pposz * eb->Zdiv; currcyl.origin.y = current_y; EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin + Vec3f(0.f, -10.f, 0.f)); if(!ep2) continue; if(!(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) continue; if(ep2->type & POLY_NOPATH) continue; if(ANCHOR_AttemptValidCylinderPos(currcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_RETURN_HEIGHT | CFLAG_ANCHOR_GENERATION)) { EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin + Vec3f(0.f, -10.f, 0.f)); if(!ep2) continue; if(!(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) continue; if(ep2->type & POLY_NOPATH) continue; if(DirectAddAnchor_Original_Method(eb, eg, &currcyl.origin)) { added = 1; } } } if(added) current_y -= 160.f; current_y -= 50.f; } } } }
static bool ANCHOR_ARX_COLLISION_Move_Cylinder(IO_PHYSICS * ip, Entity * io, float MOVE_CYLINDER_STEP, CollisionFlags flags) { MOVING_CYLINDER = 1; DIRECT_PATH = true; IO_PHYSICS test; if(ip == NULL) { MOVING_CYLINDER = 0; return false; } float distance = glm::distance(ip->startpos, ip->targetpos); if(distance <= 0.f) { MOVING_CYLINDER = 0; return true; } Vec3f mvector = (ip->targetpos - ip->startpos) / distance; while(distance > 0.f) { // First We compute current increment float curmovedist = std::min(distance, MOVE_CYLINDER_STEP); distance -= curmovedist; //CUR_FRAME_SLICE=curmovedist*onedist; // Store our cylinder desc into a test struct test = *ip; // uses test struct to simulate movement. test.cyl.origin += mvector * curmovedist; vector2D.x = mvector.x * curmovedist; vector2D.y = 0.f; vector2D.z = mvector.z * curmovedist; if ((flags & CFLAG_CHECK_VALID_POS) && (CylinderAboveInvalidZone(test.cyl))) return false; if(ANCHOR_AttemptValidCylinderPos(test.cyl, io, flags)) { *ip = test; } else { if(flags & CFLAG_CLIMBING) { test.cyl = ip->cyl; test.cyl.origin.y += mvector.y * curmovedist; if(ANCHOR_AttemptValidCylinderPos(test.cyl, io, flags)) { *ip = test; goto oki; } } DIRECT_PATH = false; // Must Attempt To Slide along collisions Vec3f vecatt; Vec3f rpos = Vec3f_ZERO; Vec3f lpos = Vec3f_ZERO; long RFOUND = 0; long LFOUND = 0; long maxRANGLE = 90; float ANGLESTEPP; // player sliding in fact... if(flags & CFLAG_EASY_SLIDING) { ANGLESTEPP = 10.f; maxRANGLE = 70; } else { ANGLESTEPP = 30.f; } float rangle = ANGLESTEPP; float langle = 360.f - ANGLESTEPP; //tries on the Right and Left sides while(rangle <= maxRANGLE) { test.cyl = ip->cyl; float t = MAKEANGLE(rangle); vecatt = VRotateY(mvector, t); test.cyl.origin += vecatt * curmovedist; if(ANCHOR_AttemptValidCylinderPos(test.cyl, io, flags)) { rpos = test.cyl.origin; RFOUND = 1; } rangle += ANGLESTEPP; test.cyl = ip->cyl; t = MAKEANGLE(langle); vecatt = VRotateY(mvector, t); test.cyl.origin += vecatt * curmovedist; if(ANCHOR_AttemptValidCylinderPos(test.cyl, io, flags)) { lpos = test.cyl.origin; LFOUND = 1; } langle -= ANGLESTEPP; if(RFOUND || LFOUND) break; } if(LFOUND && RFOUND) { langle = 360.f - langle; if(langle < rangle) { ip->cyl.origin = lpos; distance -= curmovedist; } else { ip->cyl.origin = rpos; distance -= curmovedist; } } else if(LFOUND) { ip->cyl.origin = lpos; distance -= curmovedist; } else if(RFOUND) { ip->cyl.origin = rpos; distance -= curmovedist; } else { //stopped ip->velocity = Vec3f_ZERO; MOVING_CYLINDER = 0; return false; } } oki: ; } MOVING_CYLINDER = 0; return true; }
static bool DirectAddAnchor_Original_Method(EERIE_BACKGROUND * eb, EERIE_BKG_INFO * eg, Vec3f * pos) { long found = 0; long stop_radius = 0; Cylinder testcyl; Cylinder currcyl; Cylinder bestcyl; bestcyl.height = 0; bestcyl.radius = 0; currcyl.radius = 40; currcyl.height = -165.f; currcyl.origin = *pos; stop_radius = 0; found = 0; long climb = 0; while (stop_radius != 1) { testcyl = currcyl; testcyl.radius += INC_RADIUS; if (ANCHOR_AttemptValidCylinderPos(testcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_ANCHOR_GENERATION)) { currcyl = testcyl; found = 1; } else { if ((testcyl.origin.y != currcyl.origin.y) && (glm::abs(testcyl.origin.y - pos->y) < 50)) { testcyl.radius -= INC_RADIUS; currcyl = testcyl; climb++; } else stop_radius = 1; } if (climb > 4) stop_radius = 1; if (currcyl.radius >= 50.f) stop_radius = 1; } if(found && currcyl.radius >= bestcyl.radius) { bestcyl = currcyl; } else { return false; } if(CylinderAboveInvalidZone(bestcyl)) return false; for (long k = 0; k < eb->nbanchors; k++) { ANCHOR_DATA * ad = &eb->anchors[k]; if(closerThan(ad->pos, bestcyl.origin, 50.f)) { return false; } if(closerThan(Vec2f(ad->pos.x, ad->pos.z), Vec2f(bestcyl.origin.x, bestcyl.origin.z), 45.f)) { if (glm::abs(ad->pos.y - bestcyl.origin.y) < 90.f) return false; EERIEPOLY * ep = ANCHOR_CheckInPolyPrecis(ad->pos); EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(Vec3f(ad->pos.x, bestcyl.origin.y, ad->pos.z)); if (ep2 == ep) return false; } } eg->ianchors = (long *)realloc(eg->ianchors, sizeof(long) * (eg->nbianchors + 1)); eg->ianchors[eg->nbianchors] = eb->nbanchors; eg->nbianchors++; eb->anchors = (ANCHOR_DATA *)realloc(eb->anchors, sizeof(ANCHOR_DATA) * (eb->nbanchors + 1)); ANCHOR_DATA * ad = &eb->anchors[eb->nbanchors]; ad->pos = bestcyl.origin; ad->height = bestcyl.height; ad->radius = bestcyl.radius; ad->linked = NULL; ad->nblinked = 0; ad->flags = 0; eb->nbanchors++; return true; }
bool AddAnchor_Original_Method(EERIE_BACKGROUND * eb, EERIE_BKG_INFO * eg, EERIE_3D * pos, long flags) { long found = 0; long best = 0; long stop_radius = 0; float best_dist = 99999999999.f; float v_dist = 99999999999.f; EERIE_CYLINDER testcyl; EERIE_CYLINDER currcyl; EERIE_CYLINDER bestcyl; bestcyl.height = 0; bestcyl.radius = 0; for (long rad = 0; rad < 20; rad += 10) for (long ang = 0; ang < 360; ang += 45) // 45 { float t = DEG2RAD((float)ang); // We set our current position depending on given position, radius & angle. currcyl.radius = 40; currcyl.height = -165; currcyl.origin.x = pos->x - EEsin(t) * (float)rad; currcyl.origin.y = pos->y; currcyl.origin.z = pos->z + EEcos(t) * (float)rad; stop_radius = 0; found = 0; long climb = 0; while ((stop_radius != 1)) { memcpy(&testcyl, &currcyl, sizeof(EERIE_CYLINDER)); testcyl.radius += INC_RADIUS; if (ANCHOR_AttemptValidCylinderPos(&testcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_ANCHOR_GENERATION)) { memcpy(&currcyl, &testcyl, sizeof(EERIE_CYLINDER)); found = 1; } else { if ((testcyl.origin.y != currcyl.origin.y) && (EEfabs(testcyl.origin.y - pos->y) < 50)) { testcyl.radius -= INC_RADIUS; memcpy(&currcyl, &testcyl, sizeof(EERIE_CYLINDER)); climb++; } else stop_radius = 1; } if (climb > 4) stop_radius = 1; if (currcyl.radius >= 50.f) stop_radius = 1; } if (found) { float dist = TRUEEEDistance3D(pos, &currcyl.origin); float vd = EEfabs(pos->y - currcyl.origin.y); if (currcyl.radius >= bestcyl.radius) { if (((best_dist > dist) && (currcyl.radius == bestcyl.radius)) || (currcyl.radius > bestcyl.radius)) { memcpy(&bestcyl, &currcyl, sizeof(EERIE_CYLINDER)); best_dist = dist; v_dist = vd; best = 1; } } } } if (!best) return FALSE; if (CylinderAboveInvalidZone(&bestcyl)) return FALSE; if (flags == MUST_BE_BIG) { if (bestcyl.radius < 60) return FALSE; } // avoid to recreate same anchor twice... if (0) for (long k = 0; k < eb->nbanchors; k++) { _ANCHOR_DATA * ad = &eb->anchors[k]; if ((ad->pos.x == bestcyl.origin.x) && (ad->pos.y == bestcyl.origin.y) && (ad->pos.z == bestcyl.origin.z)) { if (ad->radius >= bestcyl.radius) return FALSE; if (ad->radius <= bestcyl.radius) { ad->height = bestcyl.height; ad->radius = bestcyl.radius; return FALSE; } } } eg->ianchors = (long *)realloc(eg->ianchors, sizeof(long) * (eg->nbianchors + 1)); if (!eg->ianchors) HERMES_Memory_Emergency_Out(); eg->ianchors[eg->nbianchors] = eb->nbanchors; eg->nbianchors++; eb->anchors = (_ANCHOR_DATA *)realloc(eb->anchors, sizeof(_ANCHOR_DATA) * (eb->nbanchors + 1)); if (!eb->anchors) HERMES_Memory_Emergency_Out(); _ANCHOR_DATA * ad = &eb->anchors[eb->nbanchors]; ad->pos.x = bestcyl.origin.x; ad->pos.y = bestcyl.origin.y; ad->pos.z = bestcyl.origin.z; ad->height = bestcyl.height; ad->radius = bestcyl.radius; ad->linked = NULL; ad->nblinked = 0; ad->flags = 0; eb->nbanchors++; return TRUE; }
void AnchorData_Create(EERIE_BACKGROUND * eb) { AnchorData_ClearAll(eb); Vec3f pos; float count = 0; long lastper = -1; long per; float total = static_cast<float>(eb->Zsize * eb->Xsize * 9); for(long j = 0; j < eb->Zsize; j++) for(long i = 0; i < eb->Xsize; i++) { long LASTFOUND = 0; for(long divv = 0; divv < 9; divv++) { long divvx, divvy; switch (divv) { case 0: divvx = 0; divvy = 0; break; case 1: divvx = 1; divvy = 0; break; case 2: divvx = 2; divvy = 0; break; case 3: divvx = 0; divvy = 1; break; case 4: divvx = 1; divvy = 1; break; case 5: divvx = 2; divvy = 1; break; case 6: divvx = 0; divvy = 2; break; case 7: divvx = 1; divvy = 2; break; case 8: divvx = 2; divvy = 2; break; } per = count / total * 100.f; if(per != lastper) { LogInfo << "Anchor Generation: %" << per; lastper = per; } count += 1.f; if(LASTFOUND) break; EERIE_BKG_INFO * eg = &eb->fastdata[i][j]; pos.x = (float)((float)((float)i + 0.33f * (float)divvx) * (float)eb->Xdiv); pos.y = 0.f; pos.z = (float)((float)((float)j + 0.33f * (float)divvy) * (float)eb->Zdiv); EERIEPOLY * ep = GetMinPoly(pos); Cylinder currcyl; currcyl.radius = 20 - (4.f * divv); currcyl.height = -120.f; currcyl.origin = pos; if(ep) { EERIEPOLY * epmax; epmax = GetMaxPoly(pos); float roof = 9999999.f; if(ep) roof = ep->min.y - 300; if(epmax) roof = epmax->min.y - 300; float current_y = ep->max.y; while(current_y > roof) { currcyl.origin.y = current_y; EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin + Vec3f(0.f, -30.f, 0.f)); if( ep2 && !(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f) ) { ep2 = NULL; } if(ep2 && !(ep2->type & POLY_NOPATH)) { bool bval = ANCHOR_AttemptValidCylinderPos(currcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_RETURN_HEIGHT | CFLAG_ANCHOR_GENERATION); if( bval && currcyl.origin.y - 10.f <= current_y ) { EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin + Vec3f(0.f, -38.f, 0.f)); if(ep2 && !(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) { current_y -= 10.f; } else if ((ep2) && (ep2->type & POLY_NOPATH)) { current_y -= 10.f; } else if (AddAnchor_Original_Method(eb, eg, &currcyl.origin)) { LASTFOUND++; current_y = currcyl.origin.y + currcyl.height; } else { current_y -= 10.f; } } else { current_y -= 10.f; } } else { current_y -= 10.f; } } } } } AnchorData_Create_Phase_II_Original_Method(eb); AnchorData_Create_Links_Original_Method(eb); }
bool DirectAddAnchor_Original_Method(EERIE_BACKGROUND * eb, EERIE_BKG_INFO * eg, EERIE_3D * pos, long flags) { long found = 0; long best = 0; long stop_radius = 0; float best_dist = 99999999999.f; float v_dist = 99999999999.f; EERIE_CYLINDER testcyl; EERIE_CYLINDER currcyl; EERIE_CYLINDER bestcyl; bestcyl.height = 0; bestcyl.radius = 0; currcyl.radius = 40; currcyl.height = -165.f; currcyl.origin.x = pos->x; currcyl.origin.y = pos->y; currcyl.origin.z = pos->z; stop_radius = 0; found = 0; long climb = 0; while (stop_radius != 1) { memcpy(&testcyl, &currcyl, sizeof(EERIE_CYLINDER)); testcyl.radius += INC_RADIUS; if (ANCHOR_AttemptValidCylinderPos(&testcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_ANCHOR_GENERATION)) { memcpy(&currcyl, &testcyl, sizeof(EERIE_CYLINDER)); found = 1; } else { if ((testcyl.origin.y != currcyl.origin.y) && (EEfabs(testcyl.origin.y - pos->y) < 50)) { testcyl.radius -= INC_RADIUS; memcpy(&currcyl, &testcyl, sizeof(EERIE_CYLINDER)); climb++; } else stop_radius = 1; } if (climb > 4) stop_radius = 1; if (currcyl.radius >= 50.f) stop_radius = 1; } if (found) { float dist = TRUEEEDistance3D(pos, &currcyl.origin); float vd = EEfabs(pos->y - currcyl.origin.y); if ((currcyl.radius >= bestcyl.radius)) { if (((best_dist > dist) && (currcyl.radius == bestcyl.radius)) || (currcyl.radius > bestcyl.radius)) { memcpy(&bestcyl, &currcyl, sizeof(EERIE_CYLINDER)); best_dist = dist; v_dist = vd; best = 1; } } } if (!best) return FALSE; if (CylinderAboveInvalidZone(&bestcyl)) return FALSE; for (long k = 0; k < eb->nbanchors; k++) { _ANCHOR_DATA * ad = &eb->anchors[k]; if (TRUEEEDistance3D(&ad->pos, &bestcyl.origin) < 50.f) return FALSE; if (TRUEDistance2D(ad->pos.x, ad->pos.z, bestcyl.origin.x, bestcyl.origin.z) < 45.f) { if (EEfabs(ad->pos.y - bestcyl.origin.y) < 90.f) return FALSE; EERIEPOLY * ep = ANCHOR_CheckInPolyPrecis(ad->pos.x, ad->pos.y, ad->pos.z); EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(ad->pos.x, bestcyl.origin.y, ad->pos.z); if (ep2 == ep) return FALSE; } } eg->ianchors = (long *)realloc(eg->ianchors, sizeof(long) * (eg->nbianchors + 1)); if (!eg->ianchors) HERMES_Memory_Emergency_Out(); eg->ianchors[eg->nbianchors] = eb->nbanchors; eg->nbianchors++; eb->anchors = (_ANCHOR_DATA *)realloc(eb->anchors, sizeof(_ANCHOR_DATA) * (eb->nbanchors + 1)); if (!eb->anchors) HERMES_Memory_Emergency_Out(); _ANCHOR_DATA * ad = &eb->anchors[eb->nbanchors]; ad->pos.x = bestcyl.origin.x; ad->pos.y = bestcyl.origin.y; ad->pos.z = bestcyl.origin.z; ad->height = bestcyl.height; ad->radius = bestcyl.radius; ad->linked = NULL; ad->nblinked = 0; ad->flags = 0; eb->nbanchors++; return TRUE; }
BOOL ANCHOR_ARX_COLLISION_Move_Cylinder(IO_PHYSICS * ip, INTERACTIVE_OBJ * io, float MOVE_CYLINDER_STEP, long flags) { MOVING_CYLINDER = 1; DIRECT_PATH = TRUE; IO_PHYSICS test; if (ip == NULL) { MOVING_CYLINDER = 0; return FALSE; } float distance = TRUEEEDistance3D(&ip->startpos, &ip->targetpos); if (distance <= 0.f) { MOVING_CYLINDER = 0; return TRUE; } float onedist = 1.f / distance; EERIE_3D mvector; mvector.x = (ip->targetpos.x - ip->startpos.x) * onedist; mvector.y = (ip->targetpos.y - ip->startpos.y) * onedist; mvector.z = (ip->targetpos.z - ip->startpos.z) * onedist; while (distance > 0.f) { // First We compute current increment float curmovedist = __min(distance, MOVE_CYLINDER_STEP); distance -= curmovedist; //CUR_FRAME_SLICE=curmovedist*onedist; // Store our cylinder desc into a test struct memcpy(&test, ip, sizeof(IO_PHYSICS)); // uses test struct to simulate movement. test.cyl.origin.x += mvector.x * curmovedist; test.cyl.origin.y += mvector.y * curmovedist; test.cyl.origin.z += mvector.z * curmovedist; vector2D.x = mvector.x * curmovedist; vector2D.y = 0.f; vector2D.z = mvector.z * curmovedist; if ((flags & CFLAG_CHECK_VALID_POS) && (CylinderAboveInvalidZone(&test.cyl))) return FALSE; if (ANCHOR_AttemptValidCylinderPos(&test.cyl, io, flags)) { memcpy(ip, &test, sizeof(IO_PHYSICS)); } else { if (flags & CFLAG_CLIMBING) { memcpy(&test.cyl, &ip->cyl, sizeof(EERIE_CYLINDER)); test.cyl.origin.y += mvector.y * curmovedist; if (ANCHOR_AttemptValidCylinderPos(&test.cyl, io, flags)) { memcpy(ip, &test, sizeof(IO_PHYSICS)); goto oki; } } DIRECT_PATH = FALSE; // Must Attempt To Slide along collisions register EERIE_3D vecatt; EERIE_3D rpos = { 0, 0, 0 }; EERIE_3D lpos = { 0, 0, 0 }; long RFOUND = 0; long LFOUND = 0; long maxRANGLE = 90; long maxLANGLE = 270; float ANGLESTEPP; if (flags & CFLAG_EASY_SLIDING) // player sliding in fact... { ANGLESTEPP = 10.f; maxRANGLE = 70; maxLANGLE = 290; } else ANGLESTEPP = 30.f; register float rangle = ANGLESTEPP; register float langle = 360.f - ANGLESTEPP; while (rangle <= maxRANGLE) //tries on the Right and Left sides { memcpy(&test.cyl, &ip->cyl, sizeof(EERIE_CYLINDER)); float t = DEG2RAD(MAKEANGLE(rangle)); _YRotatePoint(&mvector, &vecatt, EEcos(t), EEsin(t)); test.cyl.origin.x += vecatt.x * curmovedist; test.cyl.origin.y += vecatt.y * curmovedist; test.cyl.origin.z += vecatt.z * curmovedist; if (ANCHOR_AttemptValidCylinderPos(&test.cyl, io, flags)) { memcpy(&rpos, &test.cyl.origin, sizeof(EERIE_3D)); RFOUND = 1; } rangle += ANGLESTEPP; memcpy(&test.cyl, &ip->cyl, sizeof(EERIE_CYLINDER)); t = DEG2RAD(MAKEANGLE(langle)); _YRotatePoint(&mvector, &vecatt, EEcos(t), EEsin(t)); test.cyl.origin.x += vecatt.x * curmovedist; test.cyl.origin.y += vecatt.y * curmovedist; test.cyl.origin.z += vecatt.z * curmovedist; if (ANCHOR_AttemptValidCylinderPos(&test.cyl, io, flags)) { memcpy(&lpos, &test.cyl.origin, sizeof(EERIE_3D)); LFOUND = 1; } langle -= ANGLESTEPP; if ((RFOUND) || (LFOUND)) break; } if ((LFOUND) && (RFOUND)) { langle = 360.f - langle; if (langle < rangle) { memcpy(&ip->cyl.origin, &lpos, sizeof(EERIE_3D)); distance -= curmovedist; } else { memcpy(&ip->cyl.origin, &rpos, sizeof(EERIE_3D)); distance -= curmovedist; } } else if (LFOUND) { memcpy(&ip->cyl.origin, &lpos, sizeof(EERIE_3D)); distance -= curmovedist; } else if (RFOUND) { memcpy(&ip->cyl.origin, &rpos, sizeof(EERIE_3D)); distance -= curmovedist; } else //stopped { ip->velocity.x = ip->velocity.y = ip->velocity.z = 0.f; MOVING_CYLINDER = 0; return FALSE; } } oki: ; } MOVING_CYLINDER = 0; return TRUE; }
//////////////////////////////////////////////////////////////////////////////////// // ALTERNATIVE METHOD void AnchorData_Create_Alternative_Method_I(EERIE_BACKGROUND * eb) { char text[256]; AnchorData_ClearAll(eb); EERIE_BKG_INFO * eg; EERIEPOLY * ep; EERIE_3D pos; long k; float count = 0; long lastper = -1; long per; float total = ARX_CLEAN_WARN_CAST_FLOAT(eb->Zsize * eb->Xsize * 4); for (long j = 0; j < eb->Zsize; j++) for (long i = 0; i < eb->Xsize; i++) { long LASTFOUND = 0; for (long divv = 0; divv < 4; divv++) { long divvx, divvy; switch (divv) { case 0: divvx = 0; divvy = 0; break; case 1: divvx = 1; divvy = 1; break; case 2: divvx = 0; divvy = 1; break; case 3: divvx = 1; divvy = 0; break; } float current_y = 99999999999.f; F2L((float)count / total * 100.f, &per); if (per != lastper) { sprintf(text, "Anchor Generation: %d%%", per); lastper = per; _ShowText(text); } count += 1.f; danaeApp.WinManageMess(); if (LASTFOUND) break; eg = &eb->Backg[i+j*eb->Xsize]; pos.x = (float)((float)((float)i + 0.5f * (float)divvx) * (float)eb->Xdiv); pos.y = 0.f; pos.z = (float)((float)((float)j + 0.5f * (float)divvy) * (float)eb->Zdiv); ep = GetMinPoly(pos.x, pos.y, pos.z); k = 0; EERIE_CYLINDER currcyl; currcyl.radius = 20 - (4.f * divv); currcyl.height = -120.f; currcyl.origin.x = pos.x; currcyl.origin.y = pos.y; currcyl.origin.z = pos.z; if (ep) { EERIEPOLY * epmax; epmax = GetMaxPoly(pos.x, pos.y, pos.z); float roof = 9999999.f; if (ep) roof = ep->min.y - 300; if (epmax) roof = epmax->min.y - 300; current_y = ep->max.y; while (current_y > roof) { currcyl.origin.y = current_y; EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin.x, currcyl.origin.y - 30.f, currcyl.origin.z); if (ep2 && !(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) ep2 = NULL; if ((ep2) && !(ep2->type & POLY_NOPATH)) { BOOL bval = ANCHOR_AttemptValidCylinderPos(&currcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_RETURN_HEIGHT | CFLAG_ANCHOR_GENERATION); if ((bval) && (currcyl.origin.y - 10.f <= current_y)) { EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin.x, currcyl.origin.y - 38.f, currcyl.origin.z); if (ep2 && !(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) { current_y -= 10.f; } else if ((ep2) && (ep2->type & POLY_NOPATH)) { current_y -= 10.f; } else if (AddAnchor_Original_Method(eb, eg, &currcyl.origin, 0)) { LASTFOUND++; current_y = currcyl.origin.y + currcyl.height; } else current_y -= 10.f; } else current_y -= 10.f; } else current_y -= 10.f; } } } } AnchorData_Create_Phase_II_Original_Method(eb); AnchorData_Create_Links_Original_Method(eb); /* TO KEEP // Parses Anchors to refine anchor creation... long ii,ia,ji,ja; EERIE_3D p1,p2; EERIE_BKG_INFO * eg2; count=0; total=eb->Zsize*eb->Xsize; long usable=0; if (0) for (j=0;j<eb->Zsize;j++) for (long i=0;i<eb->Xsize;i++) { F2L((float)count/(float)total*100.f,&per); if (per!=lastper) { sprintf(text,"Anchor Generation Pass II: %d%% Suitable %d",per,usable); lastper=per; _ShowText(text); } count++; eg=&eb->Backg[i+j*eb->Xsize]; for (long k=0;k<eg->nbianchors;k++) { ii=i-2; ia=i+2; ji=j-2; ja=j+2; FORCERANGE(ii,0,eb->Xsize-1); FORCERANGE(ia,0,eb->Xsize-1); FORCERANGE(ji,0,eb->Zsize-1); FORCERANGE(ja,0,eb->Zsize-1); for (long j2=ji;j2<=ja;j2++) for (long i2=ii;i2<=ia;i2++) { eg2=&eb->Backg[i2+j2*eb->Xsize]; for (long k2=0;k2<eg2->nbianchors;k2++) { // don't treat currently treated anchor if (eg->ianchors[k] == eg2->ianchors[k2]) continue; memcpy(&p1,&eb->anchors[eg->ianchors[k]].pos,sizeof(EERIE_3D)); memcpy(&p2,&eb->anchors[eg2->ianchors[k2]].pos,sizeof(EERIE_3D)); p1.y+=10.f; p2.y+=10.f; float dist=TRUEEEDistance3D(&p1,&p2); if (dist>120.f) continue; if (EEfabs(p1.y-p2.y)>80.f) continue; if ((eb->anchors[eg->ianchors[k]].radius>=40) && (eb->anchors[eg2->ianchors[k2]].radius>=40)) continue; { // found 2 usable anchors EERIE_3D pos; pos.x=(p1.x+p2.x)*DIV2; pos.y=(p1.y+p2.y)*DIV2; pos.z=(p1.z+p2.z)*DIV2; if (AddAnchor(eb,eg,&pos,MUST_BE_BIG)) usable++; } } } } }*/ }
void AnchorData_Create_Original_Method(EERIE_BACKGROUND * eb) { char text[256]; AnchorData_ClearAll(eb); EERIE_BKG_INFO * eg; EERIEPOLY * ep; EERIE_3D pos; #define DECALLL 20.f long k; float count = 0; long lastper = -1; long per; float total = ARX_CLEAN_WARN_CAST_FLOAT(eb->Zsize * eb->Xsize * 9); for (long j = 0; j < eb->Zsize; j++) for (long i = 0; i < eb->Xsize; i++) { long LASTFOUND = 0; for (long divv = 0; divv < 9; divv++) { long divvx, divvy; switch (divv) { case 0: divvx = 0; divvy = 0; break; case 1: divvx = 1; divvy = 0; break; case 2: divvx = 2; divvy = 0; break; case 3: divvx = 0; divvy = 1; break; case 4: divvx = 1; divvy = 1; break; case 5: divvx = 2; divvy = 1; break; case 6: divvx = 0; divvy = 2; break; case 7: divvx = 1; divvy = 2; break; case 8: divvx = 2; divvy = 2; break; } float current_y = 99999999999.f; F2L((float)count / total * 100.f, &per); if (per != lastper) { sprintf(text, "Anchor Generation: %d%%", per); lastper = per; _ShowText(text); } count += 1.f; danaeApp.WinManageMess(); if (LASTFOUND) break; eg = &eb->Backg[i+j*eb->Xsize]; pos.x = (float)((float)((float)i + 0.33f * (float)divvx) * (float)eb->Xdiv); pos.y = 0.f; pos.z = (float)((float)((float)j + 0.33f * (float)divvy) * (float)eb->Zdiv); ep = GetMinPoly(pos.x, pos.y, pos.z); k = 0; EERIE_CYLINDER currcyl; currcyl.radius = 20 - (4.f * divv); currcyl.height = -120.f; currcyl.origin.x = pos.x; currcyl.origin.y = pos.y; currcyl.origin.z = pos.z; if (ep) { EERIEPOLY * epmax; epmax = GetMaxPoly(pos.x, pos.y, pos.z); float roof = 9999999.f; if (ep) roof = ep->min.y - 300; if (epmax) roof = epmax->min.y - 300; current_y = ep->max.y; while (current_y > roof) { currcyl.origin.y = current_y; EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin.x, currcyl.origin.y - 30.f, currcyl.origin.z); if (ep2 && !(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) ep2 = NULL; if ((ep2) && !(ep2->type & POLY_NOPATH)) { BOOL bval = ANCHOR_AttemptValidCylinderPos(&currcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_RETURN_HEIGHT | CFLAG_ANCHOR_GENERATION); if ((bval) && (currcyl.origin.y - 10.f <= current_y)) { EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin.x, currcyl.origin.y - 38.f, currcyl.origin.z); if (ep2 && !(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) { current_y -= 10.f; } else if ((ep2) && (ep2->type & POLY_NOPATH)) { current_y -= 10.f; } else if (AddAnchor_Original_Method(eb, eg, &currcyl.origin, 0)) { LASTFOUND++; current_y = currcyl.origin.y + currcyl.height; } else current_y -= 10.f; } else current_y -= 10.f; } else current_y -= 10.f; } } } } AnchorData_Create_Phase_II_Original_Method(eb); AnchorData_Create_Links_Original_Method(eb); }
void AnchorData_Create_Phase_II_Original_Method(EERIE_BACKGROUND * eb) { char text[256]; EERIE_BKG_INFO * eg; EERIE_3D pos; long k; float count = 0; long lastper = -1; long per; float total = ARX_CLEAN_WARN_CAST_FLOAT(eb->Zsize * eb->Xsize); for (long j = 0; j < eb->Zsize; j++) for (long i = 0; i < eb->Xsize; i++) { float current_y = 99999999999.f; F2L((float)count / total * 100.f, &per); if (per != lastper) { sprintf(text, "Anchor Generation: %d%% (Pass II)", per); lastper = per; _ShowText(text); } count += 1.f; danaeApp.WinManageMess(); eg = &eb->Backg[i+j*eb->Xsize]; pos.x = (float)((float)((float)i) * (float)eb->Xdiv); pos.y = 0.f; pos.z = (float)((float)((float)j) * (float)eb->Zdiv); k = 0; EERIE_CYLINDER currcyl; currcyl.radius = 30; currcyl.height = -150.f; currcyl.origin.x = pos.x; currcyl.origin.y = pos.y; currcyl.origin.z = pos.z; if (eg->nbpolyin) { long ok = 0; for (long kkk = 0; kkk < eg->nbpolyin; kkk++) { EERIEPOLY * ep = eg->polyin[kkk]; if (ep->type & POLY_PRECISE_PATH) { ok = 1; break; } } if (!ok) continue; float roof = GetTileMinY(i, j); current_y = GetTileMaxY(i, j); while (current_y > roof) { long added = 0; for (float pposz = 0.f; pposz < 1.f; pposz += 0.1f) for (float pposx = 0.f; pposx < 1.f; pposx += 0.1f) { currcyl.origin.x = pos.x + pposx * eb->Xdiv; currcyl.origin.z = pos.z + pposz * eb->Zdiv; currcyl.origin.y = current_y; EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin.x, currcyl.origin.y - 10.f, currcyl.origin.z); if (!ep2) continue; if (!(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) continue; if (ep2->type & POLY_NOPATH) continue; if (ANCHOR_AttemptValidCylinderPos(&currcyl, NULL, CFLAG_NO_INTERCOL | CFLAG_EXTRA_PRECISION | CFLAG_RETURN_HEIGHT | CFLAG_ANCHOR_GENERATION)) { EERIEPOLY * ep2 = ANCHOR_CheckInPolyPrecis(currcyl.origin.x, currcyl.origin.y - 10.f, currcyl.origin.z); if (!ep2) continue; if (!(ep2->type & POLY_DOUBLESIDED) && (ep2->norm.y > 0.f)) continue; if (ep2->type & POLY_NOPATH) continue; if (DirectAddAnchor_Original_Method(eb, eg, &currcyl.origin, 0)) { added = 1; } } } if (added) current_y -= 160.f; current_y -= 50.f; } } } }