• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ math::Vector2类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中math::Vector2的典型用法代码示例。如果您正苦于以下问题:C++ Vector2类的具体用法?C++ Vector2怎么用?C++ Vector2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Vector2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: values

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);
}
开发者ID:creichert,项目名称:marshmallow_h,代码行数:7,代码来源:meshbase.cpp


示例2: draw_point

    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);
    }
开发者ID:blefaudeux,项目名称:goptical,代码行数:33,代码来源:io_renderer_plplot.cpp


示例3: Error

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;
}
开发者ID:Squareys,项目名称:magnum-plugins,代码行数:59,代码来源:StbPngImageConverter.cpp


示例4: draw_circle

 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);
 }
开发者ID:blefaudeux,项目名称:goptical,代码行数:8,代码来源:io_renderer_plplot.cpp


示例5: cos

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));
}
开发者ID:toobug1,项目名称:OpticalLib,代码行数:9,代码来源:tregularpolygon.cpp


示例6: normal

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();
}
开发者ID:toobug1,项目名称:OpticalLib,代码行数:9,代码来源:tcurvebase.cpp


示例7: Draw

	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);
	}
开发者ID:plainoldcj,项目名称:breaking_bricks,代码行数:11,代码来源:ent_block.cpp


示例8: draw_text

    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());
    }
开发者ID:blefaudeux,项目名称:goptical,代码行数:14,代码来源:io_renderer_plplot.cpp


示例9: movement

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);
}
开发者ID:Kruemmelmonster,项目名称:marshmallow_h,代码行数:15,代码来源:collidercomponent.cpp


示例10: SetEnemyEyeSight

void EnemyAIBase::SetEnemyEyeSight( math::Vector2 eye )
{
	if( m_enemyMine ){
		eye.Normalize();
		m_enemyMine->m_eye = eye;
	}
}
开发者ID:masarou,项目名称:2DAction,代码行数:7,代码来源:EnemyAIBase.cpp


示例11: inside

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);
}
开发者ID:toobug1,项目名称:OpticalLib,代码行数:17,代码来源:tregularpolygon.cpp


示例12: aspectRatioFix

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()));
}
开发者ID:respu,项目名称:magnum,代码行数:14,代码来源:AbstractCamera.hpp


示例13: aspectRatioFix

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)));
}
开发者ID:GYGit,项目名称:magnum,代码行数:15,代码来源:Camera.hpp


示例14: offsetFix

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;
}
开发者ID:St0l3nID,项目名称:ethanon,代码行数:19,代码来源:GLVideo.cpp


示例15: derivative

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);
}
开发者ID:toobug1,项目名称:OpticalLib,代码行数:18,代码来源:tcurvebase.cpp


示例16: inside

    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;
    }
开发者ID:blefaudeux,项目名称:goptical,代码行数:24,代码来源:shape_polygon.cpp


示例17: aspectRatioScale

 constexpr static Math::Matrix4<T> aspectRatioScale(const Math::Vector2<T>& scale) {
     return Math::Matrix4<T>::scaling({scale.x(), scale.y(), 1.0f});
 }
开发者ID:respu,项目名称:magnum,代码行数:3,代码来源:AbstractCamera.hpp


示例18: switch

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;
    }
}
开发者ID:toobug1,项目名称:OpticalLib,代码行数:39,代码来源:tlens.cpp


示例19: truncate

	/**
	* @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;
	}
开发者ID:ViniGodoy,项目名称:ForFun,代码行数:12,代码来源:Vector2.hpp


示例20: inside

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);
}
开发者ID:toobug1,项目名称:OpticalLib,代码行数:6,代码来源:tring.cpp



注:本文中的math::Vector2类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ math::Vector3类代码示例发布时间:2022-05-31
下一篇:
C++ math::Vector类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap