com.brackeen.javagamebook.graphics3D.texture
Class ShadedSurface

java.lang.Object
  extended bycom.brackeen.javagamebook.graphics3D.texture.Texture
      extended bycom.brackeen.javagamebook.graphics3D.texture.ShadedSurface

public final class ShadedSurface
extends Texture

A ShadedSurface is a pre-shaded Texture that maps onto a polygon.


Field Summary
static int SHADE_RES
           
static int SHADE_RES_BITS
           
static int SHADE_RES_MASK
           
static int SHADE_RES_SQ
           
static int SHADE_RES_SQ_BITS
           
static int SURFACE_BORDER_SIZE
           
 
Constructor Summary
ShadedSurface(int width, int height)
          Creates a ShadedSurface with the specified width and height.
ShadedSurface(short[] buffer, int width, int height)
          Creates a ShadedSurface with the specified buffer, width and height.
 
Method Summary
 void buildShadeMap(java.util.List pointLights, float ambientLightIntensity)
          Builds the shade map for this surface from the specified list of point lights and the ambiant light intensity.
 void buildSurface()
          Builds the surface.
 void clearSurface()
          Clears this surface, allowing the garbage collector to remove it from memory if needed.
static void createShadedSurface(TexturedPolygon3D poly, ShadedTexture texture, java.util.List lights, float ambientLightIntensity)
          Creates a ShadedSurface for the specified polygon.
static void createShadedSurface(TexturedPolygon3D poly, ShadedTexture texture, Rectangle3D textureBounds, java.util.List lights, float ambientLightIntensity)
          Creates a ShadedSurface for the specified polygon.
 short getColor(int x, int y)
          Gets the 16-bit color of the pixel at location (x,y) in the bitmap.
 short getColorChecked(int x, int y)
          Gets the 16-bit color of the pixel at location (x,y) in the bitmap.
 int getInterpolatedShade(int u, int v)
          Gets the shade (from the shade map) for the specified (u,v) location.
 int getShade(int u, int v)
          Gets the shade (from the built shade map) for the specified (u,v) location.
 Rectangle3D getSurfaceBounds()
          Gets the surface bounds for this ShadedSurface.
 boolean isCleared()
          Checks if the surface has been cleared.
 boolean isDirty()
          Checks wether this surface is dirty.
 boolean retrieveSurface()
          If the buffer has been previously built and cleared but not yet removed from memory by the garbage collector, then this method attempts to retrieve it.
 void setDirty(boolean dirty)
          Marks whether this surface is dirty.
 void setSurfaceBounds(Rectangle3D surfaceBounds)
          Sets the surface bounds for this ShadedSurface.
 void setTexture(ShadedTexture texture)
          Sets the source texture for this ShadedSurface.
 void setTexture(ShadedTexture texture, Rectangle3D bounds)
          Sets the source texture and source bounds for this ShadedSurface.
 
Methods inherited from class com.brackeen.javagamebook.graphics3D.texture.Texture
countbits, createTexture, createTexture, createTexture, createTexture, getHeight, getWidth, isPowerOfTwo
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SURFACE_BORDER_SIZE

public static final int SURFACE_BORDER_SIZE
See Also:
Constant Field Values

SHADE_RES_BITS

public static final int SHADE_RES_BITS
See Also:
Constant Field Values

SHADE_RES

public static final int SHADE_RES
See Also:
Constant Field Values

SHADE_RES_MASK

public static final int SHADE_RES_MASK
See Also:
Constant Field Values

SHADE_RES_SQ

public static final int SHADE_RES_SQ
See Also:
Constant Field Values

SHADE_RES_SQ_BITS

public static final int SHADE_RES_SQ_BITS
See Also:
Constant Field Values
Constructor Detail

ShadedSurface

public ShadedSurface(int width,
                     int height)
Creates a ShadedSurface with the specified width and height.


ShadedSurface

public ShadedSurface(short[] buffer,
                     int width,
                     int height)
Creates a ShadedSurface with the specified buffer, width and height.

Method Detail

createShadedSurface

public static void createShadedSurface(TexturedPolygon3D poly,
                                       ShadedTexture texture,
                                       java.util.List lights,
                                       float ambientLightIntensity)
Creates a ShadedSurface for the specified polygon. The shade map is created from the specified list of point lights and ambient light intensity.


createShadedSurface

public static void createShadedSurface(TexturedPolygon3D poly,
                                       ShadedTexture texture,
                                       Rectangle3D textureBounds,
                                       java.util.List lights,
                                       float ambientLightIntensity)
Creates a ShadedSurface for the specified polygon. The shade map is created from the specified list of point lights and ambient light intensity.


getColor

public short getColor(int x,
                      int y)
Gets the 16-bit color of the pixel at location (x,y) in the bitmap. The x and y values are assumbed to be within the bounds of the surface; otherwise an ArrayIndexOutOfBoundsException occurs.

Specified by:
getColor in class Texture

getColorChecked

public short getColorChecked(int x,
                             int y)
Gets the 16-bit color of the pixel at location (x,y) in the bitmap. The x and y values are checked to be within the bounds of the surface, and if not, the pixel on the edge of the texture is returned.


setDirty

public void setDirty(boolean dirty)
Marks whether this surface is dirty. Surfaces marked as dirty may be cleared externally.


isDirty

public boolean isDirty()
Checks wether this surface is dirty. Surfaces marked as dirty may be cleared externally.


clearSurface

public void clearSurface()
Clears this surface, allowing the garbage collector to remove it from memory if needed.


isCleared

public boolean isCleared()
Checks if the surface has been cleared.


retrieveSurface

public boolean retrieveSurface()
If the buffer has been previously built and cleared but not yet removed from memory by the garbage collector, then this method attempts to retrieve it. Returns true if successfull.


setTexture

public void setTexture(ShadedTexture texture)
Sets the source texture for this ShadedSurface.


setTexture

public void setTexture(ShadedTexture texture,
                       Rectangle3D bounds)
Sets the source texture and source bounds for this ShadedSurface.


setSurfaceBounds

public void setSurfaceBounds(Rectangle3D surfaceBounds)
Sets the surface bounds for this ShadedSurface.


getSurfaceBounds

public Rectangle3D getSurfaceBounds()
Gets the surface bounds for this ShadedSurface.


buildSurface

public void buildSurface()
Builds the surface. First, this method calls retrieveSurface() to see if the surface needs to be rebuilt. If not, the surface is built by tiling the source texture and apply the shade map.


getInterpolatedShade

public int getInterpolatedShade(int u,
                                int v)
Gets the shade (from the shade map) for the specified (u,v) location. The u and v values should be left-shifted by SHADE_RES_BITS, and the extra bits are used to interpolate between values. For an interpolation example, a location halfway between shade values 1 and 3 would return 2.


getShade

public int getShade(int u,
                    int v)
Gets the shade (from the built shade map) for the specified (u,v) location.


buildShadeMap

public void buildShadeMap(java.util.List pointLights,
                          float ambientLightIntensity)
Builds the shade map for this surface from the specified list of point lights and the ambiant light intensity.