Updated copyright
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / TexturedRectangle.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  *
8  */
9
10 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
11
12 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
13 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
14 import eu.svjatoslav.sixth.e3d.math.Transform;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
18
19 public class TexturedRectangle extends AbstractCompositeShape {
20
21     public Point3D topLeft;
22     public Point3D topRight;
23     public Point3D bottomRight;
24     public Point3D bottomLeft;
25     public Point2D textureTopLeft;
26     public Point2D textureTopRight;
27     public Point2D textureBottomRight;
28     public Point2D textureBottomLeft;
29     private Texture texture;
30
31     public TexturedRectangle(final Transform transform) {
32         super(transform);
33     }
34
35     public TexturedRectangle(final Transform transform, final int width,
36                              final int height, final int maxTextureUpscale) {
37         this(transform, width, height, width, height, maxTextureUpscale);
38     }
39
40     public TexturedRectangle(final Transform transform, final int width,
41                              final int height, final int textureWidth, final int textureHeight,
42                              final int maxTextureUpscale) {
43
44         super(transform);
45
46         initialize(width, height, textureWidth, textureHeight,
47                 maxTextureUpscale);
48     }
49
50     public Texture getTexture() {
51         return texture;
52     }
53
54     public void initialize(final double width, final double height,
55                            final int textureWidth, final int textureHeight,
56                            final int maxTextureUpscale) {
57
58         topLeft = new Point3D(-width / 2, -height / 2, 0);
59         topRight = new Point3D(width / 2, -height / 2, 0);
60         bottomRight = new Point3D(width / 2, height / 2, 0);
61         bottomLeft = new Point3D(-width / 2, height / 2, 0);
62
63         texture = new Texture(textureWidth, textureHeight, maxTextureUpscale);
64
65         textureTopRight = new Point2D(textureWidth, 0);
66         textureTopLeft = new Point2D(0, 0);
67         textureBottomRight = new Point2D(textureWidth, textureHeight);
68         textureBottomLeft = new Point2D(0, textureHeight);
69
70         final TexturedPolygon texturedPolygon1 = new TexturedPolygon(topLeft,
71                 topRight, bottomRight, textureTopLeft, textureTopRight,
72                 textureBottomRight, texture);
73
74         texturedPolygon1
75                 .setMouseInteractionController(mouseInteractionController);
76
77         final TexturedPolygon texturedPolygon2 = new TexturedPolygon(topLeft,
78                 bottomLeft, bottomRight, textureTopLeft, textureBottomLeft,
79                 textureBottomRight, texture);
80
81         texturedPolygon2
82                 .setMouseInteractionController(mouseInteractionController);
83
84         addShape(texturedPolygon1);
85         addShape(texturedPolygon2);
86     }
87
88     public void initialize(final int width, final int height,
89                            final int maxTextureUpscale) {
90         initialize(width, height, width, height, maxTextureUpscale);
91     }
92
93 }