Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


#Actualbelfegor

Posted 19 May 2013 - 02:22 AM

I need to split window rectangle into multiple quads. I got this far but output is wrong and i can't see how to resolve it:

 

 

static const float quadDim = 200.0f;
 
        // dim is rect dimensions

        std::size_t horCnt  = (std::size_t)std::ceil(dim.x / quadDim);

        std::size_t vertCnt = (std::size_t)std::ceil(dim.y / quadDim);



        for(std::size_t i = 0; i < horCnt; ++i)

        {

            for(std::size_t j = 0; j < vertCnt; ++j)

            {

                float x = i * quadDim;

                float y = j * quadDim;



                float xx = std::fmod(x + quadDim, dim.x);

                float yy = std::fmod(y + quadDim, dim.y);



                D3DXVECTOR3 vertCoords[4];

                vertCoords[0] = D3DXVECTOR3(absPos.x + x,   absPos.y + y,  pos.z); // top left

                vertCoords[1] = D3DXVECTOR3(absPos.x + xx,  absPos.y + y,  pos.z); // top right

                vertCoords[2] = D3DXVECTOR3(absPos.x + xx,  absPos.y + yy, pos.z); // bottom left

                vertCoords[3] = D3DXVECTOR3(absPos.x + x,   absPos.y + yy, pos.z); // bottom right



                float r = float(i + 1) * (1.0f / float(horCnt));

                float g = float(j + 1) * (1.0f / float(vertCnt));

                D3DXVECTOR4 newColor( r, g, (r+g) * 0.5f, 1.0f); // debug color



                drawer->addVertex(Vertex(vertCoords[0], texCoords[0], newColor)); // top left

                drawer->addVertex(Vertex(vertCoords[1], texCoords[1], newColor)); // top right

                drawer->addVertex(Vertex(vertCoords[2], texCoords[2], newColor)); // bottom right

                drawer->addVertex(Vertex(vertCoords[3], texCoords[3], newColor)); // bottom left

            }

        }

 

quads.jpg

 

If you need more info please tell.

 

Thank you for your time.

 

EDIT:

Looks like i solved the vertex coords:

 

quads.jpg

 

float x = i * quadDim;
                float y = j * quadDim;

                float xx = std::fmod( x + quadDim, dim.x);
                float yy = std::fmod( y + quadDim, dim.y);

                xx = (xx < quadDim) ? (quadDim - xx) + x : xx;
                yy = (yy < quadDim) ? (quadDim - yy) + y : yy;

 

 

Now i have trouble with calculating texcoords:

quads2.jpg

 

float xint, xfrac, yint, yfrac;
                xfrac = std::modf((xx - x) / quadDim, &xint);
                yfrac = std::modf((yy - y) / quadDim, &yint);

                D3DXVECTOR2 texCoords[4];
                texCoords[0] = D3DXVECTOR2(0.0f,                  0.5f);
                texCoords[1] = D3DXVECTOR2(0.5f * (1.0f - xfrac), 0.5f);
                texCoords[2] = D3DXVECTOR2(0.5f * (1.0f - xfrac), 1.0f * (1.0f - yfrac));
                texCoords[3] = D3DXVECTOR2(0.0f,                  1.0f * (1.0f - yfrac));

 

 

I am using bottom left quarter of texture because it contains the component that i need to display on quads. Looks like only bottom (y) is wrong.


#4belfegor

Posted 19 May 2013 - 02:20 AM

I need to split window rectangle into multiple quads. I got this far but output is wrong and i can't see how to resolve it:

 

 

