2 * Sixth 3D engine. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
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.
10 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
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;
19 public class TexturedRectangle extends AbstractCompositeShape {
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;
31 public TexturedRectangle(final Transform transform) {
35 public TexturedRectangle(final Transform transform, final int width,
36 final int height, final int maxTextureUpscale) {
37 this(transform, width, height, width, height, maxTextureUpscale);
40 public TexturedRectangle(final Transform transform, final int width,
41 final int height, final int textureWidth, final int textureHeight,
42 final int maxTextureUpscale) {
46 initialize(width, height, textureWidth, textureHeight,
50 public Texture getTexture() {
54 public void initialize(final double width, final double height,
55 final int textureWidth, final int textureHeight,
56 final int maxTextureUpscale) {
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);
63 texture = new Texture(textureWidth, textureHeight, maxTextureUpscale);
65 textureTopRight = new Point2D(textureWidth, 0);
66 textureTopLeft = new Point2D(0, 0);
67 textureBottomRight = new Point2D(textureWidth, textureHeight);
68 textureBottomLeft = new Point2D(0, textureHeight);
70 final TexturedPolygon texturedPolygon1 = new TexturedPolygon(topLeft,
71 topRight, bottomRight, textureTopLeft, textureTopRight,
72 textureBottomRight, texture);
75 .setMouseInteractionController(mouseInteractionController);
77 final TexturedPolygon texturedPolygon2 = new TexturedPolygon(topLeft,
78 bottomLeft, bottomRight, textureTopLeft, textureBottomLeft,
79 textureBottomRight, texture);
82 .setMouseInteractionController(mouseInteractionController);
84 addShape(texturedPolygon1);
85 addShape(texturedPolygon2);
88 public void initialize(final int width, final int height,
89 final int maxTextureUpscale) {
90 initialize(width, height, width, height, maxTextureUpscale);