Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dotnet-websharper/glmatrix
WebSharper bindings for the glMatrix library
https://github.com/dotnet-websharper/glmatrix
Last synced: about 2 months ago
JSON representation
WebSharper bindings for the glMatrix library
- Host: GitHub
- URL: https://github.com/dotnet-websharper/glmatrix
- Owner: dotnet-websharper
- License: apache-2.0
- Created: 2013-10-01T15:03:18.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-06-23T21:02:06.000Z (over 3 years ago)
- Last Synced: 2024-11-02T21:09:07.866Z (2 months ago)
- Language: F#
- Size: 220 KB
- Stars: 3
- Watchers: 10
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-websharper - GlMatrix - 3D Math library: matrices, quaternions, etc. (Libraries / JavaScript library bindings)
README
# Overview
This WebSharper Extension provides a set of classes and functions
almost identical to the ones documented in
[glMatrix](http://glmatrix.googlecode.com), version 2.2.0. When used
in WebSharper projects, these stub classes delegate the work to the
actual classes implemented by the browser.After adding the reference to the project all the classes can be found
under the `IntelliFactory.WebSharper.GlMatrix` module.# Usage
The GlMatrix WebSharper extension is as far as possible a one-to-one
mapping of glMatrix. Therefore, this documentation will only discuss
the differences between glMatrix and the WebSharper extension. For a
complete reference, see [the glMatrix homepage](http://glmatrix.googlecode.com).## Differences with the JavaScript API
In order to enforce strong typing and take advantage of F# features such as
method overloading, we made a few modifications over the glMatrix API.* While glMatrix works on `Float32Array` objects, the WebSharper
extension defines classes for each one of `Mat2`, `Mat3`, `Mat4`,
`Vec2`, `Vec2d`, `Vec3`, `Vec4` and `Quad`. These classes inherit
from the standard `Float32Array`, which allows you to pass them
directly to WebGL methods such as the `Uniform` series.## Using matrix transformations with WebGL
As the name suggests, glMatrix is mainly intended as a toolbox
for coordinate transformation for WebGL. The following example
shows a typical use to set the projection and modelview matrices
of a given WebGL shader program.```fsharp
let SetupView (gl : WebGLRenderingContext, program : WebGLProgram) =
// Set the projection matrix
let proj = Mat4.Perspective(Mat4.Create(), 45., 4./3., 0.1, 1000.)
let u_projection = gl.GetUniformLocation(program, "projectionMatrix")
gl.UniformMatrix4fv(u_projection, false, proj)// Set the modelview matrix
let cameraPosition = Mat4.Identity(Mat4.Create())
Mat4.Translate(cameraPosition, cameraPosition, Vec3.FromValues(0.2, 2.3, -5.2)) |> ignore
let u_modelview = gl.GetUniformLocation(program, "modelviewMatrix")
gl.UniformMatrix4fv(u_modelview, false, cameraPosition)
```