/** * Obtiene el angulo de inclinacion de la marca * en grados. * La marca forma 0° al estar paralela al suelo, * y 90° al estar paralela a la camara. Esto es * yangle. * La marca forma 0° al estar paralela a la camara * y 180° al estar mirando hacia los lados. Cuando * mira hacia la derecha los grados son - y cuando * mira hacia la izquierda los grados son +. Esto * es xangle. */ void get_user_angle(double trans[3][4], double *xangle, double *yangle) { double wa, wb, wc; // Obtiene el angulo euleriano. get_angle(trans, &wa, &wb, &wc); // Obtiene el angulo de inclinacion de la marca // en grados con respecto al eje natural del usuario. *xangle = toDegree(wc); *yangle = toDegree(wb) - 90; }
float Math::angle(sf::Vector2f first, sf::Vector2f second) { float dotResult=dot(first, second); if(dotResult>1.0) { dotResult=1.0; } if(dotResult<-1.0) { dotResult=-1.0; } return toDegree(acos(dotResult)); //return toDegree(acos(dot(first, second))); }
/*PRIVATE FUNCTIONS*/ void Projectile::updateCurrent(sf::Time dt, CommandQueue& commands) { if (isGuided()) { const float approachRate = 200.f; sf::Vector2f newVel = unitVector(approachRate * dt.asSeconds() * targetDirection + getVelocity()); newVel *= getMaxSpeed(); float angle = std::atan2(newVel.y, newVel.x); setRotation(toDegree(angle) + 90.f); setVelocity(newVel); //rotation and velocity set } Entity::updateCurrent(dt, commands); //rotation and velocity drawn on screen }
void Projectile::UpdateCurrent( sf::Time dt, CommandQueue& commands ) { if ( IsGuided() ) { const float approachRate = 200.f; sf::Vector2f newVelocity = unitVector( approachRate * dt.asSeconds() * pImpl->mTargetDirection + GetVelocity() ); newVelocity *= GetMaxSpeed(); float angle = std::atan2( newVelocity.y, newVelocity.x ); setRotation( toDegree( angle ) + 90.f ); SetVelocity( newVelocity ); } Entity::UpdateCurrent( dt, commands ); }
void Samsquamptch::updateCurrent(sf::Time dt, sf::Vector2f target, sf::Vector2f bounds) { acquireTarget(target,bounds); m_velocity *= dt.asSeconds()*m_aggressionLevel; if(getPosition().y >= m_target.y && getPosition().y < m_target.y + m_bounds.y && getPosition().x >= m_target.x && getPosition().x < m_target.x + m_bounds.y) { //achieved goal - target acquired } else { //work towards goal setRotation(toDegree(m_angle) + 90.f); move(m_velocity); m_rect.setPosition(getPosition()); m_rect.setRotation(getRotation()); //std::cout<<"Chasing..."<<std::endl; } }
int toBearing(double angle) { double bearing = toDegree(angle)+ 360.0; return fmod(bearing, 360); }