Vector2u Picture::getSize() const { if (m_Loaded) return Vector2u(m_Texture->getSize().x, m_Texture->getSize().y); else return Vector2u(0, 0); }
void RoomScene::OnEvent(UiEvent event, void* data) { if (event == UiEvent::ONRECEIVEROOM) { this->roomsButtons_.push_back(new AirButton(this->resourceMediator_->getPictureById(4), this->resourceMediator_->getPictureById(5), Vector2u(371, 220 + this->posLastButtonRoom_), Vector2u(559, 30), this->resourceMediator_->getFontById(0))); this->roomsButtons_[this->roomsButtons_.size() - 1]->setText((char *) data, sf::Color::Black, 15); this->roomsButtons_[this->roomsButtons_.size() - 1]->onClickHandler(this); if (this->posLastButtonRoom_ >= this->maxPosLastButtonRoom_) { this->posLastButtonRoom_ = 0; this->nbPageRoom_++; } else { this->posLastButtonRoom_ += 31; if (this->roomsButtons_.size() < 10) this->AddEntity(this->roomsButtons_[this->roomsButtons_.size() - 1]); } } else if (event == UiEvent::ONRETJOINROOM) { window_->SetScene(scenes_->getSceneByName("WaitScene")); } else if (event == UiEvent::ONRECEIVEWRONGROOM) { this->roomsButtons_.push_back(new AirButton(this->resourceMediator_->getPictureById(4), this->resourceMediator_->getPictureById(5), Vector2u(371, 220 + this->posLastButtonRoom_), Vector2u(559, 30), this->resourceMediator_->getFontById(0))); this->roomsButtons_[this->roomsButtons_.size() - 1]->setText((char *) data, sf::Color::Red, 15); this->roomsButtons_[this->roomsButtons_.size() - 1]->onClickHandler(this); this->roomsButtons_[this->roomsButtons_.size() - 1]->setEnable(false); if (this->posLastButtonRoom_ >= this->maxPosLastButtonRoom_) { this->posLastButtonRoom_ = 0; this->nbPageRoom_++; } else { this->posLastButtonRoom_ += 31; if (this->roomsButtons_.size() < 10) this->AddEntity(this->roomsButtons_[this->roomsButtons_.size() - 1]); } } else if (event == UiEvent::ONRETCREATEROOMERROR) { this->isNotifyDisplay_ = true; this->textNotify_->setTextString("Room creation error"); this->AddEntity(this->textNotify_); } else if (event == UiEvent::DISCONNECT) { window_->SetScene(scenes_->getSceneByName("ConnectionScene")); } }
Vector2u Checkbox::getSize() const { if (m_Loaded) return Vector2u(m_TextureUnchecked->getSize().x, m_TextureUnchecked->getSize().y); else return Vector2u(0, 0); }
void Frame::reset_crop_window() { impl->m_crop_window = AABB2u( Vector2u(0, 0), Vector2u(impl->m_frame_width - 1, impl->m_frame_height - 1)); m_params.strings().remove("crop_window"); }
RoomScene::RoomScene(Ui *ui, AirWindow *window, ResourceMediator *resourceMediator, SceneMediator* scenes) { this->createRoomButton_ = NULL; this->refreshButton_ = NULL; this->cancelButton_ = NULL; this->okButton_ = NULL; this->ui_ = ui; this->resourceMediator_ = resourceMediator; window_ = window; scenes_ = scenes; AirText* title = new AirText(resourceMediator->getFontById(0), "R-Wars - Room", Vector2u(430, 110), sf::Color::Yellow, 50); this->timerNotify_ = 0; this->isNotifyDisplay_ = false; this->textNotify_ = new AirText(this->resourceMediator_->getFontById(0), "", Vector2u(10, 700), sf::Color::Red, 15); this->initRoomScreen(); AirParticuleGenerator * particuleGenerator = new AirParticuleGenerator(Vector2f(-2, 0), 0.1, // vector start Vector2f(-2, 0), 0.1, // vector end sf::Color::White, 0, sf::Color::White, 0, 2, 2, // size 20000, 0, // life 20, // nb particules per secs Vector2u(1280 + 360, 360), // pos particules 360); // precision pos AirParticuleGenerator * particuleGenerator2 = new AirParticuleGenerator(Vector2f(-3, 0), 1, // vector start Vector2f(-3, 0), 1, // vector end sf::Color::White, 0, sf::Color::White, 0, 2, 2, // size 20000, 0, // life 2, // nb particules per secs Vector2u(1280 + 360, 360), 360); this->posPageRoom_ = 0; this->nbPageRoom_ = 1; this->frameUpPress_ = 0; this->frameDownPress_ = 0; this->posLastButtonRoom_ = 0; this->maxPosLastButtonRoom_ = 8 * 31; this->AddEntity(title); this->AddParticules(particuleGenerator); this->AddParticules(particuleGenerator2); }
Vector2u Panel::getSize() const { if (m_Loaded == true) return m_RenderTexture->getSize(); else return Vector2u(0, 0); }
void CreateWaterMesh(unsigned int size, Vector3f scle, Mesh& outM) { Vector3f offset(size * -0.5f, size * -0.5f, 0.0f); Array2D<float> terrainHeight(size, size, 0.0f); //Just create a flat terrain and let it do the math. Terrain terr(Vector2u(size, size)); terr.SetHeightmap(terrainHeight); std::vector<WaterVertex> verts; std::vector<unsigned int> indices; terr.GenerateTrianglesFull<WaterVertex>(verts, indices, [](WaterVertex& v) { return &v.Pos; }, [](WaterVertex& v) { return &v.TexCoord; }); //Convert the terrain vertices into water vertices. for (unsigned int i = 0; i < verts.size(); ++i) { verts[i].Pos = verts[i].Pos.ComponentProduct(scle) + offset; } //Upload the mesh data into vertex/index buffers. outM.SubMeshes.push_back(MeshData(false, PT_TRIANGLE_LIST)); MeshData& mDat = outM.SubMeshes[0]; mDat.SetVertexData(verts, MeshData::BUF_STATIC, WaterVertex::GetVertexAttributes()); mDat.SetIndexData(indices, MeshData::BUF_STATIC); }
void CreateWaterMesh(unsigned int size, Mesh& outM) { //Just create a flat terrain and let it do the math. Terrain terr(Vector2u(size, size)); std::vector<WaterVertex> verts; std::vector<unsigned int> indices; { Array2D<float> heightmap(size, size, 0.0f); terr.SetHeightmap(heightmap); terr.GenerateTrianglesFull<WaterVertex>( verts, indices, [](WaterVertex& v) { return &v.Pos; }, [](WaterVertex& v) { return &v.TexCoord; }); } //Convert the terrain vertices into water vertices. float invSize = 1.0f / (float)size; for (unsigned int i = 0; i < verts.size(); ++i) { verts[i].Pos = Vector3f(verts[i].Pos.x * invSize, verts[i].Pos.y * invSize, verts[i].Pos.z); } //Upload the mesh data into vertex/index buffers. outM.SetVertexData(verts, Mesh::BUF_STATIC, WaterVertex::GetVertexAttributes()); outM.SetIndexData(indices, Mesh::BUF_STATIC); }
// Static Vector2u SystemGUI::getDesktopSize() { HDC screenDC = GetDC(NULL); int w = GetDeviceCaps(screenDC, HORZRES); int h = GetDeviceCaps(screenDC, VERTRES); ReleaseDC(NULL, screenDC); return Vector2u(w,h); }
void Game::initialize() { getWindow()->setSize(Vector2u(SMASHBROS_WINDOWWIDTH, SMASHBROS_WINDOWHEIGHT)); getWindow()->getView()->setSize(SMASHBROS_WINDOWWIDTH, SMASHBROS_WINDOWHEIGHT); getWindow()->getView()->setLetterboxed(true); setFPS(60); menuLoad = new MenuLoad(*getWindow(), "assets/menu"); moduleLoad = new ModuleLoad(*getWindow(), "assets/characters", "assets/stages"); smashData = new SmashData(getWindow(), menuLoad, moduleLoad); }
Box2D GUITexture::GetBounds(void) const { Vector2f dims = GetScale(); if (tex != 0) { if (rotation == 0.0f) { dims = ToV2f(Vector2u(tex->GetWidth(), tex->GetHeight())); dims.MultiplyComponents(GetScale()); } else { float diameter = 2.0f * ToV2f(Vector2u(tex->GetWidth(), tex->GetHeight())).Length(); dims = Vector2f(diameter, diameter); } } return Box2D(Vector2f(), dims); }
void PlayerViewport::SetScale(Vector2f newScale) { //Instead of scaling this item, scale up the texture itself. Vector2f targetSize = newScale.ComponentProduct(ToV2f(Vector2u(worldRendColor.GetWidth(), worldRendColor.GetHeight()))); Vector2u sizeU = ToV2u(targetSize.Ceil()); worldRendColor.ClearData(sizeU.x, sizeU.y); worldRendTarg.UpdateSize(); DidBoundsChange = true; }
void Game::initialize() { setFPS(30); getWindow()->getView()->setSize(426, 240); getWindow()->getView()->setLetterboxed(true); getWindow()->getView()->setMaintainResolution(true); Vector2d viewSize = getWindow()->getView()->getSize(); cameraCenter.x = viewSize.x/2; cameraCenter.y = viewSize.y/2; getWindow()->setSize(Vector2u(800, 600)); }
int main() { AirWindow win("test",Vector2u(900,700)); win.GetWindows().setActive(false); win.GetWindows().setFramerateLimit(60); win.SetScene(new MainMenu()); IAirMusic *music = new AirMusic("ressource/Musique_traditionnelle_japonaise_quatuor.ogg"); win.AddMusic(music); while (win.IsOpen()) { win.Update(); } win.RemoveMusic(music); }
void GUILevelPathing::OnRoomsChanged(void) { LevelInfo::UIntBox bnds = editor.LevelData.GetBounds(); bnds.Min = Vector2u(); editor.LevelData.GenerateFullLevel(levelGrid, bnds); roomsToPath = editor.LevelData.Rooms.size(); roomsToNav = roomsToPath; nStepsFromRoomToTeamBases.resize(editor.LevelData.Rooms.size(), std::array<float, 2>()); roomNormalizedDistsToTeamBases.resize(editor.LevelData.Rooms.size(), std::array<float, 2>()); editor.LevelData.GetConnections(graph); }
ScoreScene::ScoreScene(Ui *ui, AirWindow *window, ResourceMediator *resourceMediator, SceneMediator* scenes) { ui_ = ui; window_ = window; this->resourceMediator_ = resourceMediator; scenes_ = scenes; AirText* title = new AirText(resourceMediator->getFontById(0), "R-Wars - Score", Vector2u(430, 110), sf::Color::Yellow, 50); AirSprite* frame = new AirSprite(resourceMediator->getPictureById(1), Vector2u(350, 200), Vector2u(600, 300)); AirParticuleGenerator * particuleGenerator = new AirParticuleGenerator(Vector2f(-2, 0), 0.1, // vector start Vector2f(-2, 0), 0.1, // vector end sf::Color::White, 0, sf::Color::White, 0, // color 2, 2, // size 20000, 0, // life 20, // nb particules per secs Vector2u(1280 + 360, 360), // pos particules 360); // precision pos AirParticuleGenerator * particuleGenerator2 = new AirParticuleGenerator(Vector2f(-3, 0), 1, // vector start Vector2f(-3, 0), 1, // vector end sf::Color::White, 0, sf::Color::White, 0, // color 2, 2, // size 20000, 0, // life 2, // nb particules per secs Vector2u(1280 + 360, 360), // pos particules 360); AirText* gameOverText = new AirText(resourceMediator->getFontById(0), "Game Over", Vector2u(550, 220), sf::Color::Black, 30); AirText* scoreText = new AirText(resourceMediator->getFontById(0), "Your Score is ", Vector2u(500, 350), sf::Color::Black, 20); this->finalScore_ = new AirText(resourceMediator->getFontById(0), "0", Vector2u(670, 350), sf::Color::Yellow, 20); this->AddEntity(frame); this->AddParticules(particuleGenerator); this->AddParticules(particuleGenerator2); this->AddEntity(title); this->AddEntity(gameOverText); this->AddEntity(scoreText); }
CodeEditor::CodeEditor() { //TODO: No hard coded values. mPos = Vector2u(4, 42); mSize = Vector2u(10, 10); getPreferences(); mCurrentLine = 0; mMarkLine = 0; mMode = Edit; Text text("", *Preferences::instance()->getFont(), mFontSize); text.setDoMultiColor(false); text.setColor(mTextColor); text.setPosition(mPos.x + mLineNumberAreaWidth, mPos.y); mText.push_back(text); mClock = Clock(); addLineNumber(); mLineIndex = 0; mUpperBound = 0; mMarkIndex = 0; mCode = "Hello"; mFilename = ""; mWorkingDirectory = ""; frames = 0; timeNow = mClock.getCurrentTimeInMilliseconds() - 1000; mFirstMarkSet = false; }
void RoomScene::initRoomScreen() { this->roomFrame_ = new AirSprite(this->resourceMediator_->getPictureById(1), Vector2u(350, 200), Vector2u(600, 340)); this->refreshButton_ = new AirButton(this->resourceMediator_->getPictureById(2), this->resourceMediator_->getPictureById(3), Vector2u(371, 220 + 9 * 31), Vector2u(559 / 3, 30), this->resourceMediator_->getFontById(0)); this->refreshButton_->setText("Refresh", sf::Color::Black, 15); this->refreshButton_->onClickHandler(this); this->createRoomButton_ = new AirButton(this->resourceMediator_->getPictureById(2), this->resourceMediator_->getPictureById(3), Vector2u(371 + (559 / 3 * 2), 220 + 9 * 31), Vector2u(559 / 3, 30), this->resourceMediator_->getFontById(0)); this->createRoomButton_->setText("Create", sf::Color::Black, 15); this->createRoomButton_->onClickHandler(this); this->AddEntity(this->roomFrame_); this->AddEntity(this->refreshButton_); this->AddEntity(this->createRoomButton_); }
void Race::HandlePlayerOnPlayerCollisions(){ for (unsigned i=0; i<Player.size()-1;i++) { for (unsigned j=i+1; j<Player.size();j++) { if (Player[i].DeathSwitch==1 || Player[j].DeathSwitch==1) continue; bool StillCorrecting=1; unsigned Attempts=0; while (StillCorrecting){ StillCorrecting=0; vector<Vector2d> Bounding1=Player[i].Bounding; for (unsigned k=0; k<Bounding1.size();k++) { Bounding1[k]=RotateVector(Bounding1[k],Player[i].Rotation); Bounding1[k]+=Player[i].Position; } vector<Vector2d> Bounding2=Player[j].Bounding; for (unsigned k=0; k<Bounding2.size();k++) { Bounding2[k]=RotateVector(Bounding2[k],Player[j].Rotation); Bounding2[k]+=Player[j].Position; } bool CornerPoly=0; Vector2u CornerSide=Vector2u(); Vector2d Direction=Vector2d(); double Overlap=0; bool DoubleFlag=0; if(InPolygon(Bounding1, Bounding2, CornerPoly, CornerSide, Direction,Overlap,DoubleFlag)) { vector<vector<Vector2d>> Bounding={Bounding1,Bounding2}; Vector2d CollisionPos=Bounding[CornerPoly][CornerSide.x]; HandleSinglePlayerCollision({&Player[i],&Player[j]},Bounding, CornerPoly,CollisionPos,Direction,Overlap,DoubleFlag,Attempts); Attempts++; StillCorrecting=1; } if(Attempts>=5) { //Player[i].DeathSwitch=1; StillCorrecting=0; } } } } }
void RoomScene::initCreateRoomScreen() { this->roomCreationFrame_ = new AirSprite(this->resourceMediator_->getPictureById(1), Vector2u(300, 200 + 100), Vector2u(700, 180)); this->roomCreation_ = new AirText(this->resourceMediator_->getFontById(0), "Room Title", Vector2u(371, 220 + 3 * 31), sf::Color::Black, 15); this->okButton_ = new AirButton(this->resourceMediator_->getPictureById(2), this->resourceMediator_->getPictureById(3), Vector2u(371, 220 + 7 * 31), Vector2u(559 / 3, 30), this->resourceMediator_->getFontById(0)); this->okButton_->setText("Ok", sf::Color::Black, 15); this->okButton_->onClickHandler(this); this->cancelButton_ = new AirButton(this->resourceMediator_->getPictureById(2), this->resourceMediator_->getPictureById(3), Vector2u(371 + (559 / 3 * 2), 220 + 7 * 31), Vector2u(559 / 3, 30), this->resourceMediator_->getFontById(0)); this->cancelButton_->setText("Cancel", sf::Color::Black, 15); this->cancelButton_->onClickHandler(this); this->newRoomTitle_ = new AirTextBox(this->resourceMediator_->getPictureById(0), Vector2u(371, 220 + 4 * 31), Vector2u(559, 30), this->resourceMediator_->getFontById(0)); this->newRoomTitle_->setText("", sf::Color::Black, 15); for (size_t i = 0; i < this->roomsButtons_.size(); i++) this->roomsButtons_[i]->setEnable(false); this->AddEntity(this->roomCreationFrame_); this->AddEntity(this->roomCreation_); this->AddEntity(this->okButton_); this->AddEntity(this->cancelButton_); this->AddEntity(this->newRoomTitle_); }
void Window::setSize(uint32 width, uint32 height) { setSize(Vector2u(width, height)); }
Vector2u Window::getSize() const { return m_impl ? m_impl->getSize() : Vector2u(); }
void GUILevelPathing::CustomUpdate(float elapsedTime, Vector2f relativeMouse) { LevelInfo& lvl = editor.LevelData; if (!UpdatePathing) { return; } //If rooms need to have their pathing info updated, pick one of them and update it. if (roomsToNav > 0) { #pragma region Calculate "Average Length" for a room assert(roomsToNav <= lvl.Rooms.size()); //Figure out the average path length to pass through the room. LevelInfo::RoomData& room = lvl.Rooms[roomsToNav - 1]; LevelInfo::UIntBox rmBnds = lvl.GetBounds(roomsToNav - 1); Array2D<BlockTypes> tempRoom(room.Walls.GetWidth(), room.Walls.GetHeight()); tempRoom.Fill(levelGrid, -ToV2i(room.MinCornerPos)); //Get a list of all open end-points of the block. std::vector<Vector2u> openSpaces; openSpaces.reserve((2 * tempRoom.GetWidth()) + (2 * tempRoom.GetHeight())); for (unsigned int x = 0; x < tempRoom.GetWidth(); ++x) { if (tempRoom[Vector2u(x, 0)] == BT_NONE) { openSpaces.push_back(Vector2u(x, 0)); } if (tempRoom[Vector2u(x, tempRoom.GetHeight() - 1)] == BT_NONE) { openSpaces.push_back(Vector2u(x, tempRoom.GetHeight() - 1)); } } for (unsigned int y = 0; y < tempRoom.GetHeight(); ++y) { if (tempRoom[Vector2u(0, y)] == BT_NONE) { openSpaces.push_back(Vector2u(0, y)); } if (tempRoom[Vector2u(tempRoom.GetWidth() - 1, y)] == BT_NONE) { openSpaces.push_back(Vector2u(tempRoom.GetWidth() - 1, y)); } } //Get all combinations of endpoints along the edge of the room. std::vector<Vector4u> openSpacePairs; openSpacePairs.reserve(openSpacePairs.size() * openSpacePairs.size()); for (unsigned int i = 0; i < openSpaces.size(); ++i) { for (unsigned int j = i + 1; j < openSpaces.size(); ++j) { openSpacePairs.push_back(Vector4u(openSpaces[i].x, openSpaces[i].y, openSpaces[j].x, openSpaces[j].y)); } } std::random_shuffle(openSpacePairs.begin(), openSpacePairs.end()); //Trim down the number of pairs to a reasonable size. const unsigned int MAX_PAIRS = 30; if (openSpacePairs.size() > MAX_PAIRS) { openSpacePairs.resize(MAX_PAIRS); } //Now go through every pair and get the average path length. unsigned int totalSteps = 0; unsigned int nPaths = 0; LevelGraph graph(tempRoom); LevelGraphPather pather(&graph); GraphSearchGoal<LevelNode> goal = GraphSearchGoal<LevelNode>(LevelNode(Vector2u())); std::vector<LevelNode> dummyPath; float dummyTraverseCost, dummySearchCost; for (unsigned int i = 0; i < openSpacePairs.size(); ++i) { Vector2u start(openSpacePairs[i].x, openSpacePairs[i].y), end(openSpacePairs[i].z, openSpacePairs[i].w); dummyPath.clear(); goal.SpecificEnd.SetValue(end); if (pather.Search(start, goal, dummyTraverseCost, dummySearchCost, dummyPath)) { totalSteps += dummyPath.size(); nPaths += 1; } } if (nPaths == 0) { room.AverageLength = 0.0f; } else { room.AverageLength = (float)totalSteps / (float)nPaths; } #pragma endregion roomsToNav -= 1; } else if (roomsToPath > 0) { assert(lvl.Rooms.size() >= roomsToPath); //Path from the room to the team bases. path.clear(); for (unsigned int i = 0; i < 2; ++i) { unsigned int teamIndex = (i == 0 ? lvl.Team1Base : lvl.Team2Base); LevelInfo::RoomData& room = lvl.Rooms[roomsToPath - 1]; LevelInfo::UIntBox rmBnds = lvl.GetBounds(roomsToPath - 1); RoomNode startNode(&room); LevelInfo::RoomData& goalRm = lvl.Rooms[teamIndex]; LevelInfo::UIntBox goalBnds = lvl.GetBounds(teamIndex); GraphSearchGoal<RoomNode> goal = GraphSearchGoal<RoomNode>(RoomNode(&goalRm)); //The pather may fail if a room isn't connected to anything. float& nSteps = nStepsFromRoomToTeamBases[roomsToPath - 1][i]; float dummyTraverseCost, dummySearchCost; if (pather.Search(startNode, goal, dummyTraverseCost, dummySearchCost, path)) { nSteps = 0.0f; for (unsigned int j = 0; j < path.size(); ++j) { nSteps += path[j].Room->AverageLength; } } else { nSteps = Mathf::NaN; } path.clear(); } roomsToPath -= 1; //If we've finally calculated pathing info for all the rooms, finalize pathing data. if (roomsToPath == 0) { //Get the max possible distance from any room to each team base. float maxDists[2] = { -1.0f, -1.0f }; for (unsigned int i = 0; i < nStepsFromRoomToTeamBases.size(); ++i) { const std::array<float, 2>& vals = nStepsFromRoomToTeamBases[i]; if (!Mathf::IsNaN(vals[0])) { maxDists[0] = Mathf::Max(maxDists[0], vals[0]); } if (!Mathf::IsNaN(vals[1])) { maxDists[1] = Mathf::Max(maxDists[1], vals[1]); } } //Get each room's distance to each base, from 0 to 1. for (unsigned int i = 0; i < nStepsFromRoomToTeamBases.size(); ++i) { roomNormalizedDistsToTeamBases[i][0] = Mathf::Min(1.0f, nStepsFromRoomToTeamBases[i][0] / maxDists[0]); roomNormalizedDistsToTeamBases[i][1] = Mathf::Min(1.0f, nStepsFromRoomToTeamBases[i][1] / maxDists[1]); } } } }
Vector2u Race::getNearestValidSquare(unsigned PlayerNumber){ Vector2u Dim=track.getDim(); vector<double> norm(Dim.x*Dim.y,0); Vector2d Position=Player[PlayerNumber].PositionBeforeDeath; for (unsigned k=0; k<Dim.x*Dim.y;++k) { unsigned k1= k % Dim.x; unsigned k2= k / Dim.x; norm[k]=sqrt(pow(k1+0.5-Position.x,2)+pow(k2+0.5-Position.y,2)); } vector<int> index(norm.size(), 0); for (unsigned i = 0 ; i != index.size() ; i++) { index[i] = i; } sort(index.begin(), index.end(),[&](const int& a, const int& b) {return (norm[a] < norm[b]);}); unsigned j=0; bool SquareValid=false; bool CarCollision=false; vector<PROPERTIES> InvalidTiles={FALL,WALL}; while (SquareValid==false || CarCollision==true) { CarCollision=false; SquareValid=true; unsigned k1=index[j]%Dim.x; unsigned k2=index[j]/Dim.x; Tile* CurrentTile=track.getTile(k1,k2); Detect Detection=CurrentTile->Detection; for (unsigned i=0; i<InvalidTiles.size(); i++) { if (Detection.x.count(InvalidTiles[i])==1) { SquareValid=0; } } if(CurrentTile->isSquare==0) { SquareValid=0; } Player[PlayerNumber].Position=Vector2d(k1+0.5, k2+0.5); for (unsigned i=0; i< Player.size();++i) { Car *Car1,*Car2; if(i==PlayerNumber) { continue; } Car1=&Player[PlayerNumber]; Car2=&Player[i]; vector<Vector2d> Bounding1=Car1->Bounding; for (unsigned k=0; k<Bounding1.size();k++) { Bounding1[k]=RotateVector(Bounding1[k],Player[PlayerNumber].Rotation); Bounding1[k]+=Player[PlayerNumber].Position; } Vector2d Center1=accumulate(Bounding1.begin(),Bounding1.end(),Vector2d(0,0))/static_cast<double>(Bounding1.size()); vector<Vector2d> Bounding2=Car2->Bounding; for (unsigned k=0; k<Bounding2.size();k++) { Bounding2[k]=RotateVector(Bounding2[k],Player[i].Rotation); Bounding2[k]+=Player[i].Position; } Vector2d Center2=accumulate(Bounding2.begin(),Bounding2.end(),Vector2d(0,0))/static_cast<double>(Bounding2.size()); if( InPolygon(Bounding1,Bounding2) || InPolygon(Center1,Bounding2) || InPolygon(Center2,Bounding1) ) { CarCollision=1; } } j++; if (j==Dim.x*Dim.y) { cerr<<"Failed to Find Valid Square!!"<<endl; } } return Vector2u(index[j-1]%Dim.x,index[j-1]/Dim.x); }
ts::Vector2u ts::graphics::Texture::size() const { return Vector2u(total_size_.x, total_size_.y); }
Vector2u Label::getSize() const { return Vector2u(static_cast<unsigned int>(text.getLocalBounds().left + text.getLocalBounds().width), static_cast<unsigned int>(text.getLocalBounds().top + text.getLocalBounds().height)); }
Vector2u AirTextBox::getSpritePosition() const { return (Vector2u(this->sprite_->getPosition().x, this->sprite_->getPosition().y)); }
void Frame::extract_parameters() { // Retrieve frame resolution parameter. { const Vector2i DefaultResolution(512, 512); Vector2i resolution = m_params.get_required<Vector2i>("resolution", DefaultResolution); if (resolution[0] < 1 || resolution[1] < 1) { RENDERER_LOG_ERROR( "invalid value \"%d %d\" for parameter \"%s\", using default value \"%d %d\".", resolution[0], resolution[1], "resolution", DefaultResolution[0], DefaultResolution[1]); resolution = DefaultResolution; } impl->m_frame_width = static_cast<size_t>(resolution[0]); impl->m_frame_height = static_cast<size_t>(resolution[1]); } // Retrieve tile size parameter. { const Vector2i DefaultTileSize(64, 64); Vector2i tile_size = m_params.get_optional<Vector2i>("tile_size", DefaultTileSize); if (tile_size[0] < 1 || tile_size[1] < 1) { RENDERER_LOG_ERROR( "invalid value \"%d %d\" for parameter \"%s\", using default value \"%d %d\".", tile_size[0], tile_size[1], "tile_size", DefaultTileSize[0], DefaultTileSize[1]); tile_size = DefaultTileSize; } impl->m_tile_width = static_cast<size_t>(tile_size[0]); impl->m_tile_height = static_cast<size_t>(tile_size[1]); } // Retrieve pixel format parameter. { const PixelFormat DefaultPixelFormat = PixelFormatHalf; const char* DefaultPixelFormatString = "half"; const string pixel_format_str = m_params.get_optional<string>("pixel_format", DefaultPixelFormatString); if (pixel_format_str == "uint8") impl->m_pixel_format = PixelFormatUInt8; else if (pixel_format_str == "uint16") impl->m_pixel_format = PixelFormatUInt16; else if (pixel_format_str == "uint32") impl->m_pixel_format = PixelFormatUInt32; else if (pixel_format_str == "half") impl->m_pixel_format = PixelFormatHalf; else if (pixel_format_str == "float") impl->m_pixel_format = PixelFormatFloat; else if (pixel_format_str == "double") impl->m_pixel_format = PixelFormatDouble; else { RENDERER_LOG_ERROR( "invalid value \"%s\" for parameter \"%s\", using default value \"%s\".", pixel_format_str.c_str(), "pixel_format", DefaultPixelFormatString); impl->m_pixel_format = DefaultPixelFormat; } } // Retrieve reconstruction filter parameter. { const char* DefaultFilterName = "gaussian"; impl->m_filter_name = m_params.get_optional<string>("filter", DefaultFilterName); impl->m_filter_radius = m_params.get_optional<float>("filter_size", 2.0f); if (impl->m_filter_name == "box") impl->m_filter.reset(new BoxFilter2<float>(impl->m_filter_radius, impl->m_filter_radius)); else if (impl->m_filter_name == "triangle") impl->m_filter.reset(new TriangleFilter2<float>(impl->m_filter_radius, impl->m_filter_radius)); else if (impl->m_filter_name == "gaussian") impl->m_filter.reset(new GaussianFilter2<float>(impl->m_filter_radius, impl->m_filter_radius, 8.0f)); else if (impl->m_filter_name == "mitchell") impl->m_filter.reset(new MitchellFilter2<float>(impl->m_filter_radius, impl->m_filter_radius, 1.0f/3, 1.0f/3)); else if (impl->m_filter_name == "bspline") impl->m_filter.reset(new MitchellFilter2<float>(impl->m_filter_radius, impl->m_filter_radius, 1.0f, 0.0f)); else if (impl->m_filter_name == "catmull") impl->m_filter.reset(new MitchellFilter2<float>(impl->m_filter_radius, impl->m_filter_radius, 0.0f, 0.5f)); else if (impl->m_filter_name == "lanczos") impl->m_filter.reset(new LanczosFilter2<float>(impl->m_filter_radius, impl->m_filter_radius, 3.0f)); else if (impl->m_filter_name == "blackman-harris") impl->m_filter.reset(new BlackmanHarrisFilter2<float>(impl->m_filter_radius, impl->m_filter_radius)); else { RENDERER_LOG_ERROR( "invalid value \"%s\" for parameter \"%s\", using default value \"%s\".", impl->m_filter_name.c_str(), "filter", DefaultFilterName); impl->m_filter_name = DefaultFilterName; impl->m_filter.reset(new GaussianFilter2<float>(impl->m_filter_radius, impl->m_filter_radius, 8.0f)); } } // Retrieve color space parameter. { const ColorSpace DefaultColorSpace = ColorSpaceLinearRGB; const char* DefaultColorSpaceString = "linear_rgb"; const string color_space_str = m_params.get_optional<string>("color_space", DefaultColorSpaceString); if (color_space_str == "linear_rgb") m_color_space = ColorSpaceLinearRGB; else if (color_space_str == "srgb") m_color_space = ColorSpaceSRGB; else if (color_space_str == "ciexyz") m_color_space = ColorSpaceCIEXYZ; else { RENDERER_LOG_ERROR( "invalid value \"%s\" for parameter \"%s\", using default value \"%s\".", color_space_str.c_str(), "color_space", DefaultColorSpaceString); m_color_space = DefaultColorSpace; } } // Retrieve premultiplied alpha parameter. m_is_premultiplied_alpha = m_params.get_optional<bool>("premultiplied_alpha", true); // Retrieve clamping parameter. impl->m_clamp = m_params.get_optional<bool>("clamping", false); // Retrieve gamma correction parameter. impl->m_target_gamma = m_params.get_optional<float>("gamma_correction", 1.0f); impl->m_rcp_target_gamma = 1.0f / impl->m_target_gamma; // Retrieve crop window parameter. const AABB2u default_crop_window( Vector2u(0, 0), Vector2u(impl->m_frame_width - 1, impl->m_frame_height - 1)); impl->m_crop_window = m_params.get_optional<AABB2u>("crop_window", default_crop_window); }
void Race::HandleWallCollisions(){ int trackwidth=track.getDim().x, trackheight=track.getDim().y; for (unsigned i=0; i<Player.size();i++) { bool StillCorrecting=1; unsigned Attempts=0; while (StillCorrecting){ StillCorrecting=0; vector<Vector2d> Bounding=Player[i].Bounding; for (unsigned j=0; j<4;j++) { Bounding[j]=RotateVector(Bounding[j],Player[i].Rotation); Bounding[j]+=Player[i].Position; } Vector2u CurrentSquare=Player[i].getGridPosition(); for (int j=0; j<9;j++) { bool TestCollision=0; vector<Vector2d> BoundingTile; int index1=(j%3)-1, index2=(j/3)-1; index1+=CurrentSquare.x; index2+=CurrentSquare.y; if (index1>=0 && index1<trackwidth && index2>=0 && index2<trackheight) { Tile* CurrentTile=track.getTile(index1,index2); Detect Detection=CurrentTile->Detection; if(CurrentTile->isSquare && Detection.x.find(WALL)!=Detection.x.end()) { BoundingTile={Vector2d(index1,index2),Vector2d(index1,index2+1), Vector2d(index1+1,index2+1),Vector2d(index1+1,index2)}; TestCollision=1; } if(CurrentTile->isSquare==0 && Detection.y.find(WALL)!=Detection.y.end()) { if(CurrentTile->Orientation==1) { BoundingTile={Vector2d(index1,index2),Vector2d(index1,index2+1),Vector2d(index1+1,index2)}; } else{ BoundingTile={Vector2d(index1,index2),Vector2d(index1+1,index2+1),Vector2d(index1+1,index2)}; } TestCollision=1; } if(CurrentTile->isSquare==0 && Detection.x.find(WALL)!=Detection.x.end()) { if(CurrentTile->Orientation==1) { BoundingTile={Vector2d(index1,index2+1),Vector2d(index1+1,index2+1),Vector2d(index1+1,index2)}; } else{ BoundingTile={Vector2d(index1,index2),Vector2d(index1,index2+1),Vector2d(index1+1,index2+1)}; } TestCollision=1; } } else{ BoundingTile={Vector2d(index1,index2),Vector2d(index1,index2+1), Vector2d(index1+1,index2+1),Vector2d(index1+1,index2)}; TestCollision=1; } if(TestCollision==1) { bool CornerPoly=0; Vector2u CornerSide=Vector2u(); Vector2d Direction=Vector2d(); double Overlap=0; bool DoubleFlag=0; if(InPolygon(BoundingTile, Bounding, CornerPoly, CornerSide, Direction,Overlap,DoubleFlag)) { if(CornerPoly==1) { Direction=Vector2d(-Direction.x,-Direction.y); } if (DoubleFlag==1) { Vector2d TileAverage=accumulate(BoundingTile.begin(),BoundingTile.end(),Vector2d(0,0)); TileAverage=TileAverage/static_cast<double>(BoundingTile.size()); Vector2d Average=accumulate(Bounding.begin(),Bounding.end(),Vector2d(0,0)); Average=Average/static_cast<double>(Bounding.size()); Vector2d AltVelocity=Average-TileAverage; AltVelocity=AltVelocity/(sqrt(DotProduct(AltVelocity,AltVelocity))); HandleSingleWallCollision(Player[i], Direction, Overlap,Attempts,AltVelocity); } else{ HandleSingleWallCollision(Player[i], Direction, Overlap,Attempts); } StillCorrecting=1; Attempts++; } } if(Attempts>=20) { Player[i].DeathSwitch=1; StillCorrecting=0; } } } } }