Fixed git clone URL
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / TexturedRectangle.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko.
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
6
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;
14
15 public class TexturedRectangle extends AbstractCompositeShape {
16
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;
26
27     public TexturedRectangle(final Transform transform) {
28         super(transform);
29     }
30
31     public TexturedRectangle(final Transform transform, final int width,
32                              final int height, final int maxTextureUpscale) {
33         this(transform, width, height, width, height, maxTextureUpscale);
34     }
35
36     public TexturedRectangle(final Transform transform, final int width,
37                              final int height, final int textureWidth, final int textureHeight,
38                              final int maxTextureUpscale) {
39
40         super(transform);
41
42         initialize(width, height, textureWidth, textureHeight,
43                 maxTextureUpscale);
44     }
45
46     public Texture getTexture() {
47         return texture;
48     }
49
50     public void initialize(final double width, final double height,
51                            final int textureWidth, final int textureHeight,
52                            final int maxTextureUpscale) {
53
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);
58
59         texture = new Texture(textureWidth, textureHeight, maxTextureUpscale);
60
61         textureTopRight = new Point2D(textureWidth, 0);
62         textureTopLeft = new Point2D(0, 0);
63         textureBottomRight = new Point2D(textureWidth, textureHeight);
64         textureBottomLeft = new Point2D(0, textureHeight);
65
66
67
68
69         final TexturedPolygon texturedPolygon1 = new TexturedPolygon(
70                 new Vertex(topLeft, textureTopLeft),
71                 new Vertex(topRight, textureTopRight),
72                 new Vertex(bottomRight, textureBottomRight), texture);
73
74         texturedPolygon1
75                 .setMouseInteractionController(mouseInteractionController);
76
77         final TexturedPolygon texturedPolygon2 = new TexturedPolygon(
78                 new Vertex(topLeft, textureTopLeft),
79                 new Vertex(bottomLeft, textureBottomLeft),
80                 new Vertex(bottomRight, textureBottomRight), texture);
81
82         texturedPolygon2
83                 .setMouseInteractionController(mouseInteractionController);
84
85         addShape(texturedPolygon1);
86         addShape(texturedPolygon2);
87     }
88
89 //    public void initialize(final int width, final int height,
90 //                           final int maxTextureUpscale) {
91 //        initialize(width, height, width, height, maxTextureUpscale);
92 //    }
93
94 }