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