What I currently have: Generating of texture coordinates given the width and height of a rectanlge along with a scale factor for the texture. this is woking fine:
vertices = new float[] {
0, 0, 0, this.height / (this.texture.height * this.texScaleHeight),
this.width, 0, this.width / (this.texture.width * this.texScaleWidth), height / (this.texture.height * this.texScaleHeight),
this.width, this.height, this.width / (this.texture.width * this.texScaleWidth), 0,
0, this.height, 0, 0 };
What I want to do now, is that some rectangles with different positions (ie. next to each other) have a seamless graduation for the textures. I tried the following but with no good result.
vertices = new float[] {
0, 0, -this.getPosition().x * this.texScaleWidth, this.height / (this.texture.height * this.texScaleHeight) -this.getPosition().y * this.texScaleHeight,
this.width, 0, this.width / (this.texture.width * this.texScaleWidth) -this.getPosition().x * this.texScaleWidth, height / (this.texture.height * this.texScaleHeight)-this.getPosition().y * this.texScaleHeight,
this.width, this.height, this.width / (this.texture.width * this.texScaleWidth) -this.getPosition().x * this.texScaleWidth, -this.getPosition().y * this.texScaleHeight,
0, this.height, -this.getPosition().x * this.texScaleWidth, -this.getPosition().y * this.texScaleHeight };
How can i achieve that textures are “aligned to the world” and not to the rectangle they sit on?
This technique is potentially way too general, but here it goes: You could project the texture coordinates onto the geometry.
The overall workflow is just the same as handling geometry itself, but here, all world points are assigned texture coordinates. Push every point in the geometry through another MVP matrix (representing the projector) and take the
(x, y)result for the texture coordinate of this very point (assuming orthographic projection); perspective requires division bywafterwards.I hope you get the idea. Searching for it, I failed to find a decent description or tutorial. Shadow mapping uses the same technique, but its goal is to determine whether a point is shadowed or not; here, the goal is to find texture coordinates for a general projector.