Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add homography to textures #9

Open
barelief opened this issue Apr 3, 2016 · 4 comments
Open

add homography to textures #9

barelief opened this issue Apr 3, 2016 · 4 comments
Assignees

Comments

@barelief
Copy link
Owner

barelief commented Apr 3, 2016

No description provided.

@barelief barelief self-assigned this Apr 3, 2016
@barelief barelief added this to the Create a library milestone Apr 3, 2016
@barelief
Copy link
Owner Author

barelief commented Apr 3, 2016

check this one http://keystonep5.sourceforge.net/

@barelief
Copy link
Owner Author

barelief commented Apr 3, 2016

check thi method from CornerPinSurface.java:

    public void render(PGraphics g, PImage texture, int tX, int tY, int tW,
            int tH) {
        g.pushMatrix();
        g.translate(x, y);
        if (Keystone.calibrate)
            g.stroke(gridColor);
        else
            g.noStroke();
        g.fill(255);
        g.beginShape(PApplet.QUADS);
        g.texture(texture);
        float u, v = 0;
        for (int x = 0; x < res - 1; x++) {
            for (int y = 0; y < res - 1; y++) {
                MeshPoint mp;
                mp = mesh[(x) + (y) * res];
                u = PApplet.map(mp.u, 0, w, tX, tX + tW);
                v = PApplet.map(mp.v, 0, h, tY, tY + tH);
                g.vertex(mp.x, mp.y, u, v);
                mp = mesh[(x + 1) + (y) * res];
                u = PApplet.map(mp.u, 0, w, tX, tX + tW);
                v = PApplet.map(mp.v, 0, h, tY, tY + tH);
                g.vertex(mp.x, mp.y, u, v);
                mp = mesh[(x + 1) + (y + 1) * res];
                u = PApplet.map(mp.u, 0, w, tX, tX + tW);
                v = PApplet.map(mp.v, 0, h, tY, tY + tH);
                g.vertex(mp.x, mp.y, u, v);
                mp = mesh[(x) + (y + 1) * res];
                u = PApplet.map(mp.u, 0, w, tX, tX + tW);
                v = PApplet.map(mp.v, 0, h, tY, tY + tH);
                g.vertex(mp.x, mp.y, u, v);
            }
        }
        g.endShape(PApplet.CLOSE);

        if (Keystone.calibrate)
            renderControlPoints(g);

        g.popMatrix();
    }

@barelief barelief modified the milestones: Library development, Create a library Apr 11, 2016
@barelief
Copy link
Owner Author

    /**
     * 
     * setup of interpolation grid points
     */
    private void setInterpolatedgrid() {
        A = new PVector(0, 0);
        B = new PVector(0, 0);
        C = new PVector(0, 0);
        D = new PVector(0, 0);
        A_ = new PVector(0, 0);
        C_ = new PVector(0, 0);
        O = new PVector(0, 0); // final point
    }

    /**
     * grid interpolation: map corner points before warping matrix points
     * 
     */
    public void interpolateGrid() {
        float n = gridRes + 0.0f;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                A_.x = PApplet.lerp(A.x, B.x, i / n);
                A_.y = PApplet.lerp(A.y, B.y, i / n);
                // ellipse(A_.x, A_.y, 10, 10);

                C_.x = PApplet.lerp(C.x, D.x, i / n);
                C_.y = PApplet.lerp(C.y, D.y, i / n);

                O.x = PApplet.lerp(A_.x, C_.x, j / n);
                O.y = PApplet.lerp(A_.y, C_.y, j / n);

                coords[i][j] = new PVector(O.x, O.y);

            }
        }
    }

@barelief
Copy link
Owner Author

public void render(PImage img) {
        myParent.noStroke();
        for (int i = 0; i < gridRes; i++) {
            for (int j = 0; j < gridRes; j++) {
                if (spritesON == 1)
                    myParent.stroke(50, 255, 0);
                if (giON == true)
                    myParent.stroke(150);
                myParent.beginShape();
                myParent.texture(img);
                myParent.vertex(coords[i][j].x, coords[i][j].y,
                        ((float) i / gridRes) * img.width,
                        ((float) j / gridRes) * img.height);
                myParent.vertex(coords[i + 1][j].x, coords[i + 1][j].y,
                        (((float) i + 1) / gridRes) * img.width,
                        ((float) j / gridRes) * img.height);
                myParent.vertex(coords[i + 1][j + 1].x, coords[i + 1][j + 1].y,
                        (((float) i + 1) / gridRes) * img.width,
                        (((float) j + 1) / gridRes) * img.height);
                myParent.vertex(coords[i][j + 1].x, coords[i][j + 1].y,
                        ((float) i / gridRes) * img.width,
                        (((float) j + 1) / gridRes) * img.height);

                myParent.endShape();
                // myParent.fill(255);
                // myParent.ellipse(coords[i][j].x, coords[i][j].y, 100, 100);
            }
        }
        sprites();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant