Changed license to Creative Commons Zero (CC0).
[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 *
6  */
7
8 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
9
10 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
11 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
12 import eu.svjatoslav.sixth.e3d.math.Transform;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
16
17 public class TexturedRectangle extends AbstractCompositeShape {
18
19     public Point3D topLeft;
20     public Point3D topRight;
21     public Point3D bottomRight;
22     public Point3D bottomLeft;
23     public Point2D textureTopLeft;
24     public Point2D textureTopRight;
25     public Point2D textureBottomRight;
26     public Point2D textureBottomLeft;
27     private Texture texture;
28
29     public TexturedRectangle(final Transform transform) {
30         super(transform);
31     }
32
33     public TexturedRectangle(final Transform transform, final int width,
34                              final int height, final int maxTextureUpscale) {
35         this(transform, width, height, width, height, maxTextureUpscale);
36     }
37
38     public TexturedRectangle(final Transform transform, final int width,
39                              final int height, final int textureWidth, final int textureHeight,
40                              final int maxTextureUpscale) {
41
42         super(transform);
43
44         initialize(width, height, textureWidth, textureHeight,
45                 maxTextureUpscale);
46     }
47
48     public Texture getTexture() {
49         return texture;
50     }
51
52     public void initialize(final double width, final double height,
53                            final int textureWidth, final int textureHeight,
54                            final int maxTextureUpscale) {
55
56         topLeft = new Point3D(-width / 2, -height / 2, 0);
57         topRight = new Point3D(width / 2, -height / 2, 0);
58         bottomRight = new Point3D(width / 2, height / 2, 0);
59         bottomLeft = new Point3D(-width / 2, height / 2, 0);
60
61         texture = new Texture(textureWidth, textureHeight, maxTextureUpscale);
62
63         textureTopRight = new Point2D(textureWidth, 0);
64         textureTopLeft = new Point2D(0, 0);
65         textureBottomRight = new Point2D(textureWidth, textureHeight);
66         textureBottomLeft = new Point2D(0, textureHeight);
67
68         final TexturedPolygon texturedPolygon1 = new TexturedPolygon(topLeft,
69                 topRight, bottomRight, textureTopLeft, textureTopRight,
70                 textureBottomRight, texture);
71
72         texturedPolygon1
73                 .setMouseInteractionController(mouseInteractionController);
74
75         final TexturedPolygon texturedPolygon2 = new TexturedPolygon(topLeft,
76                 bottomLeft, bottomRight, textureTopLeft, textureBottomLeft,
77                 textureBottomRight, texture);
78
79         texturedPolygon2
80                 .setMouseInteractionController(mouseInteractionController);
81
82         addShape(texturedPolygon1);
83         addShape(texturedPolygon2);
84     }
85
86     public void initialize(final int width, final int height,
87                            final int maxTextureUpscale) {
88         initialize(width, height, width, height, maxTextureUpscale);
89     }
90
91 }