Exemple #1
0
void
MeshBase::setVertex(int i, const Math::Vector2 &v)
{
	if (!m_vdata->set(i, v.x(), v.y()))
		MMWARNING("Failed to assign values (%f, %f) to vertex %d",
		    v.x(), v.y(), i);
}
    void RendererPlplot::draw_point(const math::Vector2 &v, const Rgb &rgb, enum PointStyle s)
    {
      int code;

      _pls->col0(get_color_id(rgb));

      switch (s)
        {
        default:
        case PointStyleDot:
          code = 1;
          break;

        case PointStyleCross:
          code = 2;
          break;

        case PointStyleRound:
          code = 4;
          break;

        case PointStyleSquare:
          code = 6;
          break;

        case PointStyleTriangle:
          code = 11;
          break;
        }

      PLFLT x = v.x(), y = v.y();
      _pls->poin(1, &x, &y, code);
    }
Containers::Array<char> StbPngImageConverter::doExportToData(const ImageView2D& image) {
    #ifndef MAGNUM_TARGET_GLES
    if(image.storage().swapBytes()) {
        Error() << "Trade::StbPngImageConverter::exportToData(): pixel byte swap is not supported";
        return nullptr;
    }
    #endif

    if(image.type() != PixelType::UnsignedByte) {
        Error() << "Trade::StbPngImageConverter::exportToData(): unsupported pixel type" << image.type();
        return nullptr;
    }

    Int components;
    switch(image.format()) {
        #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
        case PixelFormat::Red:
        #endif
        #ifdef MAGNUM_TARGET_GLES2
        case PixelFormat::Luminance:
        #endif
            components = 1;
            break;
        #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
        case PixelFormat::RG:
        #endif
        #ifdef MAGNUM_TARGET_GLES2
        case PixelFormat::LuminanceAlpha:
        #endif
            components = 2;
            break;
        case PixelFormat::RGB: components = 3; break;
        case PixelFormat::RGBA: components = 4; break;
        default:
            Error() << "Trade::StbPngImageConverter::exportToData(): unsupported pixel format" << image.format();
            return nullptr;
    }

    /* Data properties */
    std::size_t offset;
    Math::Vector2<std::size_t> dataSize;
    std::tie(offset, dataSize, std::ignore) = image.dataProperties();

    /* Reverse rows in image data */
    Containers::Array<unsigned char> reversedData{image.data().size()};
    for(Int y = 0; y != image.size().y(); ++y) {
        std::copy(image.data<unsigned char>() + offset + y*dataSize.x(), image.data<unsigned char>() + offset + (y + 1)*dataSize.x(), reversedData + (image.size().y() - y - 1)*dataSize.x());
    }

    Int size;
    unsigned char* const data = stbi_write_png_to_mem(reversedData, dataSize.x(), image.size().x(), image.size().y(), components, &size);
    CORRADE_INTERNAL_ASSERT(data);

    /* Wrap the data in an array with custom deleter (we can't use delete[]) */
    Containers::Array<char> fileData{reinterpret_cast<char*>(data), std::size_t(size),
        [](char* data, std::size_t) { std::free(data); }};

    return fileData;
}
 void RendererPlplot::draw_circle(const math::Vector2 &c, double r,
                                  const Rgb &rgb, bool filled)
 {
   _pls->col0(get_color_id(rgb));
   std::cout << "draw_circle was not tested (added 8th parameter to compile" << std::endl;
   exit(-1);
   _pls->arc(c.x(), c.y(), r, r, 0., 360., 360., filled);
 }
Math::VectorPair2 TRegularPolygon::get_edge(const Math::Vector2 &point) const
{
    // find sector start angle
    double a = Math::lp_floor(atan2(point.y(), point.x()) - _angle, (double)_edge_cnt / (2.0 * M_PI));

    // find sector edge coordinates
    return Math::VectorPair2(_radius * cos(_angle + a), _radius * sin(_angle + a),
                             _radius * cos(_angle + a + _a_step), _radius * sin(_angle + a + _a_step));
}
Exemple #6
0
void TCurveBase::normal(Math::Vector3 &normal, const Math::Vector3 &point) const
{
    Math::Vector2 d;

    derivative(point.project_xy(), d);

    normal = Math::Vector3(d.x(), d.y(), -1.0);
    normal.normalize();
}
	void Block::Draw(sf::RenderTarget& renderTarget) {
		MATH::Vector2 position = GetPosition();

		if(_highlight) {
			_blockSprite.SetColor(_color + sf::Color(255, 255, 255, 255 * sinf(_highlightPhase)));
			position -= MATH::Vector2(0.0f, 5.0f * sinf(_highlightPhase));
		}

		_blockSprite.SetPosition(position.sfVec());
		renderTarget.Draw(_blockSprite);
	}
    void RendererPlplot::draw_text(const math::Vector2 &c, const math::Vector2 &dir,
                                   const std::string &str, TextAlignMask a, int size, const Rgb &rgb)
    {
      double j = .5;

      if (a & TextAlignLeft)
        j = 0.;
      else if (a & TextAlignRight)
        j = 1.;

      _pls->schr(size/3., 1.);
      _pls->col0(get_color_id(rgb));
      _pls->ptex(c.x(), c.y(), dir.x(), dir.y(), j, str.c_str());
    }