static const float quadDim = 200.0f;
 
        // dim is rect dimensions

        std::size_t horCnt  = (std::size_t)std::ceil(dim.x / quadDim);

        std::size_t vertCnt = (std::size_t)std::ceil(dim.y / quadDim);



        for(std::size_t i = 0; i < horCnt; ++i)

        {

            for(std::size_t j = 0; j < vertCnt; ++j)

            {

                float x = i * quadDim;

                float y = j * quadDim;



                float xx = std::fmod(x + quadDim, dim.x);

                float yy = std::fmod(y + quadDim, dim.y);



                D3DXVECTOR3 vertCoords[4];

                vertCoords[0] = D3DXVECTOR3(absPos.x + x,   absPos.y + y,  pos.z); // top left

                vertCoords[1] = D3DXVECTOR3(absPos.x + xx,  absPos.y + y,  pos.z); // top right

                vertCoords[2] = D3DXVECTOR3(absPos.x + xx,  absPos.y + yy, pos.z); // bottom left

                vertCoords[3] = D3DXVECTOR3(absPos.x + x,   absPos.y + yy, pos.z); // bottom right



                float r = float(i + 1) * (1.0f / float(horCnt));

                float g = float(j + 1) * (1.0f / float(vertCnt));

                D3DXVECTOR4 newColor( r, g, (r+g) * 0.5f, 1.0f); // debug color



                drawer->addVertex(Vertex(vertCoords[0], texCoords[0], newColor)); // top left

                drawer->addVertex(Vertex(vertCoords[1], texCoords[1], newColor)); // top right

                drawer->addVertex(Vertex(vertCoords[2], texCoords[2], newColor)); // bottom right

                drawer->addVertex(Vertex(vertCoords[3], texCoords[3], newColor)); // bottom left

            }

        }

 

quads.jpg

 

If you need more info please tell.

 

Thank you for your time.

 

EDIT:

Looks like i solved the vertex coords:

 

quads.jpg

 

 

float x = i * quadDim;
                float y = j * quadDim;

                float xx = std::fmod( x + quadDim, dim.x);
                float yy = std::fmod( y + quadDim, dim.y);

                xx = (xx < quadDim) ? (quadDim - xx) + x : xx;
                yy = (yy < quadDim) ? (quadDim - yy) + y : yy;
[/code]
 
Now i have trouble with calculating texcoords:
 
[img]http://www.dodaj.rs/f/1L/B6/3pZMLXzv/quads2.jpg[/img]
 
In same loop:
[code]
float xint, xfrac, yint, yfrac;
                xfrac = std::modf((xx - x) / quadDim, &xint);
                yfrac = std::modf((yy - y) / quadDim, &yint);

                D3DXVECTOR2 texCoords[4];
                texCoords[0] = D3DXVECTOR2(0.0f,                  0.5f);
                texCoords[1] = D3DXVECTOR2(0.5f * (1.0f - xfrac), 0.5f);
                texCoords[2] = D3DXVECTOR2(0.5f * (1.0f - xfrac), 1.0f * (1.0f - yfrac));
                texCoords[3] = D3DXVECTOR2(0.0f,                  1.0f * (1.0f - yfrac));

I am using bottom left quarter of texture because it contains the component that i need to display on quads. Looks like only bottom (y) is wrong.


#3belfegor

Posted 19 May 2013 - 02:20 AM

I need to split window rectangle into multiple quads. I got this far but output is wrong and i can't see how to resolve it:

 

 

