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 FireProjectileAction::fire(const Vec2f& _source, const Vec2f& _position) { Vec2f direction = _position - _source; direction.Normalize(); Vec2f position = _source; position += direction*3; FactoryParameters _parameters; _parameters.add<Vec2f>("position", position); _parameters.add<Vec2f>("velocity", direction*100); immutableData.projectileFactory->use(&_parameters, nullptr); }
// CORRECTNESS: not calculating tangents across closed rotoPaths Vec2f AbstractPath::tangent(const int i) const { assert(i>=0 && i<getNumElements()); if (_tangents) return _tangents[i]; Vec2f U; if (i==0) Vec2f_Sub(U,getElement(1), getElement(0)); else if (i==getNumElements()-1) Vec2f_Sub(U,getElement(getNumElements()-1), getElement(getNumElements()-2)); else { Vec2f_Sub(U,getElement(i+1), getElement(i-1)); } U.Normalize(); return U; }