Castle Game Engine: CastleCubeMaps

# Unit CastleCubeMaps
Description | Uses | Classes, Interfaces, Objects and Records | Functions and Procedures | Types | Constants | Variables
## Description Utilities for cube (environment) maps. ## Uses CastleVectors Math ## Overview ### Classes, Interfaces, Objects and Records
Name | Description
--- | ---
record `TCubeMapInfo` |
### Functions and Procedures
`function CubeMapDirection(const Side: TCubeMapSide; const Pixel: Cardinal): TVector3Single;`
`procedure DirectionToCubeMap(const Dir: TVector3Single; out Side: TCubeMapSide; out Pixel: Cardinal);`
`procedure Direction4ToCubeMap(const Dir: TVector3Single; out Side: TCubeMapSide4; out Pixel: TVector4Cardinal; out Ratio: TVector4Single);`
`function CubeMapSolidAngle(const Side: TCubeMapSide; const Pixel: Cardinal): Single;`
### Types
`TCubeMapSide = (...);`
`TCubeMapSide4 = array [0..3] of TCubeMapSide;`
`TCardinal4 = array [0..3] of Cardinal;`
`TCubeMapFloat = array [TCubeMapSide, 0..Sqr(CubeMapSize) - 1] of Float;`
`PCubeMapFloat = ˆTCubeMapFloat;`
`TCubeMapByte = array [TCubeMapSide, 0..Sqr(CubeMapSize) - 1] of Byte;`
`PCubeMapByte = ˆTCubeMapByte;`
### Constants
`CubeMapSize = 16;`
`CubeMapInfo: array [TCubeMapSide] of TCubeMapInfo = ( (Dir: ( 1, 0, 0); Up: (0, -1, 0); Side: ( 0, 0,-1); ScreenX: 3; ScreenY: 0), (Dir: (-1, 0, 0); Up: (0, -1, 0); Side: ( 0, 0, 1); ScreenX: 1; ScreenY: 0), (Dir: ( 0, 1, 0); Up: (0, 0, 1); Side: ( 1, 0, 0); ScreenX: 2; ScreenY: -1), (Dir: ( 0, -1, 0); Up: (0, 0, -1); Side: ( 1, 0, 0); ScreenX: 2; ScreenY: +1), (Dir: ( 0, 0, 1); Up: (0, -1, 0); Side: ( 1, 0, 0); ScreenX: 2; ScreenY: 0), (Dir: ( 0, 0, -1); Up: (0, -1, 0); Side: (-1, 0, 0); ScreenX: 0; ScreenY: 0) );`
## Description ### Functions and Procedures
`function CubeMapDirection(const Side: TCubeMapSide; const Pixel: Cardinal): TVector3Single;`
Direction corresponding to given cube map side and pixel number. That is, assuming that the middle of cube is placed at (0, 0, 0), each pixel of the cube map corresponds to some direction. Pixel number must be between 0 and CubeMapSize*2-1. It's assumed that pixels are in the same order as they are in OpenGL images, that is row-by-row, from the lowest row to highest, in each row from left to right. Returned vector is not normalized.
`procedure DirectionToCubeMap(const Dir: TVector3Single; out Side: TCubeMapSide; out Pixel: Cardinal);`
Return cube map side and pixel that is the closest to given direction Dir. This is the reverse of CubeMapDirection function. Given here Dir need not be normalized, although must not be zero.
`procedure Direction4ToCubeMap(const Dir: TVector3Single; out Side: TCubeMapSide4; out Pixel: TVector4Cardinal; out Ratio: TVector4Single);`
Return 4 cube map indexes (side and pixel, along with ratio) that are closest to given direction Dir. All ratios will sum to 1. This is like DirectionToCubeMap, except this returns 4 values. It allows you to do bilinear interpolation between cube map items.
`function CubeMapSolidAngle(const Side: TCubeMapSide; const Pixel: Cardinal): Single;`
Calculate solid angle of given pixel on the cube map.
### Types
`TCubeMapSide = (...);`
Cube map faces. Order matches order of OpenGL constants GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z_ARB. ###### Values csPositiveX: csNegativeX: csPositiveY: csNegativeY: csPositiveZ: csNegativeZ:
`TCubeMapSide4 = array [0..3] of TCubeMapSide;`
`TCardinal4 = array [0..3] of Cardinal;`
`TCubeMapFloat = array [TCubeMapSide, 0..Sqr(CubeMapSize) - 1] of Float;`
Cube map, with each item being a Float.
`PCubeMapFloat = ˆTCubeMapFloat;`
`TCubeMapByte = array [TCubeMapSide, 0..Sqr(CubeMapSize) - 1] of Byte;`
Cube map, with each item being in 0..1 range, encoded as a Byte. This assumes that every item is actually a float in 0..1 range, encoded as Byte.
`PCubeMapByte = ˆTCubeMapByte;`
### Constants
`CubeMapSize = 16;`
`CubeMapInfo: array [TCubeMapSide] of TCubeMapInfo = ( (Dir: ( 1, 0, 0); Up: (0, -1, 0); Side: ( 0, 0,-1); ScreenX: 3; ScreenY: 0), (Dir: (-1, 0, 0); Up: (0, -1, 0); Side: ( 0, 0, 1); ScreenX: 1; ScreenY: 0), (Dir: ( 0, 1, 0); Up: (0, 0, 1); Side: ( 1, 0, 0); ScreenX: 2; ScreenY: -1), (Dir: ( 0, -1, 0); Up: (0, 0, -1); Side: ( 1, 0, 0); ScreenX: 2; ScreenY: +1), (Dir: ( 0, 0, 1); Up: (0, -1, 0); Side: ( 1, 0, 0); ScreenX: 2; ScreenY: 0), (Dir: ( 0, 0, -1); Up: (0, -1, 0); Side: (-1, 0, 0); ScreenX: 0; ScreenY: 0) );`
Information about cube map faces. Names and orientation of faces match precisely OpenGL naming and orientation (see http://www.opengl.org/registry/specs/ARB/texture_cube_map.txt), so it's straighforward to use this for OpenGL cube maps.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:09