Class Decal


  • public class Decal
    extends java.lang.Object

    Represents a sprite in 3d space. Typical 3d transformations such as translation, rotation and scaling are supported. The position includes a z component other than setting the depth no manual layering has to be performed, correct overlay is guaranteed by using the depth buffer.

    Decals are handled by the DecalBatch.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Color getColor()
      Returns the color of this decal.
      float getHeight()  
      DecalMaterial getMaterial()  
      Vector3 getPosition()
      Returns the position of this decal.
      Quaternion getRotation()
      Returns the rotation.
      float getScaleX()  
      float getScaleY()  
      TextureRegion getTextureRegion()  
      float[] getVertices()
      Returns the vertices backing this sprite.
      The returned value should under no circumstances be modified.
      float getWidth()  
      float getX()  
      float getY()  
      float getZ()  
      void lookAt​(Vector3 position, Vector3 up)
      Sets the rotation of the Decal to face the given point.
      static Decal newDecal​(float width, float height, TextureRegion textureRegion)
      Creates a decal using the region for texturing
      static Decal newDecal​(float width, float height, TextureRegion textureRegion, boolean hasTransparency)
      Creates a decal using the region for texturing
      static Decal newDecal​(float width, float height, TextureRegion textureRegion, int srcBlendFactor, int dstBlendFactor)
      Creates a decal using the region for texturing and the specified blending parameters for blending
      static Decal newDecal​(float width, float height, TextureRegion textureRegion, int srcBlendFactor, int dstBlendFactor, DecalMaterial material)
      Creates a decal using the region for texturing and the specified blending parameters for blending
      static Decal newDecal​(TextureRegion textureRegion)
      Creates a decal assuming the dimensions of the texture region
      static Decal newDecal​(TextureRegion textureRegion, boolean hasTransparency)
      Creates a decal assuming the dimensions of the texture region and adding transparency
      protected void resetVertices()
      Resets the position components of the vertices array based ont he dimensions (preparation for transformation)
      void rotateX​(float angle)
      Rotates along local X axis by the specified angle
      void rotateY​(float angle)
      Rotates along local Y axis by the specified angle
      void rotateZ​(float angle)
      Rotates along local Z axis by the specified angle
      void setBlending​(int srcBlendFactor, int dstBlendFactor)
      Sets the blending parameters for this decal
      void setColor​(float r, float g, float b, float a)
      Sets the color of all four vertices to the specified color
      void setColor​(Color tint)
      Sets the color used to tint this decal.
      void setDimensions​(float width, float height)
      Sets the width and height in world units
      void setHeight​(float height)
      Sets the height in world units
      void setMaterial​(DecalMaterial material)
      Set material
      void setPackedColor​(float color)
      Sets the color of this decal, expanding the alpha from 0-254 to 0-255.
      void setPosition​(float x, float y, float z)
      Sets the position to the given world coordinates
      void setPosition​(Vector3 pos)  
      void setRotation​(float yaw, float pitch, float roll)
      Sets the rotation of this decal to the given angles on all axes.
      void setRotation​(Quaternion q)
      Sets the rotation of this decal based on the provided Quaternion
      void setRotation​(Vector3 dir, Vector3 up)
      Sets the rotation of this decal based on the (normalized) direction and up vector.
      void setRotationX​(float angle)
      Sets the rotation on the local X axis to the specified angle
      void setRotationY​(float angle)
      Sets the rotation on the local Y axis to the specified angle
      void setRotationZ​(float angle)
      Sets the rotation on the local Z axis to the specified angle
      void setScale​(float scale)
      Sets scale along both the x and y axis
      void setScale​(float scaleX, float scaleY)
      Sets scale along both the x and y axis
      void setScaleX​(float scale)
      Sets scale along the x axis
      void setScaleY​(float scale)
      Sets scale along the y axis
      void setTextureRegion​(TextureRegion textureRegion)
      Sets the texture region
      void setWidth​(float width)
      Sets the width in world units
      void setX​(float x)
      Sets the position on the x axis
      void setY​(float y)
      Sets the position on the y axis
      void setZ​(float z)
      Sets the position on the z axis
      protected void transformVertices()
      Transforms the position component of the vertices using properties such as position, scale, etc.
      void translate​(float x, float y, float z)
      Translates by the specified amount of units
      void translate​(Vector3 trans)  
      void translateX​(float units)
      Moves by the specified amount of units along the x axis
      void translateY​(float units)
      Moves by the specified amount of units along the y axis
      void translateZ​(float units)
      Moves by the specified amount of units along the z axis
      protected void update()
      Recalculates vertices array if it grew out of sync with the properties (position, ..)
      protected void updateUVs()
      Re-applies the uv coordinates from the material's texture region to the uv components of the vertices array
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Decal

        public Decal()
    • Method Detail

      • setColor

        public void setColor​(float r,
                             float g,
                             float b,
                             float a)
        Sets the color of all four vertices to the specified color
        Parameters:
        r - Red component
        g - Green component
        b - Blue component
        a - Alpha component
      • setColor

        public void setColor​(Color tint)
        Sets the color used to tint this decal. Default is Color.WHITE.
      • setPackedColor

        public void setPackedColor​(float color)
        Sets the color of this decal, expanding the alpha from 0-254 to 0-255.
        See Also:
        setColor(Color)
      • setRotationX

        public void setRotationX​(float angle)
        Sets the rotation on the local X axis to the specified angle
        Parameters:
        angle - Angle in degrees to set rotation to
      • setRotationY

        public void setRotationY​(float angle)
        Sets the rotation on the local Y axis to the specified angle
        Parameters:
        angle - Angle in degrees to set rotation to
      • setRotationZ

        public void setRotationZ​(float angle)
        Sets the rotation on the local Z axis to the specified angle
        Parameters:
        angle - Angle in degrees to set rotation to
      • rotateX

        public void rotateX​(float angle)
        Rotates along local X axis by the specified angle
        Parameters:
        angle - Angle in degrees to rotate by
      • rotateY

        public void rotateY​(float angle)
        Rotates along local Y axis by the specified angle
        Parameters:
        angle - Angle in degrees to rotate by
      • rotateZ

        public void rotateZ​(float angle)
        Rotates along local Z axis by the specified angle
        Parameters:
        angle - Angle in degrees to rotate by
      • setRotation

        public void setRotation​(float yaw,
                                float pitch,
                                float roll)
        Sets the rotation of this decal to the given angles on all axes.
        Parameters:
        yaw - Angle in degrees to rotate around the Y axis
        pitch - Angle in degrees to rotate around the X axis
        roll - Angle in degrees to rotate around the Z axis
      • setRotation

        public void setRotation​(Vector3 dir,
                                Vector3 up)
        Sets the rotation of this decal based on the (normalized) direction and up vector.
        Parameters:
        dir - the direction vector
        up - the up vector
      • setRotation

        public void setRotation​(Quaternion q)
        Sets the rotation of this decal based on the provided Quaternion
        Parameters:
        q - desired Rotation
      • getRotation

        public Quaternion getRotation()
        Returns the rotation. The returned quaternion should under no circumstances be modified.
        Returns:
        Quaternion representing the rotation
      • translateX

        public void translateX​(float units)
        Moves by the specified amount of units along the x axis
        Parameters:
        units - Units to move the decal
      • setX

        public void setX​(float x)
        Sets the position on the x axis
        Parameters:
        x - Position to locate the decal at
      • getX

        public float getX()
        Returns:
        position on the x axis
      • translateY

        public void translateY​(float units)
        Moves by the specified amount of units along the y axis
        Parameters:
        units - Units to move the decal
      • setY

        public void setY​(float y)
        Sets the position on the y axis
        Parameters:
        y - Position to locate the decal at
      • getY

        public float getY()
        Returns:
        position on the y axis
      • translateZ

        public void translateZ​(float units)
        Moves by the specified amount of units along the z axis
        Parameters:
        units - Units to move the decal
      • setZ

        public void setZ​(float z)
        Sets the position on the z axis
        Parameters:
        z - Position to locate the decal at
      • getZ

        public float getZ()
        Returns:
        position on the z axis
      • translate

        public void translate​(float x,
                              float y,
                              float z)
        Translates by the specified amount of units
        Parameters:
        x - Units to move along the x axis
        y - Units to move along the y axis
        z - Units to move along the z axis
      • setPosition

        public void setPosition​(float x,
                                float y,
                                float z)
        Sets the position to the given world coordinates
        Parameters:
        x - X position
        y - Y Position
        z - Z Position
      • getColor

        public Color getColor()
        Returns the color of this decal. The returned color should under no circumstances be modified.
        Returns:
        The color of this decal.
      • getPosition

        public Vector3 getPosition()
        Returns the position of this decal. The returned vector should under no circumstances be modified.
        Returns:
        vector representing the position
      • setScaleX

        public void setScaleX​(float scale)
        Sets scale along the x axis
        Parameters:
        scale - New scale along x axis
      • getScaleX

        public float getScaleX()
        Returns:
        Scale on the x axis
      • setScaleY

        public void setScaleY​(float scale)
        Sets scale along the y axis
        Parameters:
        scale - New scale along y axis
      • getScaleY

        public float getScaleY()
        Returns:
        Scale on the y axis
      • setScale

        public void setScale​(float scaleX,
                             float scaleY)
        Sets scale along both the x and y axis
        Parameters:
        scaleX - Scale on the x axis
        scaleY - Scale on the y axis
      • setScale

        public void setScale​(float scale)
        Sets scale along both the x and y axis
        Parameters:
        scale - New scale
      • setWidth

        public void setWidth​(float width)
        Sets the width in world units
        Parameters:
        width - Width in world units
      • getWidth

        public float getWidth()
        Returns:
        width in world units
      • setHeight

        public void setHeight​(float height)
        Sets the height in world units
        Parameters:
        height - Height in world units
      • getHeight

        public float getHeight()
        Returns:
        height in world units
      • setDimensions

        public void setDimensions​(float width,
                                  float height)
        Sets the width and height in world units
        Parameters:
        width - Width in world units
        height - Height in world units
      • getVertices

        public float[] getVertices()
        Returns the vertices backing this sprite.
        The returned value should under no circumstances be modified.
        Returns:
        vertex array backing the decal
      • update

        protected void update()
        Recalculates vertices array if it grew out of sync with the properties (position, ..)
      • transformVertices

        protected void transformVertices()
        Transforms the position component of the vertices using properties such as position, scale, etc.
      • resetVertices

        protected void resetVertices()
        Resets the position components of the vertices array based ont he dimensions (preparation for transformation)
      • updateUVs

        protected void updateUVs()
        Re-applies the uv coordinates from the material's texture region to the uv components of the vertices array
      • setTextureRegion

        public void setTextureRegion​(TextureRegion textureRegion)
        Sets the texture region
        Parameters:
        textureRegion - Texture region to apply
      • getTextureRegion

        public TextureRegion getTextureRegion()
        Returns:
        the texture region this Decal uses. Do not modify it!
      • setBlending

        public void setBlending​(int srcBlendFactor,
                                int dstBlendFactor)
        Sets the blending parameters for this decal
        Parameters:
        srcBlendFactor - Source blend factor used by glBlendFunc
        dstBlendFactor - Destination blend factor used by glBlendFunc
      • setMaterial

        public void setMaterial​(DecalMaterial material)
        Set material
        Parameters:
        material - custom material
      • lookAt

        public void lookAt​(Vector3 position,
                           Vector3 up)
        Sets the rotation of the Decal to face the given point. Useful for billboarding.
        Parameters:
        position -
        up -
      • newDecal

        public static Decal newDecal​(TextureRegion textureRegion)
        Creates a decal assuming the dimensions of the texture region
        Parameters:
        textureRegion - Texture region to use
        Returns:
        Created decal
      • newDecal

        public static Decal newDecal​(TextureRegion textureRegion,
                                     boolean hasTransparency)
        Creates a decal assuming the dimensions of the texture region and adding transparency
        Parameters:
        textureRegion - Texture region to use
        hasTransparency - Whether or not this sprite will be treated as having transparency (transparent png, etc.)
        Returns:
        Created decal
      • newDecal

        public static Decal newDecal​(float width,
                                     float height,
                                     TextureRegion textureRegion)
        Creates a decal using the region for texturing
        Parameters:
        width - Width of the decal in world units
        height - Height of the decal in world units
        textureRegion - TextureRegion to use
        Returns:
        Created decal
      • newDecal

        public static Decal newDecal​(float width,
                                     float height,
                                     TextureRegion textureRegion,
                                     boolean hasTransparency)
        Creates a decal using the region for texturing
        Parameters:
        width - Width of the decal in world units
        height - Height of the decal in world units
        textureRegion - TextureRegion to use
        hasTransparency - Whether or not this sprite will be treated as having transparency (transparent png, etc.)
        Returns:
        Created decal
      • newDecal

        public static Decal newDecal​(float width,
                                     float height,
                                     TextureRegion textureRegion,
                                     int srcBlendFactor,
                                     int dstBlendFactor)
        Creates a decal using the region for texturing and the specified blending parameters for blending
        Parameters:
        width - Width of the decal in world units
        height - Height of the decal in world units
        textureRegion - TextureRegion to use
        srcBlendFactor - Source blend used by glBlendFunc
        dstBlendFactor - Destination blend used by glBlendFunc
        Returns:
        Created decal
      • newDecal

        public static Decal newDecal​(float width,
                                     float height,
                                     TextureRegion textureRegion,
                                     int srcBlendFactor,
                                     int dstBlendFactor,
                                     DecalMaterial material)
        Creates a decal using the region for texturing and the specified blending parameters for blending
        Parameters:
        width - Width of the decal in world units
        height - Height of the decal in world units
        textureRegion - TextureRegion to use
        srcBlendFactor - Source blend used by glBlendFunc
        dstBlendFactor - Destination blend used by glBlendFunc
        material - Custom decal material
        Returns:
        Created decal