Orientation2D

View source

ExtendsRotary

Stores an entity’s local 2D orientation as an ECS component.

A new orientation has the identity value (1, 0), representing zero rotation. Keep the value normalized when it represents a pure rotation.

Use Position2D, Scale2D, and GlobalTransform2D for an entity’s local 2D transform. It extends Rotary.

Examples

import { Query, World } from '@wimaengine/ecs'
import { Orientation2D } from '@wimaengine/transform'

const world = new World()
world.spawn([
  new Orientation2D(Math.cos(Math.PI / 4), Math.sin(Math.PI / 4))
])

const orientations = new Query(world, [Orientation2D])
orientations.each(([orientation]) => {
  // Rotary.rotate returns a rotary result; copy it into the component.
  orientation.copy(orientation.rotate(0.1))
})

Constructor


constructor(cos?: number, sin?: number)

View source

Creates a rotary from cosine and sine.

Parameters

NameDescriptionDefault
cos?——
sin?——

Methods


staticserialize(value: Orientation2D): RotaryLike

View source

Parameters

NameDescriptionDefault
value

Orientation to serialize.

—

Returns

The serialized orientation value.

  • @inheritDoc

staticdeserialize(value: RotaryLike, out?: Orientation2D): Orientation2D

View source

Parameters

NameDescriptionDefault
value

Serialized orientation value.

—
out?

Orientation to populate.

...

Returns

The populated or newly created orientation.

  • @inheritDoc