void FinalDestination::Initialize() { name = "finaldestination"; width = 512; height = 256; topdeath = -320; leftdeath = -192; rightdeath = 704; bottomdeath = 256; minhorizscroll = -128; maxhorizscroll = 384; minvertscroll = -192; maxvertscroll = 64; spawnx.push_back(160); spawnx.push_back(288); spawnx.push_back(96); spawnx.push_back(352); spawny.push_back(4); spawny.push_back(4); spawny.push_back(4); spawny.push_back(4); floors.push_back(Floor(64, 132, 384, 0, false)); walls.push_back(Wall(96, 132, 116, "left")); walls.push_back(Wall(416, 132, 116, "right")); walls.push_back(Wall(65, 132, 1, "left")); walls.push_back(Wall(447, 132, 1, "right")); ceilings.push_back(Ceiling(64, 132, 384)); ledges.push_back(Ledge(64, 132, "left")); ledges.push_back(Ledge(448, 132, "right")); songnames.push_back("Final Destination"); songnames.push_back("Final Destination"); songartists.push_back("Super Smash Bros. Brawl"); songartists.push_back("Super Smash Bros. Melee"); songs.push_back("SSBDS_Files/music/stages/finaldestination1.mp3"); songs.push_back("SSBDS_Files/music/stages/finaldestination2.mp3"); } // initializes all the variables for final destination
/**************************************************************************//** * @author Paul Blasi, Caitlin Taggart * * @par Description: * Main execution point of the app. Initializes the window and prepares the * main objects to be drawn on the screen. Also sets up the callback events. * * @returns Execution outcome. * *****************************************************************************/ int main(int argc, char *argv[]) { //set up the window glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); glutInitWindowPosition(100, 100); glutCreateWindow("Pong"); glClearColor(0.0, 0.0, 0.0, 1.0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //specify callbacks glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutKeyboardFunc(Keyboard); glutKeyboardUpFunc(KeyboardUp); glutSpecialFunc(SpecialKeys); glutSpecialUpFunc(SpecialKeysUp); glutTimerFunc(30, Animate, 1); //TODO set up players and ball BALL = Ball(Point(100, 50),5, WHITE); LEFT_PLAYER = Paddle(Point(10, 50), 10, 40, WHITE); RIGHT_PLAYER = Paddle(Point(190, 50), 10, 40, WHITE); NET = Net(Point(100, 50), VERTICAL, WHITE, 98); TOP_WALL = Wall(Point(100, 99), HORIZONTAL, WHITE, 198); BOTTOM_WALL = Wall(Point(100, 1), HORIZONTAL, WHITE, 198); LEFT_WALL = Wall(Point(1, 50), VERTICAL, WHITE, 98); RIGHT_WALL = Wall(Point(199, 50), VERTICAL, WHITE, 98); COLLISION_MAN.RegisterCollision(&BALL, &LEFT_PLAYER, BallCollideWithLeftPaddle); COLLISION_MAN.RegisterCollision(&BALL, &RIGHT_PLAYER, BallCollideWithRightPaddle); COLLISION_MAN.RegisterCollision(&BALL, &TOP_WALL, BallCollideWithWall); COLLISION_MAN.RegisterCollision(&BALL, &BOTTOM_WALL, BallCollideWithWall); COLLISION_MAN.RegisterCollision(&BALL, &LEFT_WALL, Score); COLLISION_MAN.RegisterCollision(&BALL, &RIGHT_WALL, Score); COLLISION_MAN.RegisterCollision(&LEFT_PLAYER, &TOP_WALL, LeftCollideWithWall); COLLISION_MAN.RegisterCollision(&LEFT_PLAYER, &BOTTOM_WALL, LeftCollideWithWall); COLLISION_MAN.RegisterCollision(&LEFT_PLAYER, &LEFT_WALL, LeftCollideWithWall); COLLISION_MAN.RegisterCollision(&LEFT_PLAYER, &NET, LeftCollideWithWall); COLLISION_MAN.RegisterCollision(&RIGHT_PLAYER, &TOP_WALL, RightCollideWithWall); COLLISION_MAN.RegisterCollision(&RIGHT_PLAYER, &BOTTOM_WALL, RightCollideWithWall); COLLISION_MAN.RegisterCollision(&RIGHT_PLAYER, &RIGHT_WALL, RightCollideWithWall); COLLISION_MAN.RegisterCollision(&RIGHT_PLAYER, &NET, RightCollideWithWall); glutMainLoop(); return 0; }
int CSegment::AnimateOpeningDoor (int nSide, fix xElapsedTime) { CWall *wallP = Wall (nSide); if (!wallP) return 3; return wallP->AnimateOpeningDoor (xElapsedTime); }
//----------------------------------------------------------------- // Turns off an illusionary CWall (This will be used primarily for // CWall switches or triggers that can turn on/off illusionary walls.) void CSegment::IllusionOff (int nSide) { CWall* wallP = Wall (nSide); if (!wallP) return; CSegment *connSegP; short nConnSide; wallP->flags |= WALL_ILLUSION_OFF; KillStuckObjects (wallP - WALLS); if (m_children [nSide] < 0) { if (gameOpts->legacy.bWalls) Warning (TXT_ILLUS_SINGLE, this - SEGMENTS, nSide); connSegP = NULL; nConnSide = -1; } else { connSegP = SEGMENTS + m_children [nSide]; nConnSide = ConnectedSide (connSegP); if ((wallP = connSegP->Wall (nSide))) { wallP->flags |= WALL_ILLUSION_OFF; KillStuckObjects (wallP - WALLS); } } }
int CSegment::ProcessWallHit (int nSide, fix damage, int nPlayer, CObject *objP) { CWall* wallP = Wall (nSide); if (!wallP) return WHP_NOT_SPECIAL; if (gameData.demo.nState == ND_STATE_RECORDING) NDRecordWallHitProcess (SEG_IDX (this), nSide, damage, nPlayer); if (wallP->nType == WALL_BLASTABLE) { if (objP->cType.laserInfo.parent.nType == OBJ_PLAYER) DamageWall (nSide, damage); return WHP_BLASTABLE; } if (nPlayer != gameData.multiplayer.nLocalPlayer) //return if was robot fire return WHP_NOT_SPECIAL; Assert(nPlayer > -1); // Determine whether CPlayerData is moving forward. If not, don't say negative // messages because he probably didn't intentionally hit the door. return wallP->ProcessHit (nPlayer, objP); }
MapManager DungeonGenerator::Generate(const DungeonSize& sizeData, const DungeonData& dungeonData) { MapManager manager; for (size_t i = 0; i < sizeData.DungeonHeight(); ++i) { for (size_t j = 0; j < sizeData.DungeonWidth(); ++j) { if (dungeonData.IsThis(ObjTypeOnMap::WALL, i, j)) { auto wall = std::make_shared<Wall>(Wall(Vector2(j*GeneralConstant::img_size_width, i*GeneralConstant::img_size_height))); manager.Add(wall); continue; } if (dungeonData.IsThis(ObjTypeOnMap::FLOOR, i, j)) { auto floor = std::make_shared<Floor>(Floor(Vector2(j*GeneralConstant::img_size_width, i*GeneralConstant::img_size_height))); manager.Add(floor); continue; } if (dungeonData.IsThis(ObjTypeOnMap::PATH, i, j)) { auto path = std::make_shared<Path>(Path(Vector2(j*GeneralConstant::img_size_width, i*GeneralConstant::img_size_height))); manager.Add(path); continue; } } } return manager; }
void CastleSiege::Initialize() { name = "castlesiege"; width = 512; height = 384; topdeath = -320; bottomdeath = 384; leftdeath = -128; rightdeath = 576; minhorizscroll = -64; maxhorizscroll = 256; minvertscroll = -192; maxvertscroll = 64; spawnx.push_back(160); spawnx.push_back(288); spawnx.push_back(96); spawnx.push_back(352); spawny.push_back(88); spawny.push_back(88); spawny.push_back(88); spawny.push_back(88); floors.push_back(Floor(40, 216, 161, 0, false)); floors.push_back(Floor(202, 216, 98, 25, false)); floors[0].rightneighbor = 1; floors[1].leftneighbor = 0; floors[1].rightneighbor = 2; floors.push_back(Floor(300, 191, 150, 0, false)); floors[2].leftneighbor = 1; floors.push_back(Floor(84, 160, 110, 0, true)); floors.push_back(Floor(302, 142, 104, 0, true)); ledges.push_back(Ledge(40, 216, "left")); ledges.push_back(Ledge(450, 191, "right")); walls.push_back(Wall(41, 216, 40, "left")); walls.push_back(Wall(449, 191, 40, "right")); ceilings.push_back(Ceiling(40, 256, 100)); ceilings.push_back(Ceiling(349, 231, 100)); walls.push_back(Wall(55, 256, 200, "left")); walls.push_back(Wall(435, 231, 200, "right")); songnames.push_back("Ike's Theme"); songnames.push_back("Victory is Near"); songartists.push_back("Fire Emblem 10: Radiant Dawn"); songartists.push_back("Fire Emblem 9: Path of Radiance"); songs.push_back("SSBDS_Files/music/stages/castlesiege1.mp3"); songs.push_back("SSBDS_Files/music/stages/castlesiege2.mp3"); } // initializes Castle Siege
//----------------------------------------------------------------- // Destroys a blastable CWall. void CSegment::DestroyWall (int nSide) { CWall* wallP = Wall (nSide); if (wallP) { if (wallP->nType == WALL_BLASTABLE) BlastWall (nSide); else Error (TXT_WALL_INDESTRUCTIBLE); } }
//----------------------------------------------------------------- // Opens a door void CSegment::OpenDoor (int nSide) { CWall* wallP; if (!(wallP = Wall (nSide))) return; CActiveDoor* doorP; if (!(doorP = wallP->OpenDoor ())) return; short nConnSide, nConnWall = NO_WALL; CSegment *connSegP; // So that door can't be shot while opening if (m_children [nSide] < 0) { if (gameOpts->legacy.bWalls) Warning (TXT_OPEN_SINGLE, this - SEGMENTS, nSide, WallNum (nSide)); connSegP = NULL; nConnSide = -1; nConnWall = NO_WALL; } else { connSegP = SEGMENTS + m_children [nSide]; nConnSide = ConnectedSide (connSegP); if (nConnSide >= 0) { CWall* wallP = connSegP->Wall (nConnSide); if (wallP) wallP->state = WALL_DOOR_OPENING; } } //KillStuckObjects(WallNumP (connSegP, nConnSide)); doorP->nFrontWall [0] = WallNum (nSide); doorP->nBackWall [0] = nConnWall; Assert(SEG_IDX (this) != -1); if (gameData.demo.nState == ND_STATE_RECORDING) NDRecordDoorOpening (SEG_IDX (this), nSide); if (IS_WALL (wallP->nLinkedWall) && IS_WALL (nConnWall) && (wallP->nLinkedWall == nConnWall)) { CWall *linkedWallP = WALLS + wallP->nLinkedWall; CSegment *linkedSegP = SEGMENTS + linkedWallP->nSegment; linkedWallP->state = WALL_DOOR_OPENING; connSegP = SEGMENTS + linkedSegP->m_children [linkedWallP->nSide]; if (IS_WALL (nConnWall)) WALLS [nConnWall].state = WALL_DOOR_OPENING; doorP->nPartCount = 2; doorP->nFrontWall [1] = wallP->nLinkedWall; doorP->nBackWall [1] = linkedSegP->ConnectedSide (connSegP); } else doorP->nPartCount = 1; if (gameData.demo.nState != ND_STATE_PLAYBACK) { if (gameData.walls.animP [wallP->nClip].openSound > -1) CreateSound (gameData.walls.animP [wallP->nClip].openSound, nSide); } }
//extern "C" SEXP log_marg_A0k(SEXP WpostR, SEXP A0R, SEXP N2R, SEXP consttermR, SEXP bfR, SEXP UTR, SEXP TinvR, SEXP dfR, SEXP n0R) { int i, j, *dTi, db, m, N2, df, len; N2=INTEGER(N2R)[0]; df=INTEGER(dfR)[0]; m=INTEGER(coerceVector(listElt(WpostR,"m"),INTSXP))[0]; double *pbfi, *lpa0, *cterm, lN2, tol, maxvlog, lqlog; lN2=log((double)N2); tol=1E-12; cterm=REAL(consttermR); //Rprintf("m: %d\nN2: %d\ndf: %d\n",m,N2,df); // Initialize Tinv/b.free/vlog variables SEXP Ti, bfi; Matrix Tinv; ColumnVector bfree, vlog(N2), qlog; // Initialize Wlist/W/Wmat objects and populate Wlist from WpostR Wlist Wall(WpostR,N2); Wobj W; Matrix Wmat; // Initialize SEXP/ptr to store/access log marginal A0k values SEXP lpa0yao; PROTECT(lpa0yao=allocVector(REALSXP,m)); lpa0=REAL(lpa0yao); for(i=0;i<m-1;i++){ PROTECT(Ti=VECTOR_ELT(TinvR,i)); dTi=getdims(Ti); Tinv=R2Cmat(Ti,dTi[0],dTi[1]); UNPROTECT(1); //Rprintf("Tinv[[%d]](%dx%d) initialized\n",i,dTi[0],dTi[1]); PROTECT(bfi=VECTOR_ELT(bfR,i)); db=length(bfi); bfree.ReSize(db); pbfi=REAL(bfi); bfree<<pbfi; UNPROTECT(1); //Rprintf("bfree[[%d]](%d) initialized\n",i,db); for(j=1;j<=N2;j++){ Wall.getWobj(W,j); Wmat=W.getWelt(i+1); W.clear(); vlog(j)=getvlog(Wmat,Tinv,bfree,cterm[i],df,tol); //Rprintf("vlog(%d): %f\n",j,vlog(j)); } // Modified harmonic mean of the max maxvlog=vlog.Maximum(); qlog=vlog-maxvlog; len=qlog.Storage(); lqlog=0; for(j=1;j<=len;j++) lqlog+=exp(qlog(j)); lqlog=log(lqlog); // log(sum(exp(qlog))) lpa0[i]=maxvlog-lN2+lqlog; //Rprintf("lpa0[%d] = %f\n", i, lpa0[i]); } // Computations for last column PROTECT(Ti=VECTOR_ELT(TinvR,m-1)); dTi=getdims(Ti); Tinv=R2Cmat(Ti,dTi[0],dTi[1]); UNPROTECT(1); //Rprintf("Tinv[[%d]](%dx%d) initialized\n",i,dTi[0],dTi[1]); PROTECT(bfi=VECTOR_ELT(bfR,m-1)); pbfi=REAL(bfi); bfree.ReSize(length(bfi)); bfree<<pbfi; UNPROTECT(1); //Rprintf("bfree[[%d]](%d) initialized\n",i,db); UTobj UT(UTR); Matrix A0=R2Cmat(A0R,m,m); A0=drawA0cpp(A0,UT,df,INTEGER(n0R),W); Wmat=W.getWelt(m); lpa0[m-1]=getvlog(Wmat,Tinv,bfree,cterm[m-1],df,tol); //Rprintf("lpa0[%d] = %f\n",m-1,lpa0[m-1]); // Return R object lpa0yao UNPROTECT(1); return lpa0yao; }
//----------------------------------------------------------------- // Opens doors/destroys CWall/shuts off triggers. void CSegment::ToggleWall (int nSide) { CWall *wallP = Wall (nSide); if (!wallP) return; if (gameData.demo.nState == ND_STATE_RECORDING) NDRecordWallToggle (SEG_IDX (this), nSide); if (wallP->nType == WALL_BLASTABLE) DestroyWall (nSide); if ((wallP->nType == WALL_DOOR) && (wallP->state == WALL_DOOR_CLOSED)) OpenDoor (nSide); }
/* * Draw scene * light>0 lit colors * light<0 shaded colors * light=0 shadow volumes */ void Scene(int Light) { int k; // Counters used to draw floor // Set global light switch (used in DrawPolyShadow) light = Light; // Texture (pi.bmp) glBindTexture(GL_TEXTURE_2D,tex2d[2]); // Enable textures if not drawing shadow volumes if (light) glEnable(GL_TEXTURE_2D); // Draw objects x y z th,ph dims if (obj&0x01) Cube(-0.8,+0.8,0.0 , -0.25*zh, 0 , 0.3 ); if (obj&0x02) Cylinder(+0.8,+0.5,0.0 , 0.5*zh,zh , 0.2,0.5); if (obj&0x04) Torus(+0.5,-0.8,0.0 , 0,zh , 0.5,0.2); if (obj&0x08) Teapot(-0.5,-0.5,0.0 , 2*zh, 0 , 0.25 ); // Disable textures if (light) glDisable(GL_TEXTURE_2D); // The floor, ceiling and walls don't cast a shadow, so bail here if (!light) return; // Always enable textures glEnable(GL_TEXTURE_2D); Color(1,1,1); // Water texture for floor and ceiling glBindTexture(GL_TEXTURE_2D,tex2d[0]); for (k=-1;k<=box;k+=2) Wall(0,0,0, 0,90*k , 8,8,box?6:2 , 4); // Crate texture for walls glBindTexture(GL_TEXTURE_2D,tex2d[1]); for (k=0;k<4*box;k++) Wall(0,0,0, 90*k,0 , 8,box?6:2,8 , 1); // Disable textures glDisable(GL_TEXTURE_2D); }
SoccerPitch::SoccerPitch(int cx, int cy): m_cxClient(cx), m_cyClient(cy), m_bPaused(false) { //GoalWidth指的是得分區厚度 int GoalWidth = 200; m_pPlayingArea = new Region(20, 20, cx-20, cy-20); // m_pRedGoal = new Goal(V2D(m_pPlayingArea->Left(), (cy-GoalWidth)/2), V2D(m_pPlayingArea->Left(), cy - (cy-GoalWidth)/2), V2D(1,0)); m_pBlueGoal = new Goal(V2D( m_pPlayingArea->Right(), (cy-GoalWidth)/2), V2D(m_pPlayingArea->Right(), cy - (cy-GoalWidth)/2), V2D(-1,0)); //建立外牆 V2D TopLeft(m_pPlayingArea->Left(), m_pPlayingArea->Top()); V2D TopRight(m_pPlayingArea->Right(), m_pPlayingArea->Top()); V2D BottomRight(m_pPlayingArea->Right(), m_pPlayingArea->Bottom()); V2D BottomLeft(m_pPlayingArea->Left(), m_pPlayingArea->Bottom()); m_vecWalls.push_back(Wall(BottomLeft, m_pRedGoal->RightPost())); m_vecWalls.push_back(Wall(m_pRedGoal->LeftPost(), TopLeft)); m_vecWalls.push_back(Wall(TopLeft, TopRight)); m_vecWalls.push_back(Wall(TopRight, m_pBlueGoal->LeftPost())); m_vecWalls.push_back(Wall(m_pBlueGoal->RightPost(), BottomRight)); m_vecWalls.push_back(Wall(BottomRight, BottomLeft)); }
void PokemonStadium::Initialize() { name = "pokemonstadium"; width = 512; height = 256; topdeath = -320; bottomdeath = 256; leftdeath = -192; rightdeath = 704; minhorizscroll = -128; maxhorizscroll = 384; minvertscroll = -192; maxvertscroll = 64; spawnx.push_back(160); spawnx.push_back(288); spawnx.push_back(96); spawnx.push_back(352); spawny.push_back(26); spawny.push_back(26); spawny.push_back(26); spawny.push_back(26); floors.push_back(Floor(42, 154, 428, 0, false)); floors.push_back(Floor(128, 110, 62, 0, true)); floors.push_back(Floor(324, 110, 62, 0, true)); walls.push_back(Wall(43, 154, 102, "left")); walls.push_back(Wall(469, 154, 102, "right")); ceilings.push_back(Ceiling(42, 216, 428)); ledges.push_back(Ledge(42, 154, "left")); ledges.push_back(Ledge(470, 154, "right")); songnames.push_back("Pokemon Gym / Evolution"); songnames.push_back("Battle Theme"); songnames.push_back("Lugia's Song"); songartists.push_back("Pokemon Red/Blue/Yellow"); songartists.push_back("Pokemon Gold/Silver/Crystal"); songartists.push_back("Pokemon 2000"); songs.push_back("SSBDS_Files/music/stages/pokemonstadium1.mp3"); songs.push_back("SSBDS_Files/music/stages/pokemonstadium2.mp3"); songs.push_back("SSBDS_Files/music/stages/pokemonstadium3.mp3"); } // initializes the pokemon stadium stage
Wall_Entity Light_Manager::Add_Wall(sf::Vector2f pt1,sf::Vector2f pt2) { for(int i=0;i<(int)m_wall.size();i++) if((pt1.y-pt2.y)/(pt1.x-pt2.y)==(m_wall[i].pt1.y-m_wall[i].pt2.y)/(m_wall[i].pt1.x-m_wall[i].pt2.y)) if(pt1==m_wall[i].pt1 || pt2==m_wall[i].pt1 || pt1==m_wall[i].pt2 || pt2==m_wall[i].pt2) { sf::Vector2f min=pt1,max=pt2; if(pt2.x<min.x) min.x=pt2.x; if(pt1.x>max.x) max.x=pt2.x; if(m_wall[i].pt1.x<min.x) min.x=m_wall[i].pt1.x; if(m_wall[i].pt2.x<min.x) min.x=m_wall[i].pt2.x; if(m_wall[i].pt1.x>max.x) max.x=m_wall[i].pt1.x; if(m_wall[i].pt2.x>max.x) max.x=m_wall[i].pt2.x; if(pt2.y<min.y) min.y=pt2.y; if(pt1.y>max.y) max.y=pt2.y; if(m_wall[i].pt1.y<min.y) min.y=m_wall[i].pt1.y; if(m_wall[i].pt2.y<min.y) min.y=m_wall[i].pt2.y; if(m_wall[i].pt1.y>max.y) max.y=m_wall[i].pt1.y; if(m_wall[i].pt2.y>max.y) max.y=m_wall[i].pt2.y; m_wall[i].pt1=min; m_wall[i].pt2=max; return Wall_Entity(i); } m_wall.push_back(Wall (pt1,pt2)); return Wall_Entity(m_wall.size()-1); }
Wall Projectile::checkWallCollision(int deltax, int deltay) { for(int n = 0; n < (int)((mystage -> getWalls()).size()); n++) { if(dx > 0) { if(x+deltax <= mystage -> getWalls()[n].x && x+deltax+dx > mystage -> getWalls()[n].x && y+deltay+dy > mystage -> getWalls()[n].y && y+deltax+dy < mystage -> getWalls()[n].y + mystage -> getWalls()[n].length) { return mystage -> getWalls()[n]; } } else if(dx < 0) { if(x+deltax >= mystage -> getWalls()[n].x && x+deltax+dx < mystage -> getWalls()[n].x && y+deltay+dy > mystage -> getWalls()[n].y && y+deltax+dy < mystage -> getWalls()[n].y + mystage -> getWalls()[n].length) { return mystage -> getWalls()[n]; } } } return Wall(0, 0, 0, 0, ""); }
//----------------------------------------------------------------- // Deteriorate appearance of CWall. (Changes bitmap (paste-ons)) void CSegment::DamageWall (int nSide, fix damage) { int a, i, n; short nConnSide, nConnWall; CWall *wallP = Wall (nSide); CSegment *connSegP; if (!wallP) { #if TRACE console.printf (CON_DBG, "Damaging illegal CWall\n"); #endif return; } if (wallP->nType != WALL_BLASTABLE) return; if ((wallP->flags & WALL_BLASTED) || (wallP->hps < 0)) return; if (m_children [nSide] < 0) { if (gameOpts->legacy.bWalls) Warning (TXT_DMG_SINGLE, this - SEGMENTS, nSide, wallP - WALLS); connSegP = NULL; nConnSide = -1; nConnWall = NO_WALL; } else { connSegP = SEGMENTS + m_children [nSide]; nConnSide = ConnectedSide (connSegP); Assert(nConnSide != -1); nConnWall = connSegP->WallNum (nConnSide); } wallP->hps -= damage; if (IS_WALL (nConnWall)) WALLS [nConnWall].hps -= damage; a = wallP->nClip; n = AnimFrameCount (gameData.walls.animP + a); if (wallP->hps < WALL_HPS * 1 / n) { BlastWall (nSide); if (IsMultiGame) MultiSendDoorOpen (SEG_IDX (this), nSide, wallP->flags); } else { for (i = 0; i < n; i++) if (wallP->hps < WALL_HPS * (n - i) / n) SetTexture (nSide, connSegP, nConnSide, a, i); } }
/// Format configuration fajla: /// svaki red predstavlja 1 zid: /// x y w h is_dangerous /// (is_dangerous je + ili -) /// poslednji red ima w = h = 0 Configuration::Configuration(std::string fileName) { std::ifstream fs(fileName); if(!fs.good()) { std::cerr << "Error: cannot open file " << fileName << std::endl; return; } while(!fs.eof()) { double x, y, w, h; char d; fs >> x >> y >> w >> h >> d; if(w == 0 && h == 0) break; walls.push_back(Wall(x, y, w, h, d == '+')); } }
// start the transition from closed -> open CWall void CSegment::StartCloak (int nSide) { if (gameData.demo.nState == ND_STATE_PLAYBACK) return; CWall* wallP = Wall (nSide); if (!wallP) return; if (wallP->nType == WALL_OPEN || wallP->state == WALL_DOOR_CLOAKING) //already open or cloaking return; CCloakingWall* cloakWallP; CSegment* connSegP; short nConnSide; int i; short nConnWall; connSegP = SEGMENTS + m_children [nSide]; nConnSide = ConnectedSide (connSegP); if (!(cloakWallP = wallP->StartCloak ())) { wallP->nType = WALL_OPEN; if ((wallP = connSegP->Wall (nConnSide))) wallP->nType = WALL_OPEN; return; } nConnWall = connSegP->WallNum (nConnSide); if (IS_WALL (nConnWall)) WALLS [nConnWall].state = WALL_DOOR_CLOAKING; cloakWallP->nFrontWall = WallNum (nSide); cloakWallP->nBackWall = nConnWall; Assert(SEG_IDX (this) != -1); //Assert(!IS_WALL (wallP->nLinkedWall)); if (gameData.demo.nState != ND_STATE_PLAYBACK) { CreateSound (SOUND_WALL_CLOAK_ON, nSide); } for (i = 0; i < 4; i++) { cloakWallP->front_ls [i] = m_sides [nSide].m_uvls [i].l; if (IS_WALL (nConnWall)) cloakWallP->back_ls [i] = connSegP->m_sides [nConnSide].m_uvls [i].l; } }
Wall_Entity Light_Manager::Add_Wall(sf::Vector2f pt1,sf::Vector2f pt2,int hauteur) { /* if(pt2.x<pt1.x) { sf::Vector2f buffer=pt1; pt1=pt2,pt2=buffer; } for(int i=0;i<(int)m_wall.size();i++) // if(hauteur==m_wall[i].hauteur) if((pt1.x+2>=(int)m_wall[i].pt1.x && pt1.x-2<=(int)m_wall[i].pt1.x && pt1.y+2>=(int)m_wall[i].pt1.y && pt1.y-2<=(int)m_wall[i].pt1.y) ||(pt1.x+2>=(int)m_wall[i].pt2.x && pt1.x-2<=(int)m_wall[i].pt2.x && pt1.y+2>=(int)m_wall[i].pt2.y && pt1.y-2<=(int)m_wall[i].pt2.y) ||(pt2.x+2>=(int)m_wall[i].pt1.x && pt2.x-2<=(int)m_wall[i].pt1.x && pt2.y+2>=(int)m_wall[i].pt1.y && pt2.y-2<=(int)m_wall[i].pt1.y) ||(pt2.x+2>=(int)m_wall[i].pt2.x && pt2.x-2<=(int)m_wall[i].pt2.x && pt2.y+2>=(int)m_wall[i].pt2.y && pt2.y-2<=(int)m_wall[i].pt2.y)) { if(((pt1.y-pt2.y)/(pt1.x-pt2.y))==((m_wall[i].pt1.y-m_wall[i].pt2.y)/(m_wall[i].pt1.x-m_wall[i].pt2.y))) { sf::Vector2f min=pt1,max=pt2; if(pt2.x<min.x) min=pt2; if(m_wall[i].pt1.x<min.x) min=m_wall[i].pt1; if(m_wall[i].pt2.x<min.x) min=m_wall[i].pt2; if(pt1.x>max.x) max=pt1; if(m_wall[i].pt1.x>max.x) max=m_wall[i].pt1; if(m_wall[i].pt2.x>max.x) max=m_wall[i].pt2; m_wall[i].pt1=min; m_wall[i].pt2=max; return Wall_Entity(i); } }*/ m_wall.push_back(Wall (pt1,pt2,hauteur)); return Wall_Entity(m_wall.size()-1); }
//----------------------------------------------------------------- // Closes a door void CSegment::CloseDoor (int nSide) { CWall* wallP; if (!(wallP = Wall (nSide))) return; if ((wallP->state == WALL_DOOR_CLOSING) || //already closing (wallP->state == WALL_DOOR_WAITING) || //open, waiting to close (wallP->state == WALL_DOOR_CLOSED)) //closed return; if (DoorIsBlocked (nSide)) return; CActiveDoor* doorP; if (!(doorP = wallP->CloseDoor ())) return; CSegment* connSegP; short nConnSide, nConnWall; connSegP = SEGMENTS + m_children [nSide]; nConnSide = ConnectedSide (connSegP); nConnWall = connSegP->WallNum (nConnSide); if (IS_WALL (nConnWall)) WALLS [nConnWall].state = WALL_DOOR_CLOSING; doorP->nFrontWall [0] = WallNum (nSide); doorP->nBackWall [0] = nConnWall; Assert(SEG_IDX (this) != -1); if (gameData.demo.nState == ND_STATE_RECORDING) NDRecordDoorOpening (SEG_IDX (this), nSide); if (IS_WALL (wallP->nLinkedWall)) Int3(); //don't think we ever used linked walls else doorP->nPartCount = 1; if (gameData.demo.nState != ND_STATE_PLAYBACK) { if (gameData.walls.animP [wallP->nClip].openSound > -1) CreateSound (gameData.walls.animP [wallP->nClip].openSound, nSide); } }
// ------------------------------------------------------------------------------- //when the CWall has used all its hitpoints, this will destroy it void CSegment::BlastWall (int nSide) { short nConnSide; CSegment* connSegP; int a, n; short nConnWall; CWall* wallP = Wall (nSide); if (!wallP) return; wallP->hps = -1; //say it's blasted if (m_children [nSide] < 0) { if (gameOpts->legacy.bWalls) Warning (TXT_BLAST_SINGLE, this - SEGMENTS, nSide, wallP - WALLS); connSegP = NULL; nConnSide = -1; nConnWall = NO_WALL; } else { connSegP = SEGMENTS + m_children [nSide]; nConnSide = ConnectedSide (connSegP); Assert (nConnSide != -1); nConnWall = connSegP->WallNum (nConnSide); KillStuckObjects (nConnWall); } KillStuckObjects (WallNum (nSide)); //if this is an exploding wall, explode it if ((gameData.walls.animP [wallP->nClip].flags & WCF_EXPLODES) && !(wallP->flags & WALL_BLASTED)) ExplodeWall (Index (), nSide); else { //if not exploding, set final frame, and make door passable a = wallP->nClip; n = AnimFrameCount (gameData.walls.animP + a); SetTexture (nSide, connSegP, nConnSide, a, n - 1); wallP->flags |= WALL_BLASTED; if (IS_WALL (nConnWall)) WALLS [nConnWall].flags |= WALL_BLASTED; } }
//----------------------------------------------------------------- // start the transition from open -> closed CWall void CSegment::StartDecloak (int nSide) { if (gameData.demo.nState == ND_STATE_PLAYBACK) return; CWall *wallP; if (!(wallP = Wall (nSide))) return; if (wallP->nType == WALL_CLOSED || wallP->state == WALL_DOOR_DECLOAKING) //already closed or decloaking return; CCloakingWall *cloakWallP; short nConnSide; CSegment *connSegP; int i; connSegP = SEGMENTS + m_children [nSide]; nConnSide = ConnectedSide (connSegP); if (!(cloakWallP = wallP->StartDecloak ())) { wallP->state = WALL_CLOSED; if ((wallP = connSegP->Wall (nConnSide))) wallP->state = WALL_CLOSED; return; } // So that door can't be shot while opening if ((wallP = connSegP->Wall (nConnSide))) wallP->state = WALL_DOOR_DECLOAKING; cloakWallP->nFrontWall = WallNum (nSide); cloakWallP->nBackWall = connSegP->WallNum (nConnSide); if (gameData.demo.nState != ND_STATE_PLAYBACK) { CreateSound (SOUND_WALL_CLOAK_OFF, nSide); } for (i = 0; i < 4; i++) { cloakWallP->front_ls [i] = m_sides [nSide].m_uvls [i].l; if (wallP) cloakWallP->back_ls [i] = connSegP->m_sides [nConnSide].m_uvls [i].l; } }
void World::setFromMesh(const Mesh &mesh) { // DOPE_WARN("called"); // this does not have to be fast since it is called only once or twice ;-) // copy all vertices m_vertices=mesh.vertices; m_startPoints=mesh.startPoints; m_startObjects=mesh.startObjects; // calculate bounding box R big=999999999999; // todo m_topLeft=V2D(big,-big); m_bottomRight=V2D(-big,big); for (unsigned i=0;i<m_vertices.size();++i){ m_topLeft=V2D(std::min(m_topLeft[0],m_vertices[i][0]), std::max(m_topLeft[1],m_vertices[i][1])); m_bottomRight=V2D(std::max(m_bottomRight[0],m_vertices[i][0]), std::min(m_bottomRight[1],m_vertices[i][1])); } // constuct our new edge-list typedef std::pair<Edge::VID,Edge::VID> Key; typedef FWEdge::EID Value; // first edge ID of the current room FWEdge::EID fe; // the first edge was clockwise bool feCW; // the ID of the last edge we visisted FWEdge::EID lastID=FWEdge::noEdge; // the last edge was clockwise bool lastCW; // half edges already stored std::map<Key,Value> stored; for (Mesh::EID ce=0;ce<mesh.edgelist.size();++ce) { if (mesh.edgelist[ce].vid==-1) continue; // first edge of room bool firstEdge=(lastID==FWEdge::noEdge); // next edge in this room Mesh::EID ne=mesh.getNCW(ce); // is this the "last" edge of this room ? bool leor=mesh.lastEdgeOfRoom(ce); // if it is the first edge remember this id // we assume that all rooms are in clockwise or counter clockwise order // each edge is visited in both directions or only once (borders) std::map<Key,Value>::const_iterator it(stored.find(Key(mesh.edgelist[ne].vid,mesh.edgelist[ce].vid))); // \todo clean it up this is nearly twice if (it!=stored.end()) { // we visited this edge already - set current full winged edge Value cfweID=it->second; if (firstEdge) { fe=cfweID; // todo here is a bug? (if the first edge is not CW there is a bug) feCW=false; } FWEdge &cfwe=m_edges[cfweID]; // cfwe.m_nccw=; if (!firstEdge) { cfwe.m_pccw=lastID; if (lastCW) m_edges[lastID].m_ncw=cfweID; else m_edges[lastID].m_nccw=cfweID; } cfwe.m_rccw=m_rooms.size(); cfwe.m_etccw=mesh.edgelist[ce].type; if (leor) { // we finished this room if (feCW) m_edges[fe].m_pcw=cfweID; else m_edges[fe].m_pccw=cfweID; cfwe.m_nccw=fe; Room newRoom; newRoom.m_e=fe; newRoom.m_cw=feCW; m_rooms.push_back(newRoom); fe=lastID=FWEdge::noEdge; }else{ lastID=cfweID; lastCW=false; } } else { // we did not visit this edge yet // the id of the new edge FWEdge::EID newID=m_edges.size(); if (firstEdge) { fe=newID; feCW=true; } // fill in the things we know already FWEdge newEdge; newEdge.m_sv=mesh.edgelist[ce].vid; newEdge.m_ev=mesh.edgelist[ne].vid; // if it is the first edge we have to fill this in later if (!firstEdge) { newEdge.m_pcw=lastID; if (lastCW) m_edges[lastID].m_ncw=newID; else m_edges[lastID].m_nccw=newID; } // we don't know yet but the constructor initialized to noEdge/noRoom // newEdge.m_ncw=FWEdge::noEdge; // newEdge.m_nccw=FWEdge::noEdge; // newEdge.m_pccw=FWEdge::noEdge; newEdge.m_rcw=m_rooms.size(); newEdge.m_etcw=mesh.edgelist[ce].type; // newEdge.m_rccw=FWEdge::noRoom; if (leor) { // we finished this room if (feCW) m_edges[fe].m_pcw=newID; else m_edges[fe].m_pccw=newID; newEdge.m_ncw=fe; Room newRoom; newRoom.m_e=fe; newRoom.m_cw=feCW; m_rooms.push_back(newRoom); fe=lastID=FWEdge::noEdge; }else{ lastID=newID; lastCW=true; } // calculate corresponding wall DOPE_ASSERT(newEdge.m_sv<m_vertices.size()&&newEdge.m_ev<m_vertices.size()); newEdge.m_wall=Wall(Line(m_vertices[newEdge.m_sv],m_vertices[newEdge.m_ev])); m_edges.push_back(newEdge); stored[Key(mesh.edgelist[ce].vid,mesh.edgelist[ne].vid)]=newID; // std::cout << "Stored "<<mesh.edgelist[ce].vid<<","<<mesh.edgelist[ne].vid<<std::endl; } } for (unsigned r=0;r<m_rooms.size();++r) { m_rooms[r].m_poly=getLineLoop(r); // loop through edges of this room EdgeIterator end(*this); for (EdgeIterator it(*this,r);it!=end;++it) { if (it.getEdge().isDoor()) continue; m_rooms[r].m_walls.push_back(it.getEdge().m_wall); m_rooms[r].m_eids.push_back(it.getID()); } } }
// ----------------------------------------------------------------------------- //if an effect is hit, and it can blow up, then blow it up //returns true if it blew up int CSegment::CheckEffectBlowup (int nSide, CFixVector& vHit, CObject* blowerP, int bForceBlowup) { int tm, tmf, ec, nBitmap = 0; int bOkToBlow = 0, nSwitchType = -1; short nSound, bPermaTrigger; ubyte vc; fix u, v; fix xDestSize; tEffectClip* ecP = NULL; CBitmap* bmP; CWall* wallP; CTrigger* trigP; CObject* parentP = (!blowerP || (blowerP->cType.laserInfo.parent.nObject < 0)) ? NULL : OBJECTS + blowerP->cType.laserInfo.parent.nObject; // If this CWall has a CTrigger and the blowerP-upper is not the CPlayerData or the buddy, abort! if (parentP) { if ((parentP->info.nType == OBJ_ROBOT) && ROBOTINFO (parentP->info.nId).companion) bOkToBlow = 1; if (!(bOkToBlow || (parentP->info.nType == OBJ_PLAYER)) && ((wallP = Wall (nSide)) && (wallP->nTrigger < gameData.trigs.m_nTriggers))) return 0; } if (!(tm = m_sides [nSide].m_nOvlTex)) return 0; tmf = m_sides [nSide].m_nOvlOrient; //tm flags ec = gameData.pig.tex.tMapInfoP [tm].nEffectClip; if (ec < 0) { if (gameData.pig.tex.tMapInfoP [tm].destroyed == -1) return 0; nBitmap = -1; nSwitchType = 0; } else { ecP = gameData.eff.effectP + ec; if (ecP->flags & EF_ONE_SHOT) return 0; nBitmap = ecP->nDestBm; if (nBitmap < 0) return 0; nSwitchType = 1; } //check if it's an animation (monitor) or casts light bmP = gameData.pig.tex.bitmapP + gameData.pig.tex.bmIndexP [tm].index; LoadBitmap (gameData.pig.tex.bmIndexP [tm].index, gameStates.app.bD1Data); //this can be blown up...did we hit it? if (!bForceBlowup) { HitPointUV (nSide, &u, &v, NULL, vHit, 0); //evil: always say face zero bForceBlowup = !PixelTranspType (tm, tmf, m_sides [nSide].m_nFrame, u, v); } if (!bForceBlowup) return 0; if (IsMultiGame && netGame.bIndestructibleLights && !nSwitchType) return 0; //note: this must get called before the texture changes, //because we use the light value of the texture to change //the static light in the CSegment wallP = Wall (nSide); bPermaTrigger = (trigP = Trigger (nSide)) && (trigP->flags & TF_PERMANENT); if (!bPermaTrigger) SubtractLight (Index (), nSide); if (gameData.demo.nState == ND_STATE_RECORDING) NDRecordEffectBlowup (Index (), nSide, vHit); if (nSwitchType) { xDestSize = ecP->xDestSize; vc = ecP->nDestVClip; } else { xDestSize = I2X (20); vc = 3; } /*Object*/CreateExplosion (short (Index ()), vHit, xDestSize, vc); if (nSwitchType) { if ((nSound = gameData.eff.vClipP [vc].nSound) != -1) audio.CreateSegmentSound (nSound, Index (), 0, vHit); if ((nSound = ecP->nSound) != -1) //kill sound audio.DestroySegmentSound (Index (), nSide, nSound); if (!bPermaTrigger && (ecP->nDestEClip != -1) && (gameData.eff.effectP [ecP->nDestEClip].nSegment == -1)) { tEffectClip *newEcP = gameData.eff.effectP + ecP->nDestEClip; int nNewBm = newEcP->changingWallTexture; if (ChangeTextures (-1, nNewBm)) { newEcP->xTimeLeft = EffectFrameTime (newEcP); newEcP->nCurFrame = 0; newEcP->nSegment = Index (); newEcP->nSide = nSide; newEcP->flags |= EF_ONE_SHOT | ecP->flags; newEcP->flags &= ~EF_INITIALIZED; newEcP->nDestBm = ecP->nDestBm; Assert ((nNewBm != 0) && (m_sides [nSide].m_nOvlTex != 0)); m_sides [nSide].m_nOvlTex = nNewBm; //replace with destoyed } } else { Assert ((nBitmap != 0) && (m_sides [nSide].m_nOvlTex != 0)); if (!bPermaTrigger) m_sides [nSide].m_nOvlTex = nBitmap; //replace with destoyed } } else { if (!bPermaTrigger) m_sides [nSide].m_nOvlTex = gameData.pig.tex.tMapInfoP [tm].destroyed; //assume this is a light, and play light sound audio.CreateSegmentSound (SOUND_LIGHT_BLOWNUP, Index (), 0, vHit); } return 1; //blew up! }
bool BaseAI::startTurn() { int count = 0; count = getWallCount(); walls.clear(); walls.resize(count); for(int i = 0; i < count; i++) { walls[i] = Wall(getWalls()+i); } count = getCrateCount(); crates.clear(); crates.resize(count); for(int i = 0; i < count; i++) { crates[i] = Crate(getCrates()+i); } count = getWeaponCount(); weapons.clear(); weapons.resize(count); for(int i = 0; i < count; i++) { weapons[i] = Weapon(getWeapons()+i); } count = getHumanCount(); humans.clear(); humans.resize(count); for(int i = 0; i < count; i++) { humans[i] = Human(getHumans()+i); } count = getZombieCount(); zombies.clear(); zombies.resize(count); for(int i = 0; i < count; i++) { zombies[i] = Zombie(getZombies()+i); } count = getAirstrikeCount(); airstrikes.clear(); airstrikes.resize(count); for(int i = 0; i < count; i++) { airstrikes[i] = Airstrike(getAirstrikes()+i); } count = getSpawnzoneCount(); spawnzones.clear(); spawnzones.resize(count); for(int i = 0; i < count; i++) { spawnzones[i] = Spawnzone(getSpawnzones()+i); } if(turnNum() == 1) { init(); if(!isHuman()) { return true; } } if(isHuman()) { return runHuman(); } else { return runZombie(); } }
int ComWallFrame::action(IDS* main) { int x,y,xo,yo, Y; Kinect::depth_buffer* dframe = main->getDepth(); Kinect* kinect = main->getKinect(); Minotaur* minotaur = main->getMinotaur(); Minotaur::MinotaurState minostate = minotaur->getState(); Point p3d[8][8]; Point avg3d; Point avgbar_flat; int valid; float zvariance, xvariance, yvariance, xSS, ySS, xybar, xzbar, yzbar; float slopeyx, slopezx, slopezy; float yint, zxint, zyint; float resid_yx, resid_zx, resid_zy; uint8_t r,g,b; uint16_t d, d0, d1; float fd; float floor_height = 0; int floor_count = 0; float rx, ry, rz; float sin_ori = sin(minostate.orient); float cos_ori = cos(minostate.orient); float origin_dist; float avg_dist; float orient_yx; uint32_t count, max_count = 0; Wall avg_walls[480/8/WALL_AVG_SIZE][640/8/WALL_AVG_SIZE][WALL_AVG_SIZE][WALL_AVG_SIZE]; bool valid_walls[480/8/WALL_AVG_SIZE][640/8/WALL_AVG_SIZE][WALL_AVG_SIZE][WALL_AVG_SIZE]; int nslope = 480; int nodist = 256; int nodist_half = nodist / 2 + 1; float fft_data[nslope][nodist]; fftwf_complex* fft_out = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*nslope*nodist_half); float avg_slope, avg_yint; int fail_yx_res = 0; int fail_zx_res = 0; int fail_zy_res = 0; int fail_floor_check1 = 0; int fail_floor_check2 = 0; int fail_floor_check3 = 0; int fail_floor_check4 = 0; bool wall_check1, wall_check2, wall_check3; bool floor_check1, floor_check2, floor_check3, floor_check4; if(main->getDepthCount() <= 0) { std::cerr << "MapFrame awaiting depth data" << std::endl; return 1; } for(y = 0; y < 480/8/WALL_AVG_SIZE; y++) for(x = 0; x < 640/8/WALL_AVG_SIZE; x++) for(yo = 0; yo < WALL_AVG_SIZE; yo++) for(xo = 0; xo < WALL_AVG_SIZE; xo++) valid_walls[y][x][yo][xo] = false; for(x = 0; x < nodist; x++) for(y = 0; y < nslope; y++) fft_data[y][x] = fft_data[y][x] = 0; for(y = 0; y < 480/8; y++) { for(x = 0; x < 640/8; x++) { avg3d = {0,0,0}; avg_dist = 0; valid = 0; xybar = 0; for(yo = 0; yo < 8; yo++) { for(xo = 0; xo < 8; xo++) { d0 = (*dframe)[y*8+yo][x*8+xo][0]; d1 = (*dframe)[y*8+yo][x*8+xo][1]; d = d1; d = d << 8 | d0; if(d != 0x07FF && d <= KINECT_CALIB_DOFF) { fd = decode_kinect_dist[d]; avg_dist += fd; rx = kinect->x3d(x,y,xo,yo,fd); ry = kinect->y3d(x,y,xo,yo,fd); rz = kinect->z3d(x,y,xo,yo,fd); p3d[yo][xo].x = rx * cos_ori - ry * sin_ori + minostate.x; p3d[yo][xo].y = rx * sin_ori + ry * cos_ori + minostate.y; p3d[yo][xo].z = rz; avg3d.x += p3d[yo][xo].x; avg3d.y += p3d[yo][xo].y; avg3d.z += p3d[yo][xo].z; valid_points[yo][xo] = true; ++valid; }else valid_points[yo][xo] = false; //p3d[yo][xo].valid = false; } } avg3d.x /= valid; avg3d.y /= valid; avg3d.z /= valid; if(valid <= (8*8)*3/4) { //Not enough data to represent the points r = 0x00; g = 0x00; b = 0x00; }else{ //Calculate statistics for slope calculation zvariance = 0; xvariance = 0; yvariance = 0; xSS = 0, ySS = 0; xybar = 0, xzbar = 0, yzbar = 0; for(yo = 0; yo < 8; yo++) for(xo = 0; xo < 8; xo++) { if(valid_points[yo][xo]) { xvariance += quick_square(p3d[yo][xo].x-avg3d.x); yvariance += quick_square(p3d[yo][xo].y-avg3d.y); zvariance += quick_square(p3d[yo][xo].z-avg3d.z); xSS += quick_square(p3d[yo][xo].x); ySS += quick_square(p3d[yo][xo].y); xybar += p3d[yo][xo].x * p3d[yo][xo].y; xzbar += p3d[yo][xo].x * p3d[yo][xo].z; yzbar += p3d[yo][xo].y * p3d[yo][xo].z; } } xybar /= valid; xzbar /= valid; yzbar /= valid; xSS /= valid; ySS /= valid; slopeyx = (xybar - avg3d.x * avg3d.y) / (xSS - quick_square(avg3d.x)); slopezx = (xzbar - avg3d.x * avg3d.z) / (xSS - quick_square(avg3d.x)); slopezy = (yzbar - avg3d.y * avg3d.z) / (ySS - quick_square(avg3d.y)); yint = avg3d.y - slopeyx * avg3d.x; zxint = avg3d.z - slopezx * avg3d.x; zyint = avg3d.z - slopezy * avg3d.y; resid_yx = 0; resid_zx = 0; resid_zy = 0; for(yo = 0; yo < 8; yo++) for(xo = 0; xo < 8; xo++) if(valid_points[yo][xo]) { resid_yx += quick_square((p3d[yo][xo].y - slopeyx * p3d[yo][xo].x - yint)); resid_zx += quick_square((p3d[yo][xo].z - slopezx * p3d[yo][xo].x - zxint)); resid_zy += quick_square((p3d[yo][xo].z - slopezy * p3d[yo][xo].y - zyint)); } floor_check1 = fabs(atan(slopezx)) < 0.262; floor_check2 = fabs(atan(slopezy)) < 0.262; floor_check3 = resid_zx * 50000 < valid * quick_square(avg_dist/100); floor_check4 = resid_zy * 50000 < valid * quick_square(avg_dist/100); if(floor_check1 && floor_check2 && floor_check3 && floor_check4) { //Floor or ceiling at a constant height from Kinect if(avg3d.z < -800 && avg3d.z > -1600) { r = 0xFF; g = 0xFF; b = 0xFF; floor_height += avg3d.z; floor_count++; }else{ r = 0xFF; g = 0x00; b = 128 + avg3d.z / 12 / 100 * 256; } }else{ //Wall or non-plane //r = std::min<int>(std::max<int>(resid_yx*20,0),255); wall_check1 = resid_yx * 1000 < valid * quick_square(avg_dist/100); if(wall_check1 && !floor_check3 && !floor_check4) { //Using minimum distance to robot point location for hashing, less likely to be out of range. origin_dist = (slopeyx * minostate.x - minostate.y + yint) / sqrt(quick_square(slopeyx)+1); orient_yx = fmod((atan(slopeyx) + PI / 2),PI); fft_data[(int)(orient_yx / PI * nslope / 2)][(int)(origin_dist/100) + nodist/4]++; fft_data[(int)(orient_yx / PI * nslope / 2 + nslope / 2)][(int)(origin_dist/100) + nodist/4]++; avg_walls[y/WALL_AVG_SIZE][x/WALL_AVG_SIZE][y % WALL_AVG_SIZE][x % WALL_AVG_SIZE] = Wall(slopeyx, yint); valid_walls[y/WALL_AVG_SIZE][x/WALL_AVG_SIZE][y % WALL_AVG_SIZE][x % WALL_AVG_SIZE] = true; r = 0; g = 255-std::min<int>(std::max<int>(orient_yx / PI * 256,0),255);//std::min<int>(std::max<int>(yint*20+128,0),255); b = std::min<int>(std::max<int>(orient_yx / PI * 256,0),255); }else{ r = g = b = 0x80; if(!wall_check1) fail_yx_res++; if(!floor_check1) fail_floor_check1++; if(!floor_check2) fail_floor_check2++; if(!floor_check3) fail_floor_check3++; if(!floor_check4) fail_floor_check4++; } } } /* for(yo = 0; yo < 8; yo++) for(xo = 0; xo < 8; xo++) { frame[y*8+yo][x*8+xo][0] = r; frame[y*8+yo][x*8+xo][1] = g; frame[y*8+yo][x*8+xo][2] = b; }*/ } } //std::cerr << fail_yx_res << " " << fail_floor_check1 << " " << fail_floor_check2 << " " << fail_floor_check3 << " " << fail_floor_check4 << std::endl; fftwf_plan fft = fftwf_plan_dft_r2c_2d(nslope, nodist, &(fft_data[0][0]), fft_out, FFTW_ESTIMATE); fftwf_execute(fft); fftwf_destroy_plan(fft); float mag; float stddev_x, stddev_y; float var_x, var_y; float mean_x, mean_y; float filter_x, filter_y; float coeff_x, coeff_y; stddev_x = 2; stddev_y = 2; mean_x = 0; mean_y = nslope / 2; var_x = quick_square(x); var_y = quick_square(y); coeff_x = 1 / (stddev_x * sqrt(2*PI)) / 0.4; coeff_y = 1 / (stddev_y * sqrt(2*PI)) / 0.4; for(y = 0; y < nslope; y++) { Y = (nslope / 2 + y) % nslope; // filter_y = coeff_y * exp(-1 * quick_square(mean_y - y) / (2*var_y)); for(x = 0; x < nodist_half; x++) { /*filter_x = fabs(coeff_x * exp(-1 * quick_square(mean_x - x) / (2*var_x))); fft_out[Y*nodist_half+x][0] *= filter_x * filter_y; fft_out[Y*nodist_half+x][1] *= filter_x * filter_y; continue;*/ if(abs(y - nslope / 2) >= 8 || x >= 8) { fft_out[Y*nodist_half+x][0] = 0; fft_out[Y*nodist_half+x][1] = 0; }else{ mag = sqrt(quick_square(fft_out[Y*nodist_half+x][0]) + quick_square(fft_out[Y*nodist_half+x][1])); /* frame[y][x][0] = mag / fft_out[0][0]*256; frame[y][x][1] = mag / fft_out[0][0]*256; frame[y][x][2] = mag / fft_out[0][0]*256;*/ } } } fft = fftwf_plan_dft_c2r_2d(nslope, nodist, fft_out, &(fft_data[0][0]), FFTW_ESTIMATE); fftwf_execute(fft); fftwf_destroy_plan(fft); float max_mag = 0, maxgrad; int maxgradid; std::set< Wall > walls; std::set< Wall >::iterator it_walls; for(y = 0; y < nslope; y++) { for(x = 0; x < nodist; x++) { mag = fft_data[y][x]; if(mag > max_mag) max_mag = mag; } } for(y = 0; y < nslope; y++) { for(x = 0; x < nodist; x++) { maxgrad = 0; maxgradid = 0; for(yo = -1; yo <= 1; yo++) for(xo = -1; xo <= 1; xo++) if(fft_data[y + yo][x + xo] > maxgrad) { maxgrad = fft_data[y + yo][x + xo]; maxgradid = yo * 3 + xo; } mag = std::max<float>(fft_data[y][x],0); if(maxgradid != 0) { frame[y][x][0] = mag / max_mag * 255; frame[y][x][1] = mag / max_mag * 255; frame[y][x][2] = mag / max_mag * 255; }else if(abs(y - nslope/2) <= nslope/4){ frame[y][x][0] = mag / max_mag * 255; frame[y][x][1] = 0; frame[y][x][2] = 0; if(mag > 125893) //10 ** 5.1 walls.insert(Wall(fmod((float)y / nslope * 2 * PI,PI) - PI / 2,(float)x - nodist / 4.0)); } } } for(it_walls = walls.begin(); it_walls != walls.end(); it_walls++) { std::cerr << " " << it_walls->orient / PI; std::cerr << " " << it_walls->yint; std::cerr << " " << log10(max_mag); std::cerr << std::endl; } std::cerr << std::endl; fftwf_free(fft_out); /* float prev_count = fft_data[255] > 3000 ? fft_data[255] : -1; float prev_count_2 = fft_data[254] > 3000 ? fft_data[254] : -1; for(y = 0; y < 256; y++) { if(fft_data[y] > 3000) { if(prev_count != -1 && prev_count > fft_data[y] && prev_count_2 < prev_count && prev_count_2 != -1) std::cerr << (y-128)*(1/81.487330864) << "\t" << fft_data[y] << std::endl; prev_count_2 = prev_count; prev_count = fft_data[y]; }else{ prev_count = -1; } } std::cerr << std::endl;*/ return 0; }
void buildEnvironment() { /* *----*----*--------* | | | | | A . | D | | | | | *----* C | | | | *--- --* | B . . | | | . E | *----*-------------* */ // Points env.addPoint(core::Pointf(0, 0)); // 0 env.addPoint(core::Pointf(0, 10)); // 1 env.addPoint(core::Pointf(10, 10)); // 2 env.addPoint(core::Pointf(10, 0)); // 3 env.addPoint(core::Pointf(5, 0)); // 4 env.addPoint(core::Pointf(10, -10)); // 5 env.addPoint(core::Pointf(0, -10)); // 6 env.addPoint(core::Pointf(-5, -10)); // 7 env.addPoint(core::Pointf(-5, -7)); // 8 env.addPoint(core::Pointf(-10, -10)); // 9 env.addPoint(core::Pointf(-10, 0)); // 10 env.addPoint(core::Pointf(-5, 0)); // 11 env.addPoint(core::Pointf(-5, -3)); // 12 env.addPoint(core::Pointf(-5, 3)); // 13 env.addPoint(core::Pointf(-10, 10)); // 14 env.addPoint(core::Pointf(-5, 10)); // 15 env.addPoint(core::Pointf(-5, 7)); // 16 env.addPoint(core::Pointf(3, 0)); // 17 // Walls env.addWall(Wall (14, 10, 0.0)); // 0 env.addWall(Wall (15, 14, 0.0)); // 1 env.addWall(Wall (1, 15, 0.0)); // 2 env.addWall(Wall (2, 1, 0.0)); // 3 env.addWall(Wall (3, 2, 0.0)); // 4 env.addWall(Wall (5, 3, 0.0)); // 5 env.addWall(Wall (6, 5, 0.0)); // 6 env.addWall(Wall (7, 6, 0.0)); // 7 env.addWall(Wall (9, 7, 0.0)); // 8 env.addWall(Wall (10, 9, 0.0)); // 9 env.addWall(Wall (10, 11, 0.0)); // 10 env.addWall(Wall (15, 16, 0.0)); // 11 env.addWall(Wall (13, 11, 0.0)); // 12 env.addWall(Wall (11, 12, 0.0)); // 13 env.addWall(Wall (8, 7, 0.0)); // 14 env.addWall(Wall (0, 1, 0.0)); // 15 env.addWall(Wall (17, 0, 0.0)); // 16 env.addWall(Wall (3, 4, 0.0)); // 17 env.addWall(Wall (8, 12, INFINITY)); // 18 env.addWall(Wall (0, 6, INFINITY)); // 19 env.addWall(Wall (17, 4, INFINITY)); // 20 env.addWall(Wall (16, 13, INFINITY)); // 21 // Rooms Room rA, rB, rC, rD, rE; rA.setIdx(0); rB.setIdx(1); rC.setIdx(2); rD.setIdx(3); rE.setIdx(4); // Room A rA.addWall(0, 1); rA.addWall(1, 1); rA.addWall(11, -1); rA.addWall(21, -1); rA.addWall(12, -1); rA.addWall(10, 1); env.addRoom(rA); // Room B rB.addWall(8, 1); rB.addWall(14, -1); rB.addWall(18, 1); rB.addWall(13, -1); rB.addWall(10, -1); rB.addWall(9, 1); env.addRoom(rB); // Room C rC.addWall(2, 1); rC.addWall(11, 1); rC.addWall(21, 1); rC.addWall(12, 1); rC.addWall(13, 1); rC.addWall(18, -1); rC.addWall(14, 1); rC.addWall(7, 1); rC.addWall(19, -1); rC.addWall(15, 1); env.addRoom(rC); // Room D rD.addWall(3, 1); rD.addWall(20, 1); rD.addWall(16, -1); rD.addWall(15, -1); rD.addWall(17, -1); rD.addWall(4, 1); env.addRoom(rD); // Room E rE.addWall(17, 1); rE.addWall(20, -1); rE.addWall(16, 1); rE.addWall(19, 1); rE.addWall(6, 1); rE.addWall(5, 1); env.addRoom(rE); Source src(rD, core::Pointf(5, 5)); env.setSource(src); std::vector<std::vector<Environment::GraphNode> > adj; adj.resize(env.getRooms().size()); env.buildAdjacencyGraph(adj); env.DFS(adj, src.getInsideRoom().getRoomIdx()); env.filterValidPaths(2); env.getValidPaths()->getNumberOfLeaves(env.getValidPaths()->_root, numberOfPaths); env.getValidPaths()->getDepth(env.getValidPaths()->_root, maximumDepth, 0); std::cout << numberOfPaths << " valid paths found" << std::endl; std::cout << "Depth: " << maximumDepth << std::endl; }
static void make_new_wall(GameWorld::WallCollection& walls, const Config::WallConfig& wallConfig) { walls.push_back(Wall(wallConfig.bounds, wallConfig.color)); }
void CalcVolume::OnPointDetected(int nAngle, int nRange, int nSignal, DWORD dwTicks, int npacket) { if(GetState() != SLMstate_scanning) return; static int rendercount=0; static int nRangeOld=0; CriticalData crdata_save; EnterCriticalSection(&lock); crdata_save=crdata; LeaveCriticalSection(&lock); crdata_save.count.nu=npacket; BOOL er=FALSE; if(nAngle==m_nLastAngle || nAngle < cv.vol.angmin || nAngle > cv.vol.angmax) er=!er; double dj; if(!er) { if(cv.flag.rbound) { if(nRange<cv.vol.rmin||nRange>cv.vol.rmax) nRange=nRangeOld; else nRangeOld=nRange; } int angprev=nAngle-deltaprev; if( nAngle > cv.vol.angmin && angprev >= cv.vol.angmin && m_nLastAngle != angprev) { crdata_save.count.nleave++; if(m_fv) fprintf(m_fv,"missing: angle=%d,old=%d\n",nAngle,m_nLastAngle); // Debug: выводим какие углы тер¤ютс¤ TRACE("missig m_nLastAngle = %d != angprev = %d \n",m_nLastAngle,angprev); } if(nAngle < m_nLastAngle) { if(pnow!=rl[0]) { pnow=rl[0]; pold=rl[1]; } else { pnow=rl[1]; pold=rl[0]; } if(cv.flag.render==cv.RENDER_3D&&cv.history.render) { rendercount++; if(rendercount>=cv.history.render) rendercount=0; } } crdata_save.slm.u=(double)nAngle/100.; if(cv.flag.virt) crdata_save.slm.r=Wall((double)nRange/100.,crdata_save.slm.u); else crdata_save.slm.r=(double)nRange/100.; pnow[nAngle].r=crdata_save.slm.r; pnow[nAngle].s=nSignal; pnow[nAngle].t=dwTicks; pnow[nAngle].l=crdata_save.lm.l;//GetL(dwTicks); //pnow[nAngle].l=GetL(dwTicks); //if(m_fv) fprintf(m_fv,"%6.2f,%0d,%6.2f\n",crdata_save.slm.r,nAngle,crdata_save.lm.l); dj=((double)nAngle*0.01-90.)*SLM_PI/180.; pnow[nAngle].h=cv.vol.Height-pnow[nAngle].r*sin(dj); if( nAngle > cv.vol.angmin && angprev >= cv.vol.angmin) Calc(nAngle,&crdata_save); m_nLastAngle=nAngle; } EnterCriticalSection(&lock); if(!er) { if(cv.flag.render==cv.RENDER_3D&&cv.history.render) cr_prender[nAngle][rendercount]=pnow[nAngle]; if(cv.flag.render==cv.RENDER_2D) { double Width = cv.vol.Wleft+cv.vol.Wright; double Length = cv.vol.Lstart-cv.vol.Lend; int y=(double)cv.render.y2d*(cv.vol.Wleft-pnow[nAngle].r*cos(dj))/Width; int x=(double)cv.render.x2d*(cv.vol.Lstart-pnow[nAngle].l)/Length; if(x<0){ x=0; } else if(x>cv.render.x2d-1) x=cv.render.x2d-1; if(y<0){ y=0; } else if(y>cv.render.y2d-1) y=cv.render.y2d-1; cr_index=x; if(cv.render.havarage){ cr_points_count[y][x]++; // ƒобавл¤етс¤ нова¤ точка cr_hcolor[y][x] = (cr_hcolor[y][x]*(cr_points_count[y][x]-1)+pnow[nAngle].h)/cr_points_count[y][x]; } else cr_hcolor[y][x] = pnow[nAngle].h; } } crdata=crdata_save; LeaveCriticalSection(&lock); }