当前位置: 首页>>代码示例>>C++>>正文


C++ Box2d类代码示例

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


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

示例1: rect

float mgnear::quadSplinesHit(int n, const Point2d* knots, bool closed,
                             const Point2d& pt, float tol, Point2d& nearpt, int& segment)
{
    Point2d ptTemp;
    float dist, distMin = _FLT_MAX;
    Point2d pts[3 + 4];
    const Box2d rect (pt, 2 * tol, 2 * tol);
    
    segment = -1;
    for (int i = 0; i < (closed ? n : n - 2); i++, pts[0] = pts[2]) {
        if (i == 0) {
            pts[0] = closed ? (knots[0] + knots[1]) / 2 : knots[0];
        }
        pts[1] = knots[(i+1) % n];
        if (closed || i + 3 < n)
            pts[2] = (knots[(i+1) % n] + knots[(i+2) % n]) / 2;
        else
            pts[2] = knots[i+2];
        
        mgcurv::quadBezierToCubic(pts, pts + 3);
        if (rect.isIntersect(computeCubicBox(pts + 3))) {
            dist = mgnear::nearestOnBezier(pt, pts + 3, ptTemp);
            if (dist < distMin) {
                distMin = dist;
                nearpt = ptTemp;
                segment = i;
            }
        }
    }
    
    return distMin;
}
开发者ID:codingBobo,项目名称:vgcore,代码行数:32,代码来源:mgnear.cpp

示例2: box

void NormalFilter::render(const ITextureObject& texture, const ICamera<float>& renderedCamera)
{
	const Box2d<float> box(Vector2d<float>(-1.0, -1.0), Vector2d<float>(1.0, 1.0));
	const auto& positions = box.toArray();

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


	glEnable(GL_DEPTH_TEST);
	//glDisable(GL_DEPTH_TEST);

	glUseProgram(shader.getId());

	texture.bind();
	
	//glGetUniformLocation( texture.getId()
	glUniform1i(shader.getUniformLocation("depthTex"), texture.getId());
	glUniform1f(shader.getUniformLocation("texelSizeW"), 1.0f / static_cast<float>(texture.getWidth()));
	glUniform1f(shader.getUniformLocation("texelSizeH"), 1.0f / static_cast<float>(texture.getHeight()));

	glUniformMatrix4fv(shader.getUniformLocation("projectionMatrix"), 1, GL_FALSE, renderedCamera.getProjectionMatrix().toArray().data());
	glVertexAttribPointer(shader.getAttribLocation("positions"), 2, GL_FLOAT, GL_FALSE, 0, positions.data());

	glEnableVertexAttribArray(0);
	glDrawArrays(GL_QUADS, 0, static_cast<GLsizei>( positions.size() / 2) );
	glDisableVertexAttribArray(0);

	glBindFragDataLocation(shader.getId(), 0, "fragColor");

	texture.unbind();
	glDisable(GL_DEPTH_TEST);

	glUseProgram(0);
}
开发者ID:SatoshiMabuchi,项目名称:CGLib,代码行数:35,代码来源:NormalFilter.cpp

示例3: setClipBox

bool GiGraphics::setClipBox(const RECT_2D& rc)
{
    if (m_impl->drawRefcnt < 1)
        return false;

    bool ret = false;
    Box2d rect;

    if (!rect.intersectWith(Box2d(rc), Box2d(m_impl->clipBox0)).isEmpty())
    {
        if (rect != Box2d(m_impl->clipBox))
        {
            rect.get(m_impl->clipBox);
            m_impl->rectDraw.set(Box2d(rc));
            m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
            m_impl->rectDrawM = m_impl->rectDraw * xf().displayToModel();
            m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
            SafeCall(m_impl->canvas, clipRect(m_impl->clipBox.left, m_impl->clipBox.top,
                                              m_impl->clipBox.width(),
                                              m_impl->clipBox.height()));
        }
        ret = true;
    }

    return ret;
}
开发者ID:gkrists,项目名称:TouchVG,代码行数:26,代码来源:gigraph.cpp

示例4: box

