Example #1
0
void Camera::UpdateVisibility(const Collider& Collider)
{
    using std::sort;
    using std::unique;

    for (auto&& buf : m_Buffers) {
        buf.clear();
    }

    const Vec2i LeftUpper = -m_CurTranslation - Vec2f(1.f, 1.f);
    const Vec2i RightLower =
        -m_CurTranslation + m_ViewHalfSize * 2.f + Vec2f(1.f, 1.f);
    m_CollisionsEnd = Collider.CopyColliding(
        LeftUpper, RightLower, m_CollisionsBuffer.begin());

    sort(m_CollisionsBuffer.begin(), m_CollisionsEnd);
    m_CollisionsEnd = unique(m_CollisionsBuffer.begin(), m_CollisionsEnd);

    for (auto CollisionsIter = m_CollisionsBuffer.begin();
         CollisionsIter != m_CollisionsEnd; ++CollisionsIter) {
        const int TextureDescr = (*CollisionsIter)->GetTextureDescriptor();
        if (TextureDescr != -1) {
            m_Buffers[TextureDescr].push_back(*CollisionsIter);
        }
    }
}
Example #2
0
void Camera::DrawBack()
{
    using namespace ci;

    m_Back.enableAndBind();

    Rectf rect(0.f, 0.f, m_ViewHalfSize.x * 2.f, m_ViewHalfSize.y * 2.f);
    glEnableClientState(GL_VERTEX_ARRAY);
    GLfloat verts[8];
    glVertexPointer(2, GL_FLOAT, 0, verts);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    GLfloat texCoords[8];
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    verts[0 * 2 + 0] = rect.getX2();
    verts[0 * 2 + 1] = rect.getY1();
    verts[1 * 2 + 0] = rect.getX1();
    verts[1 * 2 + 1] = rect.getY1();
    verts[2 * 2 + 0] = rect.getX2();
    verts[2 * 2 + 1] = rect.getY2();
    verts[3 * 2 + 0] = rect.getX1();
    verts[3 * 2 + 1] = rect.getY2();

    const Vec2f LeftUpper = -m_CurTranslation - Vec2f(1.f, 1.f);
    const Vec2f RightLower =
        -m_CurTranslation + m_ViewHalfSize * 2.f + Vec2f(1.f, 1.f);
    const Vec2f TextureSize = m_Back.getSize();
    const float x1 = LeftUpper.x / TextureSize.x;
    const float x2 = RightLower.x / TextureSize.x;
    const float y1 = LeftUpper.y / TextureSize.y;
    const float y2 = RightLower.y / TextureSize.y;

    texCoords[0 * 2 + 0] = x2;
    texCoords[0 * 2 + 1] = y1;
    texCoords[1 * 2 + 0] = x1;
    texCoords[1 * 2 + 1] = y1;
    texCoords[2 * 2 + 0] = x2;
    texCoords[2 * 2 + 1] = y2;
    texCoords[3 * 2 + 0] = x1;
    texCoords[3 * 2 + 1] = y2;

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Example #3
0
void Particles::
update_from_grid(void)
{
   int p;
   int i, ui, j, vj;
   float fx, ufx, fy, vfy;
   for(p=0; p<np; ++p){
      grid.bary_x(x[p][0], ui, ufx);
      grid.bary_x_centre(x[p][0], i, fx);
      grid.bary_y(x[p][1], vj, vfy);
      grid.bary_y_centre(x[p][1], j, fy);
      //u[p]+=Vec2f(grid.du.bilerp(ui, j, ufx, fy), grid.dv.bilerp(i, vj, fx, vfy)); // FLIP
      u[p]=Vec2f(grid.u.bilerp(ui, j, ufx, fy), grid.v.bilerp(i, vj, fx, vfy)); // PIC
   }
}
Example #4
0
Texture TextureFromAsset(const string& Id)
{
    using ci::loadImage;
    using ci::app::loadAsset;
    return loadImage(loadAsset(Id));
}
Example #5
0
Vec2i Camera::GetSize() const { return Vec2i(m_HorizBounds.y, m_VertBounds.y); }
Example #6
0
ci::Rectf ToRect(const AABB Box)
{
    using ci::Rectf;
    return Rectf(Box.m_Center - Box.m_HalfSize, Box.m_Center + Box.m_HalfSize);
}