I have written a javascript-program. This program requires the package gl-matrix.js.
But i get the wrong result!!!!
[source lang="java"][script type="text/javascript" src="js/glMatrix.js"][/script][script type="text/javascript"]// coordinate system://// |y// |___ x// /// z// normal (unit) vector// normalized vector perpendicular to the share planevar n = vec3.create([0, 1, 0]); // x, y, zvar nx = n[0];var ny = n[1];var nz = n[2];// shear vector:// vector on the plane which indicates how planes parallel to the shear plane will be transformedvar s = vec3.create([1, 0, 0]); // x, y, zvar sx = s[0];var sy = s[1];var sz = s[2];// shear://// ^ y ^ y ^ y// | |______ | _______// ^ n | | | / /// | | | | / /// O |___\_____\ x |______|___\ x => |/______/___\ x// / /s / / / / /// / shear / /// / plane / /// z z z//// The shear plane is the x/z plane.// Legende:// O ... Origin (0/0/0)// n ... unit vector normal to shear plane// s ... shear vector// creating matrixvar m = mat4.create();// Matrix:// | I + n x s 0 |// | 0T 1 |// Legende:// I ... Identity matrix// x ... tensor product:// | nx | | nx * sx nx * sy nx * sz |// | ny | | sx sy sz | => | ny * sx ny * sy ny * sz |// | nz | | nz * sx nz * sy nz * sz |m[ 0] /* x/y 0/0 */ = nx * sx + 1;m[ 1] /* x/y 0/1 */ = ny * sx;m[ 2] /* x/y 0/2 */ = nz * sx;m[ 3] /* x/y 0/3 */ = 0;m[ 4] /* x/y 1/0 */ = nx * sy;m[ 5] /* x/y 1/1 */ = ny * sy + 1;m[ 6] /* x/y 1/2 */ = nz * sy;m[ 7] /* x/y 1/3 */ = 0;m[ 8] /* x/y 2/0 */ = nx * sz;m[ 9] /* x/y 2/1 */ = ny * sz;m[10] /* x/y 2/2 */ = nz * sz + 1;m[11] /* x/y 2/3 */ = 0;m[12] /* x/y 3/0 */ = 0;m[13] /* x/y 3/1 */ = 0;m[14] /* x/y 3/2 */ = 0;m[15] /* x/y 3/3 */ = 1;for (var i = 0; i < 16; ++i) console.log(m[i]); // example transformation://// ^ y ^ y// [3]|______[2] |[3]_______[2]// | | | / /// | | | / / EXPECTED!!!!!!!!!!!!!!// |______|___\ x => |/______/___\ x RESULT!!!!!!!!!!!!!!!!// /[0] [1] / /[0] [1] /// / /// / /// z zvar v = [];v[0] = vec3.create([0, 0, 0]);v[1] = vec3.create([1, 0, 0]);v[2] = vec3.create([1, 1, 0]);v[3] = vec3.create([0, 1, 0]);var length = v.length;for (var i = 0; i < length; ++i) { var result = mat4.multiplyVec3(m, v[i]); console.log(result);}// But i get the following result://// ^ y// | [2]// | /|// | / |// [3]|/ |[1]// | / // | / // |/______\ x// /[0] /// /// /// z[/script][/source]
Why does my program shear the vertices in the wrong direction???
EDIT: THE EDITOR OF THIS WEBSITE IS REALLY AWFUL!
THE CODE YOU SEE IS NOT THE CODE I POSTED. TEXT HAS BEEN IMPROPERLY FORMATTED!
Edited by friba77, 27 June 2012 - 12:11 PM.