bool GiGraphics::setClipWorld(const Box2d& rectWorld)
{
    bool ret = false;

    if (isDrawing() && !rectWorld.isEmpty())
    {
        Box2d box (rectWorld * xf().worldToDisplay());

        box.intersectWith(Box2d(m_impl->clipBox0));
        if (!box.isEmpty(Tol(1, 0)))
        {
            if (box != Box2d(m_impl->clipBox))
            {
                box.get(m_impl->clipBox);
                m_impl->rectDraw = box;
                m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
                m_impl->rectDrawM = m_impl->rectDraw * xf().displayToModel();
                m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
                SafeCall(m_impl->canvas, _clipBoxChanged(m_impl->clipBox));
            }

            ret = true;
        }
    }

    return ret;
}
开发者ID:acekiller,项目名称:touchvg,代码行数:27,代码来源:gigraph.cpp

示例5: pt1

float MgEllipse::_hitTest(const Point2d& pt, float tol, MgHitResult& res) const
{
    if (isCircle()) {
        Point2d pt1(getCenter()), pt2(pt);
        crossCircle(pt1, pt2, this);
        float d1 = pt.distanceTo(pt1);
        float d2 = pt.distanceTo(pt2);
        res.nearpt = d1 < d2 ? pt1 : pt2;
        return mgMin(d1, d2);
    }
    
    float distMin = _FLT_MAX;
    const Box2d rect (pt, 2 * tol, 2 * tol);
    Point2d ptTemp;

    for (int i = 0; i < 4; i++) {
        if (rect.isIntersect(Box2d(4, _bzpts + 3 * i))) {
            mgnear::nearestOnBezier(pt, _bzpts + 3 * i, ptTemp);
            float dist = pt.distanceTo(ptTemp);
            if (dist <= tol && dist < distMin) {
                distMin = dist;
                res.nearpt = ptTemp;
                res.segment = i;
            }
        }
    }

    return distMin;
}
开发者ID:Vito2015,项目名称:vgcore,代码行数:29,代码来源:mgellipse.cpp

示例6: rect

float MgEllipse::_hitTest(const Point2d& pt, float tol, 
                          Point2d& nearpt, int& segment) const
{
    float distMin = _FLT_MAX;
    const Box2d rect (pt, 2 * tol, 2 * tol);
    Point2d ptTemp;

    segment = -1;
    for (int i = 0; i < 4; i++)
    {
        if (rect.isIntersect(Box2d(4, _bzpts + 3 * i)))
        {
            mgNearestOnBezier(pt, _bzpts + 3 * i, ptTemp);
            float dist = pt.distanceTo(ptTemp);
            if (dist <= tol && dist < distMin)
            {
                distMin = dist;
                nearpt = ptTemp;
                segment = i;
            }
        }
    }

    return distMin;
}
开发者ID:firehot,项目名称:touchvg,代码行数:25,代码来源:mgellipse.cpp

示例7: box

void OnScreenRenderer::render(const ITextureObject& texture)
{
	const Box2d<float> box(Vector2d<float>(-1.0, -1.0), Vector2d<float>(1.0, 1.0));
	const auto& positions = box.toArray();

	//glEnable(GL_DEPTH_TEST);

	glUseProgram(shader.getId());

	texture.bind();

	glUniform1i(shader.getUniformLocation("texture"), texture.getId());

	glVertexAttribPointer(shader.getAttribLocation("positions"), 2, GL_FLOAT, GL_FALSE, 0, positions.data());

	glEnableVertexAttribArray(0);
	glDrawArrays(GL_QUADS, 0,  static_cast<GLsizei>( positions.size() / 2) );
	glDisableVertexAttribArray(0);

	glBindFragDataLocation(shader.getId(), 0, "fragColor");

	texture.unbind();
	//glDisable(GL_DEPTH_TEST);

	glUseProgram(0);
}
开发者ID:SatoshiMabuchi,项目名称:CGLib,代码行数:26,代码来源:OnScreenRenderer.cpp

示例8: PQ2

 inline Pt2dr  PQ2(const Box2d<Type> & b,INT c1,INT c2)
 {
       return Pt2dr
              (  
                  b.x(TAB_IND_Q2X[c1][c2]),
                  b.y(TAB_IND_Q2Y[c1][c2])
              );
 }
开发者ID:jakexie,项目名称:micmac-archeos,代码行数:8,代码来源:box.cpp

示例9: box

bool mglnrel::clipLine(Point2d& pt1, Point2d& pt2, const Box2d& _box)
{
    Box2d box (_box);
    box.normalize();
    
    unsigned code1, code2;
    code1 = ClipCode(pt1, box);
    code2 = ClipCode(pt2, box);
    
    for ( ; ; )
    {
        if (!(code1 | code2))       // 完全在矩形内
            return true;
        if (code1 & code2)          // 完全在矩形外
            return false;
        
        float x = 0.f, y = 0.f;
        unsigned code;
        
        if (code1)                  // 起点不在矩形内
            code = code1;
        else                        // 终点不在矩形内
            code = code2;
        if (code & 0x1000)          // 上
        {
            x = pt1.x + (pt2.x - pt1.x) * (box.ymax - pt1.y) / (pt2.y - pt1.y);
            y = box.ymax;
        }
        else if (code & 0x0100)     // 下
        {
            x = pt1.x + (pt2.x - pt1.x) * (box.ymin - pt1.y) / (pt2.y - pt1.y);
            y = box.ymin;
        }
        else if (code & 0x0001)     // 左
        {
            y = pt1.y + (pt2.y - pt1.y) * (box.xmin - pt1.x) / (pt2.x - pt1.x);
            x = box.xmin;
        }
        else if (code & 0x0010)     // 右
        {
            y = pt1.y + (pt2.y - pt1.y) * (box.xmax - pt1.x) / (pt2.x - pt1.x);
            x = box.xmax;
        }
        
        if (code == code1)
        {
            pt1.x = x;
            pt1.y = y;
            code1 = ClipCode(pt1, box);
        }
        else
        {
            pt2.x = x;
            pt2.y = y;
            code2 = ClipCode(pt2, box);
        }
    }
}
开发者ID:arthur-zhang,项目名称:touchvg,代码行数:58,代码来源:mglnrel.cpp

示例10: drawRect

bool GiGraphics::drawRect(const GiContext* ctx, const Box2d& rect, 
                          bool modelUnit)
{
    Point2d points[4] = {
        rect.leftBottom(), rect.rightBottom(), 
        rect.rightTop(), rect.leftTop()
    };
    return drawPolygon(ctx, 4, points, modelUnit);
}
开发者ID:acekiller,项目名称:touchvg,代码行数:9,代码来源:gigraph.cpp

示例11: Box2d

void CScrollShapeView::OnZoomed()
{
    CRandomShapeView::OnZoomed();

    Box2d rect;

    // m_rcLimits: 极限范围对应的坐标范围, 像素
    rect = m_shapes->getExtent() * m_graph->xf.modelToDisplay();
    rect.inflate(1, 1);
    rect.get(m_rcLimits);

    // m_rcScrWnd: 当前窗口对应的坐标范围, 像素
    rect = Box2d(m_graph->xf.getCenterW(),
        m_graph->xf.getWidth() / m_graph->xf.getWorldToDisplayX(),
        m_graph->xf.getHeight() / m_graph->xf.getWorldToDisplayY());
    rect *= m_graph->xf.worldToDisplay();
    rect.get(m_rcScrWnd);

    // 以m_rcLimits左上角为原点调整m_rcScrWnd和m_rcLimits
    ::OffsetRect(&m_rcScrWnd, -m_rcLimits.left, -m_rcLimits.top);
    ::OffsetRect(&m_rcLimits, -m_rcLimits.left, -m_rcLimits.top);

    // 避免m_rcScrWnd部分超出m_rcLimits
    ::UnionRect(&m_rcLimits, &m_rcLimits, &m_rcScrWnd);

    SCROLLINFO si;
    si.cbSize = sizeof(si);
    si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
    si.nMin = 0;

    if (m_rcLimits.right - m_rcLimits.left > m_rcScrWnd.right - m_rcScrWnd.left)
    {
        si.nMax = max(1, m_rcLimits.right - m_rcLimits.left);
        si.nPage = m_rcScrWnd.right - m_rcScrWnd.left;
        si.nPos = m_rcScrWnd.left;
        ::EnableScrollBar(m_hWnd, SB_HORZ, ESB_ENABLE_BOTH);
        ::SetScrollInfo(m_hWnd, SB_HORZ, &si, TRUE);
    }
    else
    {
        ::EnableScrollBar(m_hWnd, SB_HORZ, ESB_DISABLE_BOTH);
    }

    if (m_rcLimits.bottom - m_rcLimits.top > m_rcScrWnd.bottom - m_rcScrWnd.top)
    {
        si.nMax = max(1, m_rcLimits.bottom - m_rcLimits.top);
        si.nPage = m_rcScrWnd.bottom - m_rcScrWnd.top;
        si.nPos = m_rcScrWnd.top;
        ::EnableScrollBar(m_hWnd, SB_VERT, ESB_ENABLE_BOTH);
        ::SetScrollInfo(m_hWnd, SB_VERT, &si, TRUE);
    }
    else
    {
        ::EnableScrollBar(m_hWnd, SB_VERT, ESB_DISABLE_BOTH);
    }
}
开发者ID:thinkfeed,项目名称:touchvg,代码行数:56,代码来源:Step2View.cpp

