2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
7 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
8 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
9 import eu.svjatoslav.sixth.e3d.math.Transform;
10 import eu.svjatoslav.sixth.e3d.math.Vertex;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
15 public class TexturedRectangle extends AbstractCompositeShape {
17 public Point3D topLeft;
18 public Point3D topRight;
19 public Point3D bottomRight;
20 public Point3D bottomLeft;
21 public Point2D textureTopLeft;
22 public Point2D textureTopRight;
23 public Point2D textureBottomRight;
24 public Point2D textureBottomLeft;
25 private Texture texture;
27 public TexturedRectangle(final Transform transform) {
31 public TexturedRectangle(final Transform transform, final int width,
32 final int height, final int maxTextureUpscale) {
33 this(transform, width, height, width, height, maxTextureUpscale);
36 public TexturedRectangle(final Transform transform, final int width,
37 final int height, final int textureWidth, final int textureHeight,
38 final int maxTextureUpscale) {
42 initialize(width, height, textureWidth, textureHeight,
46 public Texture getTexture() {
50 public void initialize(final double width, final double height,
51 final int textureWidth, final int textureHeight,
52 final int maxTextureUpscale) {
54 topLeft = new Point3D(-width / 2, -height / 2, 0);
55 topRight = new Point3D(width / 2, -height / 2, 0);
56 bottomRight = new Point3D(width / 2, height / 2, 0);
57 bottomLeft = new Point3D(-width / 2, height / 2, 0);
59 texture = new Texture(textureWidth, textureHeight, maxTextureUpscale);
61 textureTopRight = new Point2D(textureWidth, 0);
62 textureTopLeft = new Point2D(0, 0);
63 textureBottomRight = new Point2D(textureWidth, textureHeight);
64 textureBottomLeft = new Point2D(0, textureHeight);
69 final TexturedPolygon texturedPolygon1 = new TexturedPolygon(
70 new Vertex(topLeft, textureTopLeft),
71 new Vertex(topRight, textureTopRight),
72 new Vertex(bottomRight, textureBottomRight), texture);
75 .setMouseInteractionController(mouseInteractionController);
77 final TexturedPolygon texturedPolygon2 = new TexturedPolygon(
78 new Vertex(topLeft, textureTopLeft),
79 new Vertex(bottomLeft, textureBottomLeft),
80 new Vertex(bottomRight, textureBottomRight), texture);
83 .setMouseInteractionController(mouseInteractionController);
85 addShape(texturedPolygon1);
86 addShape(texturedPolygon2);
89 // public void initialize(final int width, final int height,
90 // final int maxTextureUpscale) {
91 // initialize(width, height, width, height, maxTextureUpscale);