bool
BounceColliderComponent::collision(ColliderComponent &c, float d, const CollisionData &data)
{
	MMUNUSED(c);
	MMUNUSED(d);
	MMUNUSED(data);

	const Math::Vector2 &l_vel = movement()->velocity();
	const float l_mag = l_vel.magnitude();
	const Math::Vector2 l_normal = l_vel.normalized(l_mag);
	Math::Vector2 l_pvel = (l_normal * (2.f * l_normal.dot(l_vel * -1.f)) + l_vel);
	movement()->velocity() = l_pvel.normalize(l_pvel.magnitude()) * l_mag;

	return(true);
}
Exemple #10
0
void EnemyAIBase::SetEnemyEyeSight( math::Vector2 eye )
{
	if( m_enemyMine ){
		eye.Normalize();
		m_enemyMine->m_eye = eye;
	}
}
bool TRegularPolygon::inside(const Math::Vector2 &point) const
{
    double d = Math::square(point.x()) + Math::square(point.y());

    // check against circumscribed circle
    if (d > Math::square(_radius))
        return false;

    // check against inscribed circle
    if (d < Math::square(_i_radius))
        return true;

    Math::VectorPair2 e(get_edge(point));

    return ((point.y() - e.y0()) * (e.x1() - e.x0()) -
            (point.x() - e.x0()) * (e.y1() - e.y0()) > 0);
}
Exemple #12
0
template<UnsignedInt dimensions, class T> typename DimensionTraits<dimensions, T>::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Vector2i& viewport) {
    /* Don't divide by zero / don't preserve anything */
    if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved)
        return {};

    Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale;

    /* Extend on larger side = scale larger side down
       Clip on smaller side = scale smaller side up */
    return Camera<dimensions, T>::aspectRatioScale(
               (relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ?
               Vector2(relativeAspectRatio.y()/relativeAspectRatio.x(), T(1.0)) :
               Vector2(T(1.0), relativeAspectRatio.x()/relativeAspectRatio.y()));
}
Exemple #13
0
template<UnsignedInt dimensions, class T> MatrixTypeFor<dimensions, T> aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Vector2i& viewport) {
    /* Don't divide by zero / don't preserve anything */
    if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved)
        return {};

    CORRADE_INTERNAL_ASSERT((projectionScale > Math::Vector2<T>(0)).all() && (viewport > Vector2i(0)).all());
    Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale;

    /* Extend on larger side = scale larger side down
       Clip on smaller side = scale smaller side up */
    return MatrixTypeFor<dimensions, T>::scaling(Math::Vector<dimensions, T>::pad(
        (relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ?
        Math::Vector2<T>(relativeAspectRatio.y()/relativeAspectRatio.x(), T(1)) :
        Math::Vector2<T>(T(1), relativeAspectRatio.x()/relativeAspectRatio.y()), T(1)));
}
Exemple #14
0
bool GLVideo::DrawLine(const math::Vector2 &p1, const math::Vector2 &p2, const Color& color1, const Color& color2)
{
	if (GetLineWidth() <= 0.0f)
		return true;
	if (p1 == p2)
		return true;

	static const math::Vector2 offsetFix(0.5f, 0.5f);
	const math::Vector2 a(p1 + offsetFix), b(p2 + offsetFix);
	const math::Vector2 v2Dir = a - b;

	const float length = v2Dir.Length() + 0.5f;
	const float angle  = math::RadianToDegree(math::GetAngle(v2Dir));

	DrawRectangle(a, math::Vector2(GetLineWidth(), length),
				  color2, color2, color1, color1,
				  angle, Sprite::EO_CENTER_BOTTOM);
	return true;
}
Exemple #15
0
void TCurveBase::derivative(const Math::Vector2 & xy, Math::Vector2 & dxdy) const
{
    double abserr;
    struct curve_gsl_params_s params;
    gsl_function gsl_func;

    gsl_func.params = &params;

    params.c = this;
    params.x = xy.x();
    params.y = xy.y();

    gsl_func.function = gsl_func_sagitta_x;
    gsl_deriv_central(&gsl_func, xy.x(), 1e-6, &dxdy.x(), &abserr);

    gsl_func.function = gsl_func_sagitta_y;
    gsl_deriv_central(&gsl_func, xy.y(), 1e-6, &dxdy.y(), &abserr);
}
Exemple #16
0
    bool Polygon::inside(const math::Vector2 &p) const
    {
      unsigned int s = _vertices.size();

      if (s < 3)
        return false;

      unsigned int count = 0;
      const math::Vector2 *w = &_vertices[s - 1];

      // FIXME optimize
      for (unsigned int i = 0; i < s; i++)
        {
          const math::Vector2 *v = &_vertices[i];

          // Algorithm from http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
          if ((((v->y() <= p.y()) && (p.y() < w->y())) || ((w->y() <= p.y()) && (p.y() < v->y()))) &&
              (p.x() < (w->x() - v->x()) * (p.y() - v->y()) / (w->y() - v->y()) + v->x()))
            count++;
          w = v;
        }

      return (count & 1) != 0;
    }
