pixijs / pixi-projection

MIT License
191 stars 34 forks source link

How can I decide which diagonal to use ? #97

Open paganaye opened 3 years ago

paganaye commented 3 years ago

With pixi-projection we use square sprite, then inside the application transform it into two triangles. In my game half the time it looks all right and half the time it looks bad. How can I fix that. image

paganaye commented 3 years ago

I fixed it (badly) using this code. The question becomes: Is there a better way?

        const rightDiagonal = Math.abs(this.elevations.topRight - this.elevations.bottomLeft)
            <= Math.abs(this.elevations.topLeft - this.elevations.bottomRight);
        if (!rightDiagonal) {
            let tempX = vertexData2d[0];
            let tempY = vertexData2d[1];
            let tempZ = vertexData2d[2];
            vertexData2d[0] = vertexData2d[3];
            vertexData2d[1] = vertexData2d[4];
            vertexData2d[2] = vertexData2d[5];
            vertexData2d[3] = vertexData2d[6];
            vertexData2d[4] = vertexData2d[7];
            vertexData2d[5] = vertexData2d[8];
            vertexData2d[6] = vertexData2d[9];
            vertexData2d[7] = vertexData2d[10];
            vertexData2d[8] = vertexData2d[11];
            vertexData2d[9] = tempX;
            vertexData2d[10] = tempY;
            vertexData2d[11] = tempZ;
            this.rotation = - Math.PI / 2;
        } else {
            this.rotation = 0;
        }
ivanpopelyshev commented 3 years ago

The question is a bit wrong, we have to make actual quads, not triangles :) The whole point of Sprite2d is how to make weights ([2], [5], [8], [11]) so it actually becomes a projective quad and not two triangles.

paganaye commented 3 years ago

You're telling me I am a sprite abuser. Well you might be right, but I do with what I have. Perhaps I need a triangle primitive. This would allow me to have a different tint for each triangle. image

ivanpopelyshev commented 3 years ago

hm, interesting. Yeah, we might need mesh like this. Seriously, that's a mesh problem, mesh with 3 coords per vertex.