# @react-vertex/matrix-hooks

> React hooks for WebGL matrix operations

Latest version **1.3.0** (published 2019-04-20) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @react-vertex/matrix-hooks
pnpm add @react-vertex/matrix-hooks
yarn add @react-vertex/matrix-hooks
bun add @react-vertex/matrix-hooks
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2019-04-20 |
| First published | 2019-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1234 |
| Author | Steven Hall |
| Maintainers | sghall |
| Keywords | react, hooks, webgl |

## Links

- npm: https://www.npmjs.com/package/@react-vertex/matrix-hooks
- Repository: https://github.com/sghall/react-vertex
- Homepage: https://github.com/sghall/react-vertex/tree/master/packages/matrix-hooks#readme
- Issues: https://github.com/sghall/react-vertex/issues
- npm.io page: https://npm.io/package/@react-vertex/matrix-hooks

## Dependencies (2)

- [gl-matrix](https://npm.io/package/gl-matrix.md) ^3.0.0
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.4.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2019-04-20
- 1.2.0 — 2019-04-13
- 1.1.0 — 2019-04-12
- 1.0.0 — 2019-04-08
- 0.6.0 — 2019-04-07
- 0.5.0 — 2019-04-07
- 0.4.0 — 2019-04-05
- 0.3.0 — 2019-04-04
- 0.2.0 — 2019-04-04

## README

# `@react-vertex/matrix-hooks`

[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/sghall/react-vertex/blob/master/packages/matrix-hooks/LICENSE)
[![bundlephobia](https://badgen.net/bundlephobia/minzip/@react-vertex/matrix-hooks)](https://bundlephobia.com/result?p=@react-vertex/matrix-hooks)
[![npm version](https://img.shields.io/npm/v/@react-vertex/matrix-hooks.svg)](https://www.npmjs.com/package/@react-vertex/matrix-hooks)

### [Documentation and Examples](https://react-vertex.com)

React hooks for working with matrices in WebGL.  This package just contains a couple of items that were helpful in developing the examples.  I think a package like this would be great but the API needs to be fleshed out.  This package uses [gl-matrix](http://glmatrix.net/docs/module-mat4.html).

##### Install via npm:
```js
npm install @react-vertex/matrix-hooks
```

#### Importing:

```js
import {
  useIdentity,
  usePerspective,
} from '@react-vertex/matrix-hooks'
```
## `usePerspective(fov, aspect, near, far)` => `matrix`

React hook to create a perspective projection matrix with the given field of view.

##### Arguments:

`fov`: A number defining the field of view.  Generally, numbers from 35 to 75 are reasonable. 

`aspect`: A number defining aspect ratio.  In most cases you want to use canvas.width / canvas.height but other scenarios exist.

`near (optional)`: The camera frustum near plane. Defaults to 1.

`far (optional)`: The camera frustum far plane. Defaults to 1000.

##### Returns:

`matrix`: Returns an instance of a [gl-matrix mat4](http://glmatrix.net/docs/module-mat4.html)

##### Example Usage:

```js
import { usePerspective } from '@react-vertex/matrix-hooks'

...
  const projection = usePerspective(55, canvas.width / canvas.height, 0.1, 5000)
...
```

## `useIdentity([px], [py], [pz], [rx], [ry], [rz])` => `matrix`

React hook to create a new identity matrix.  You can set the initial position and rotation.

##### Arguments:

`px (optional)`: A number for the x position. Defaults to 0.

`py (optional)`: A number for the y position. Defaults to 0.

`pz (optional)`: A number for the z position. Defaults to 0.

`rx (optional)`: A number for the x rotation in radians. Defaults to 0.

`ry (optional)`: A number for the y rotation in radians. Defaults to 0.

`rz (optional)`: A number for the z rotation in radians. Defaults to 0.

##### Returns:

`matrix`: Returns an instance of a [gl-matrix mat4](http://glmatrix.net/docs/module-mat4.html)

##### Example Usage:

```js
import { useIdentity } from '@react-vertex/matrix-hooks'

...
  const view = useIdentity(0, 20, 0)
...
```

---
_Source: https://npm.io/package/@react-vertex/matrix-hooks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