Exemple #17
0
 constexpr static Math::Matrix4<T> aspectRatioScale(const Math::Vector2<T>& scale) {
     return Math::Matrix4<T>::scaling({scale.x(), scale.y(), 1.0f});
 }
Exemple #18
0
void TLens::draw_2d_edge(TRenderer &r, const TSurface &left, double l_y,
                         const TSurface &right, double r_y, LensEdge type,
                         const TElement *ref) const
{
    const Math::Vector3 l3(0., l_y, left.get_curve()->sagitta(Math::Vector2(0., l_y)));
    const Math::Vector2 l2(left.get_transform_to(ref).transform(l3).project_zy());

    const Math::Vector3 r3(0., r_y, right.get_curve()->sagitta(Math::Vector2(0., r_y)));
    const Math::Vector2 r2(right.get_transform_to(ref).transform(r3).project_zy());

    switch (type)
    {
    case StraightEdge: {
        if (fabs(l2.y() - r2.y()) > 1e-6)
        {
            double m;

            if (fabs(l2.y()) > fabs(r2.y()))
            {
                m = l2.y();
                r.draw_segment(Math::VectorPair2(r2.x(), m, r2.x(), r2.y()), left.get_color(r));
            }
            else
            {
                m = r2.y();
                r.draw_segment(Math::VectorPair2(l2.x(), m, l2.x(), l2.y()), left.get_color(r));
            }

            r.draw_segment(Math::VectorPair2(l2.x(), m, r2.x(), m), left.get_color(r));

            break;
        }
    }

    case SlopeEdge:
        r.draw_segment(l2, r2, left.get_color(r));
        break;
    }
}
Exemple #19
0
	/**
	* @param v A vector
	* @param size Maximum size of the returning vector
	* 
	* @return If the size if v is greater than size, returns
	* a resized version of v with the specified size. Otherwise
	* just return a copy of v.
	*/
	inline Vector2 truncate(const math::Vector2& v, float size)
	{					
		return (v.sizeSqr() > size * size) ? resize(v, size) : v;
	}
Exemple #20
0
bool TRingBase::inside(const Math::Vector2 &point) const
{
    double d = Math::square(point.x()) + Math::square(point.y());

    return d <= Math::square(_radius) && d >= Math::square(_hole_radius);
}
Exemple #21
0
bool SDLInput::SetCursorPositionF(math::Vector2 v2Pos)
{
	return SetCursorPosition(v2Pos.ToVector2i());
}
Exemple #22
0
 double EllipseBase::get_outter_radius(const math::Vector2 &dir) const
 {
   return _xr > _yr
     ? sqrt(math::square(_yr) / (1. - _e2 * math::square(dir.x())))
     : sqrt(math::square(_xr) / (1. - _e2 * math::square(dir.y())));
 }
Exemple #23
0
 bool EllipseBase::inside(const math::Vector2 &point) const
 {
   return (math::square(point.x()) + math::square(point.y() * _xy_ratio) <= math::square(_xr));
 }