static const float quadDim = 200.0f;
 
        // dim is rect dimensions

        std::size_t horCnt  = (std::size_t)std::ceil(dim.x / quadDim);

        std::size_t vertCnt = (std::size_t)std::ceil(dim.y / quadDim);



        for(std::size_t i = 0; i < horCnt; ++i)

        {

            for(std::size_t j = 0; j < vertCnt; ++j)

            {

                float x = i * quadDim;

                float y = j * quadDim;



                float xx = std::fmod(x + quadDim, dim.x);

                float yy = std::fmod(y + quadDim, dim.y);



                D3DXVECTOR3 vertCoords[4];

                vertCoords[0] = D3DXVECTOR3(absPos.x + x,   absPos.y + y,  pos.z); // top left

                vertCoords[1] = D3DXVECTOR3(absPos.x + xx,  absPos.y + y,  pos.z); // top right

                vertCoords[2] = D3DXVECTOR3(absPos.x + xx,  absPos.y + yy, pos.z); // bottom left

                vertCoords[3] = D3DXVECTOR3(absPos.x + x,   absPos.y + yy, pos.z); // bottom right



                float r = float(i + 1) * (1.0f / float(horCnt));

                float g = float(j + 1) * (1.0f / float(vertCnt));

                D3DXVECTOR4 newColor( r, g, (r+g) * 0.5f, 1.0f); // debug color



                drawer->addVertex(Vertex(vertCoords[0], texCoords[0], newColor)); // top left

                drawer->addVertex(Vertex(vertCoords[1], texCoords[1], newColor)); // top right

                drawer->addVertex(Vertex(vertCoords[2], texCoords[2], newColor)); // bottom right

                drawer->addVertex(Vertex(vertCoords[3], texCoords[3], newColor)); // bottom left

            }

        }

 

quads.jpg

 

If you need more info please tell.

 

Thank you for your time.

 

EDIT:

Looks like i solved the vertex coords:

 

quads.jpg

 

 

float x = i * quadDim;
                float y = j * quadDim;

                float xx = std::fmod( x + quadDim, dim.x);
                float yy = std::fmod( y + quadDim, dim.y);

                xx = (xx < quadDim) ? (quadDim - xx) + x : xx;
                yy = (yy < quadDim) ? (quadDim - yy) + y : yy;
[code]
 
Now i have trouble with calculating texcoords:
 
[img]http://www.dodaj.rs/f/1L/B6/3pZMLXzv/quads2.jpg[/img]
 
In same loop:
[code]
float xint, xfrac, yint, yfrac;
                xfrac = std::modf((xx - x) / quadDim, &xint);
                yfrac = std::modf((yy - y) / quadDim, &yint);

                D3DXVECTOR2 texCoords[4];
                texCoords[0] = D3DXVECTOR2(0.0f,                  0.5f);
                texCoords[1] = D3DXVECTOR2(0.5f * (1.0f - xfrac), 0.5f);
                texCoords[2] = D3DXVECTOR2(0.5f * (1.0f - xfrac), 1.0f * (1.0f - yfrac));
                texCoords[3] = D3DXVECTOR2(0.0f,                  1.0f * (1.0f - yfrac));

I am using bottom left quarter of texture because it contains the component that i need to display on quads. Looks like only bottom (y) is wrong.


#2belfegor

Posted 19 May 2013 - 02:19 AM

I need to split window rectangle into multiple quads. I got this far but output is wrong and i can't see how to resolve it:

 

 

static const float quadDim = 200.0f;
 
        // dim is rect dimensions

        std::size_t horCnt  = (std::size_t)std::ceil(dim.x / quadDim);

        std::size_t vertCnt = (std::size_t)std::ceil(dim.y / quadDim);



        for(std::size_t i = 0; i < horCnt; ++i)

        {

            for(std::size_t j = 0; j < vertCnt; ++j)

            {

                float x = i * quadDim;

                float y = j * quadDim;



                float xx = std::fmod(x + quadDim, dim.x);

                float yy = std::fmod(y + quadDim, dim.y);



                D3DXVECTOR3 vertCoords[4];

                vertCoords[0] = D3DXVECTOR3(absPos.x + x,   absPos.y + y,  pos.z); // top left

                vertCoords[1] = D3DXVECTOR3(absPos.x + xx,  absPos.y + y,  pos.z); // top right

                vertCoords[2] = D3DXVECTOR3(absPos.x + xx,  absPos.y + yy, pos.z); // bottom left

                vertCoords[3] = D3DXVECTOR3(absPos.x + x,   absPos.y + yy, pos.z); // bottom right



                float r = float(i + 1) * (1.0f / float(horCnt));

                float g = float(j + 1) * (1.0f / float(vertCnt));

                D3DXVECTOR4 newColor( r, g, (r+g) * 0.5f, 1.0f); // debug color



                drawer->addVertex(Vertex(vertCoords[0], texCoords[0], newColor)); // top left

                drawer->addVertex(Vertex(vertCoords[1], texCoords[1], newColor)); // top right

                drawer->addVertex(Vertex(vertCoords[2], texCoords[2], newColor)); // bottom right

                drawer->addVertex(Vertex(vertCoords[3], texCoords[3], newColor)); // bottom left

            }

        }

 

