void Camera::UpdateHeroFollow( float dt ) { //if hero hasn't moved this frame, return Hero* hero = g_game->GetWorld()->GetHero(); if(hero->MovedLastFrame() == false) { return; } //try to focus on hero Vec2f oldCenter = m_quad.Center(); Vec2f toHero = g_game->GetWorld()->GetHero()->GetMoveCenter() - m_quad.Center(); float oldDistance = toHero.Length(); toHero.Normalize(); m_quad.Offset(toHero * kCameraMoveSpeed * dt); float distanceMoved = (m_quad.Center() - oldCenter).Length(); if(distanceMoved > oldDistance) { //overshoot m_quad.SetCenter(g_game->GetWorld()->GetHero()->GetMoveCenter()); } //constrain to room m_quad.ClipInsideOtherQuad(m_room->RoomQuad()); }
void Camera::UpdateDestination( float dt ) { //move if necessary if(m_hasDestination) { Vec2f toDestination = m_destinationPosition - m_quad.Center(); float distanceRemaning = toDestination.Length(); float moveStep = kCameraMoveSpeed * dt; bool doneMoving = false; if(moveStep > distanceRemaning) { moveStep = distanceRemaning; m_hasDestination = false; //we're there } Vec2f direction = toDestination; direction.Normalize(); Vec2f oldPosition = m_quad.Center(); //movestep m_quad.SetLowerLeft(m_quad.LowerLeft() + direction * moveStep); } }
void WaterPhysicsSystem::Vertex::addOutwardsEdge(Edge* _edge, const Vec2f& _b) { assert(_edge->getA() == this); Vec2f dir = _b - position; dir /= dir.Length(); float angle = atan2(dir.y, dir.x); for (auto i = edges.begin(); i != edges.end(); i++) { if (i->angle > angle) { edges.insert(i, {angle, _edge}); return; } } edges.push_back({angle, _edge}); }
void SceneObjectGeometry::ComputeDestructionGraph(const float _accuracy) { destructionGraph.clear(); destructionGraph.resize(figures.size() * figures.size()); memset(&*destructionGraph.begin(), 0, sizeof(int) * destructionGraph.size()); // TODO: optimize this (o(n^2) now) for (unsigned i = 0; i < figures.size(); i++) { for (unsigned j = 0; j < figures.size(); j++) { int cont = 0; for (unsigned int k = 0; k < figures[i].vertices.size() && cont < 2; k++) { for (unsigned int l = 0; l < figures[j].vertices.size() && cont < 2; l++) { Vec2f dist = figures[i].vertices[k]; dist -= figures[j].vertices[l]; unsigned int res = 0; if (dist.Length() < _accuracy) { cont++; } if (cont >= 2) { res = 1; } destructionGraph[i * figures.size() + j] = res; destructionGraph[j * figures.size() + i] = res; } } } } }