Home Reference Source

Function

Static Public Summary
public

Calculate closest turn angle difference.

public

Calculate cubic bezier curve value at given time with four curve parameters.

public

convertGlobalPointToLocalPoint(target: vec3, globalVec: vec3, globalTransform: mat4)

Converts global vec3 coordinate into local vec2 coordinate.

public

convertLocalPointToGlobalPoint(target: vec3, localVec: vec3, globalTransform: mat4)

Converts local vec3 coordinate into global vec2 coordinate.

public

findMapKeyOfValue(map: *, value: *): string | null

Search for key of given map value.

public

Calculate mipmap scale at given level.

public

getPOT(v: number, upper: boolean): number

Calculate nearest power-of-two.

public

isGlobalPointInGlobalBoundingBox(globalVec: vec2, w: number, h: number, ox: number, oy: number, globalTransform: mat4): boolean

Tells if given global vec2 coordinate is contained by given bounding box in given global transform space.

public

isLocalPointInLocalBoundingBox(localVec: vec2, w: number, h: number, ox: number, oy: number): boolean

Tells if given local vec2 coordinate is contained by given bounding box.

public

isPOT(args: number[]): boolean

Checks if all arguments are power-of-two.

public

Function used to initialize Oxygen Core engine without any effort.

public

Stringify key-value map into enumeration-like representation.

public

stringToRGBA(value: string): [number]

Converts hexadecimal color string into four element array of color channels values.

public

Produces promise that waits given amount of seconds, then resolves itself.

Static Public

public angleDifference(a: number, b: number): number source

import {angleDifference} from 'oxygen-core/utils'

Calculate closest turn angle difference.

Params:

NameTypeAttributeDescription
a number

From angle.

b number

To angle.

Return:

number

Angle difference (negative values possible).

Example:

angleDifference(10, 350) === -20

public bezierCubic(t: number, a: number, b: number, c: number, d: number): number source

import {bezierCubic} from 'oxygen-core/utils'

Calculate cubic bezier curve value at given time with four curve parameters.

Params:

NameTypeAttributeDescription
t number

Time.

a number

First curve position.

b number

First curve controller.

c number

Second curve controller.

d number

Second curve controller.

Return:

number

Calculated curve value.

public convertGlobalPointToLocalPoint(target: vec3, globalVec: vec3, globalTransform: mat4) source

import {convertGlobalPointToLocalPoint} from 'oxygen-core/utils'

Converts global vec3 coordinate into local vec2 coordinate.

Params:

NameTypeAttributeDescription
target vec3

Result vec3 value.

globalVec vec3

Global vec3 value.

globalTransform mat4

Object mat4 transform.

Example:

const result = vec3.create();
const pos = vec3.fromValues(1, 1, 0);
const transform = mat4.identity();
convertGlobalPointToLocalPoint(result, pos, transform);

public convertLocalPointToGlobalPoint(target: vec3, localVec: vec3, globalTransform: mat4) source

import {convertLocalPointToGlobalPoint} from 'oxygen-core/utils'

Converts local vec3 coordinate into global vec2 coordinate.

Params:

NameTypeAttributeDescription
target vec3

Result vec3 value.

localVec vec3

Local vec3 value.

globalTransform mat4

Object mat4 transform.

Example:

const result = vec3.create();
const pos = vec3.fromValues(1, 1, 0);
const transform = mat4.identity();
convertLocalPointToGlobalPoint(result, pos, transform);

public findMapKeyOfValue(map: *, value: *): string | null source

import {findMapKeyOfValue} from 'oxygen-core/utils'

Search for key of given map value.

Params:

NameTypeAttributeDescription
map *

map collection object.

value *

value you're looking for.

Return:

string | null

value key or null if value not found.

Example:

const found = findMapKeyOfValue({ hello: 'world' }, 'world');

public getMipmapScale(level: number): number source

import {getMipmapScale} from 'oxygen-core/utils'

Calculate mipmap scale at given level.

Params:

NameTypeAttributeDescription
level number

Level value (0 means base level, full scale).

Return:

number

Mipmap scale for given level.

public getPOT(v: number, upper: boolean): number source

import {getPOT} from 'oxygen-core/utils'

Calculate nearest power-of-two.

Params:

NameTypeAttributeDescription
v number

Value.

upper boolean

calculate upper POT value.

Return:

number

Nearest power-of-two value.

public isGlobalPointInGlobalBoundingBox(globalVec: vec2, w: number, h: number, ox: number, oy: number, globalTransform: mat4): boolean source

import {isGlobalPointInGlobalBoundingBox} from 'oxygen-core/utils'

Tells if given global vec2 coordinate is contained by given bounding box in given global transform space.

Params:

NameTypeAttributeDescription
globalVec vec2

Global vec2 value.

w number

BBox width.

h number

BBox height.

ox number

BBox X offset.

oy number

BBox Y offset.

globalTransform mat4

Object mat4 transform.

Return:

boolean

True if point is contained by bounding box.

Example:

const pos = vec2.fromValues(2, 2);
const transform = mat4.identity();
isGlobalPointInGlobalBoundingBox(pos, 2, 2, 1, 1, transform) === true

public isLocalPointInLocalBoundingBox(localVec: vec2, w: number, h: number, ox: number, oy: number): boolean source

import {isLocalPointInLocalBoundingBox} from 'oxygen-core/utils'

Tells if given local vec2 coordinate is contained by given bounding box.

Params:

NameTypeAttributeDescription
localVec vec2

Local vec2 value.

w number

BBox width.

h number

BBox height.

ox number

BBox X offset.

oy number

BBox Y offset.

Return:

boolean

True if point is contained by bounding box.

public isPOT(args: number[]): boolean source

import {isPOT} from 'oxygen-core/utils'

Checks if all arguments are power-of-two.

Params:

NameTypeAttributeDescription
args number[]

Values.

Return:

boolean

True if all arguments are power-of-two.

public lazyInitialization(config: *): EventsController source

import {lazyInitialization} from 'oxygen-core'

Function used to initialize Oxygen Core engine without any effort.

Params:

NameTypeAttributeDescription
config *

engine configuration options.

Return:

EventsController

instance used to dynamically control events processing.

Example:

lazyInitialization({
  entities: { triggerEvents: true },
  asset: { pathPrefix: 'assets/' },
  render: { screen: 'screen-0' },
  input: { triggerEvents: true },
  store: { id: 'my-game-id' },
  events: { transform: true, update: true, view: true, gamepads: true }
});

public propsEnumStringify(values: *): string source

import {propsEnumStringify} from 'oxygen-core/utils'

Stringify key-value map into enumeration-like representation.

Params:

NameTypeAttributeDescription
values *

Map collection.

Return:

string

Stringified map collection.

Example:

const enum = propsEnumStringify({ hello: 'world', ohayo: 'gosaimasu' });

public stringToRGBA(value: string): [number] source

import {stringToRGBA} from 'oxygen-core/utils'

Converts hexadecimal color string into four element array of color channels values.

Params:

NameTypeAttributeDescription
value string

Hexadecimal color string.

Return:

[number]

Four element array of color channels.

Example:

const color = stringToRGBA('AABBCCFF');

public waitForSeconds(seconds: number): Promise source

import {waitForSeconds} from 'oxygen-core/utils'

Produces promise that waits given amount of seconds, then resolves itself.

Params:

NameTypeAttributeDescription
seconds number

Number of seconds to wait.

Return:

Promise

Produced promise.

Example:

waitForSeconds(1.5).then(() => console.log('hello!'));