2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
8 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
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;
17 public class TexturedRectangle extends AbstractCompositeShape {
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;
29 public TexturedRectangle(final Transform transform) {
33 public TexturedRectangle(final Transform transform, final int width,
34 final int height, final int maxTextureUpscale) {
35 this(transform, width, height, width, height, maxTextureUpscale);
38 public TexturedRectangle(final Transform transform, final int width,
39 final int height, final int textureWidth, final int textureHeight,
40 final int maxTextureUpscale) {
44 initialize(width, height, textureWidth, textureHeight,
48 public Texture getTexture() {
52 public void initialize(final double width, final double height,
53 final int textureWidth, final int textureHeight,
54 final int maxTextureUpscale) {
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);
61 texture = new Texture(textureWidth, textureHeight, maxTextureUpscale);
63 textureTopRight = new Point2D(textureWidth, 0);
64 textureTopLeft = new Point2D(0, 0);
65 textureBottomRight = new Point2D(textureWidth, textureHeight);
66 textureBottomLeft = new Point2D(0, textureHeight);
68 final TexturedPolygon texturedPolygon1 = new TexturedPolygon(topLeft,
69 topRight, bottomRight, textureTopLeft, textureTopRight,
70 textureBottomRight, texture);
73 .setMouseInteractionController(mouseInteractionController);
75 final TexturedPolygon texturedPolygon2 = new TexturedPolygon(topLeft,
76 bottomLeft, bottomRight, textureTopLeft, textureBottomLeft,
77 textureBottomRight, texture);
80 .setMouseInteractionController(mouseInteractionController);
82 addShape(texturedPolygon1);
83 addShape(texturedPolygon2);
86 public void initialize(final int width, final int height,
87 final int maxTextureUpscale) {
88 initialize(width, height, width, height, maxTextureUpscale);