示例12: getExtent

Box2d MgShapeDoc::getExtent() const
{
    Box2d rect;

    for (unsigned i = 0; i < im->layers.size(); i++) {
        rect.unionWith(im->layers[i]->getExtent());
    }

    return rect;
}
开发者ID:rhcad,项目名称:touchvg-v0.6,代码行数:10,代码来源:mgshapedoc.cpp

示例13: drawRoundRect

bool GiGraphics::drawRoundRect(const GiContext* ctx, 
                               const Box2d& rect, float rx, float ry, 
                               bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || rect.isEmpty())
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    bool ret = false;

    if (ry < _MGZERO)
        ry = rx;

    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(rect))  // 全部在显示区域外
        return false;

    if (rx < _MGZERO)
    {
        Point2d points[4] = {
            rect.leftBottom(), rect.rightBottom(), 
            rect.rightTop(), rect.leftTop()
        };
        return drawPolygon(ctx, 4, points);
    }
    else
    {
        Point2d points[16];

        mgRoundRectToBeziers(points, rect, rx, ry);
        S2D(xf(), modelUnit).TransformPoints(16, points);

        ret = rawBeginPath();
        if (ret)
        {
            ret = rawMoveTo(points[0].x, points[0].y);
            ret = rawBezierTo(&points[1], 3);

            ret = rawLineTo(points[4].x, points[4].y);
            ret = rawBezierTo(&points[5], 3);

            ret = rawLineTo(points[8].x, points[8].y);
            ret = rawBezierTo(&points[9], 3);

            ret = rawLineTo(points[12].x, points[12].y);
            ret = rawBezierTo(&points[13], 3);

            ret = rawClosePath();
            ret = rawEndPath(ctx, true);
        }
    }

    return ret;
}
开发者ID:acekiller,项目名称:touchvg,代码行数:52,代码来源:gigraph.cpp

示例14: Box2d

void MgCmdManagerImpl::getBoundingBox(Box2d& box, const MgMotion* sender)
{
    MgCommand* cmd = sender->cmds()->getCommand();
    Box2d selbox;

    if (cmd && strcmp(cmd->getName(), MgCmdSelect::Name()) == 0) {
        MgCmdSelect* sel = (MgCmdSelect*)cmd;
        selbox = sel->getBoundingBox(sender);
    }

    box = selbox.isEmpty() ? Box2d(sender->pointM, 0, 0) : selbox;
    box *= sender->view->xform()->modelToDisplay();
    box.normalize();
}
开发者ID:rhcad,项目名称:touchvg-v0.6,代码行数:14,代码来源:mgcmdmgr2.cpp

示例15: beziersBox

void mgnear::beziersBox(
    Box2d& box, int count, const Point2d* points, bool closed)
{
    box.empty();

    for (int i = 0; i + 3 < count; i += 3) {
        box.unionWith(computeCubicBox(points + i));
    }
    if (closed && count > 3) {
        box.unionWith(computeCubicBox(points[count - 1],
            points[count - 1] * 2 - points[count - 2].asVector(),
            points[0] * 2 - points[1].asVector(), points[0]));
    }
}
开发者ID:codingBobo,项目名称:vgcore,代码行数:14,代码来源:mgnear.cpp


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