Comments (1)
Here's a simpler example which uses both libraries to do the same perspective, translate, and rotate operations:
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>
<script src="lib/gl-matrix-min.js" ></script>
<script src="lib/glmw-browser.js" ></script>
<script>
glmw.init().then(ready => {
const pi = Math.PI;
const fieldOfView = 45 * pi / 180; //// in radians
const aspect = 600/400;
const zNear = 0.1; // depth clipping
const zFar = 100.0;// depth clipping
const time_ms = 101;
const period_ms = 4000;
const rotation = ((time_ms) % period_ms) / period_ms * pi;
// gl-matrix
// first set the camera perspective
console.log("Using glMatrix:")
var projectionMatrix = glMatrix.mat4.create();
console.log("New matrix: "+(projectionMatrix));
glMatrix.mat4.perspective(projectionMatrix, fieldOfView, aspect, zNear,zFar);
console.log("perspective: "+(projectionMatrix));
// now position the 3D model
var modelViewMatrix = glMatrix.mat4.create();
console.log("New matrix: "+(modelViewMatrix));
glMatrix.mat4.translate(modelViewMatrix, modelViewMatrix, [0.0, 0.0, -4]);
console.log("translate: "+(modelViewMatrix));
glMatrix.mat4.rotate(modelViewMatrix, modelViewMatrix, rotation,[0, 0, 1] );
console.log("rotate: "+(modelViewMatrix));
console.log("----------")
// glmw
// first set the camera perspective
console.log("Using GLMW:")
var projectionMatrix = glmw.mat4.create();
console.log("New matrix: "+glmw.mat4.str(projectionMatrix));
glmw.mat4.perspective(projectionMatrix, fieldOfView, aspect, zNear,zFar);
console.log("perspective: "+glmw.mat4.str(projectionMatrix));
// now position the 3D model
var modelViewMatrix = glmw.mat4.create();
console.log("New matrix: "+glmw.mat4.str(modelViewMatrix));
glmw.mat4.translate(modelViewMatrix, modelViewMatrix, [0.0, 0.0, -4]);
console.log("translate: "+glmw.mat4.str(modelViewMatrix));
glmw.mat4.rotate(modelViewMatrix, modelViewMatrix, rotation,[0, 0, 1] );
console.log("rotate: "+glmw.mat4.str(modelViewMatrix));
});
</script>
</body></html>
The output is as follows:
Using glMatrix:
New matrix: 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1
perspective: 1.6094757318496704,0,0,0,0,2.4142136573791504,0,0,0,0,-1.0020020008087158,-1,0,0,-0.20020020008087158,0
New matrix: 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1
translate: 1,0,0,0,0,1,0,0,0,0,1,0,0,0,-4,1
rotate: 0.9968553781509399,0.0792420506477356,0,0,-0.0792420506477356,0.9968553781509399,0,0,0,0,1,0,0,0,-4,1
----------
Using GLMW:
New matrix: mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
perspective: mat4(1.6094756126403809, 0, 0, 0, 0, 2.4142134189605713, 0, 0, 0, 0, -1.0020020008087158, -1, 0, 0, -0.20020020008087158, 0)
New matrix: mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
translate: mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1.8811030585096344e-41, 0, 1)
rotate: mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1.8811030585096344e-41, 0, 1)
As you can see, mat4.perspective works the same in both libraries, but neither mat4.translate nor mat4.rotate are storing the correct values in the matrix
from glmw.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glmw.