quads.jpg

 

If you need more info please tell.

 

Thank you for your time.

 

Looks like i solved the vertex coords:

 

quads.jpg

 

float x = i * quadDim;
                float y = j * quadDim;

                float xx = std::fmod( x + quadDim, dim.x);
                float yy = std::fmod( y + quadDim, dim.y);

                xx = (xx < quadDim) ? (quadDim - xx) + x : xx;
                yy = (yy < quadDim) ? (quadDim - yy) + y : yy;
[code]
 
Now i have trouble with calculating texcoords:
 
[img]http://www.dodaj.rs/f/1L/B6/3pZMLXzv/quads2.jpg[/img]
 
In same loop:
[code]
float xint, xfrac, yint, yfrac;
                xfrac = std::modf((xx - x) / quadDim, &xint);
                yfrac = std::modf((yy - y) / quadDim, &yint);

                D3DXVECTOR2 texCoords[4];
                texCoords[0] = D3DXVECTOR2(0.0f,                  0.5f);
                texCoords[1] = D3DXVECTOR2(0.5f * (1.0f - xfrac), 0.5f);
                texCoords[2] = D3DXVECTOR2(0.5f * (1.0f - xfrac), 1.0f * (1.0f - yfrac));
                texCoords[3] = D3DXVECTOR2(0.0f,                  1.0f * (1.0f - yfrac));

I am using bottom left quarter of texture because it contains the component that i need to display on quads. Looks like only bottom (y) is wrong.


#1belfegor

Posted 19 May 2013 - 01:45 AM

I need to split window rectangle into multiple quads. I got this far but output is wrong and i can't see how to resolve it:

 

static const float quadDim = 200.0f;
 
        // dim is rect dimensions

        std::size_t horCnt  = (std::size_t)std::ceil(dim.x / quadDim);

        std::size_t vertCnt = (std::size_t)std::ceil(dim.y / quadDim);



        for(std::size_t i = 0; i < horCnt; ++i)

        {

            for(std::size_t j = 0; j < vertCnt; ++j)

            {

                float x = i * quadDim;

                float y = j * quadDim;



                float xx = std::fmod(x + quadDim, dim.x);

                float yy = std::fmod(y + quadDim, dim.y);



                D3DXVECTOR3 vertCoords[4];

                vertCoords[0] = D3DXVECTOR3(absPos.x + x,   absPos.y + y,  pos.z); // top left

                vertCoords[1] = D3DXVECTOR3(absPos.x + xx,  absPos.y + y,  pos.z); // top right

                vertCoords[2] = D3DXVECTOR3(absPos.x + xx,  absPos.y + yy, pos.z); // bottom left

                vertCoords[3] = D3DXVECTOR3(absPos.x + x,   absPos.y + yy, pos.z); // bottom right



                float r = float(i + 1) * (1.0f / float(horCnt));

                float g = float(j + 1) * (1.0f / float(vertCnt));

                D3DXVECTOR4 newColor( r, g, (r+g) * 0.5f, 1.0f); // debug color



                drawer->addVertex(Vertex(vertCoords[0], texCoords[0], newColor)); // top left

                drawer->addVertex(Vertex(vertCoords[1], texCoords[1], newColor)); // top right

                drawer->addVertex(Vertex(vertCoords[2], texCoords[2], newColor)); // bottom right

                drawer->addVertex(Vertex(vertCoords[3], texCoords[3], newColor)); // bottom left

            }

        }

 

quads.jpg

 

If you need more info please tell.

 

Thank you for your time.


PARTNERS