Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added examples in Matrix4.js for #651 #724

Merged
merged 8 commits into from
May 2, 2013
185 changes: 185 additions & 0 deletions Source/Core/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,18 @@ define([
* @return {Array} The modified Array parameter or a new Array instance if one was not provided.
*
* @exception {DeveloperError} matrix is required.
*
* @example
* //create an array from an instance of Matrix4
* // m = [10.0, 14.0, 18.0, 22.0]
* // [11.0, 15.0, 19.0, 23.0]
* // [12.0, 16.0, 20.0, 24.0]
* // [13.0, 17.0, 21.0, 25.0]
* var a = Matrix4.toArray(m);
*
* // m remains the same
* //creates a = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this in the debugger? This shows a row-major ordering, but I believe it should be column-major.

*
*/
Matrix4.toArray = function(matrix, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -866,6 +878,23 @@ define([
* @exception {DeveloperError} index is required and must be 0, 1, 2, or 3.
*
* @see Cartesian4
*
* @example
* //returns a Cartesian4 instance with values from the specified column
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* //Example 1: Creates an instance of Cartesian
* var a = Matrix4.getColumn(m, 2);
*
* //Example 2: Sets values for Cartesian instance
* var a = new Cartesian4();
* Matrix4.getColumn(m, 2, a);
*
* // a.x = 12.0; a.y = 16.0; a.z = 20.0; a.w = 24.0;
*
*/
Matrix4.getColumn = function(matrix, index, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -907,6 +936,22 @@ define([
* @exception {DeveloperError} index is required and must be 0, 1, 2, or 3.
*
* @see Cartesian4
*
* @example
* //creates a new Matrix4 instance with new column values from the Cartesian4 instance
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.setColumn(m, 2, new Cartesian4(99.0, 98.0, 97.0, 96.0));
*
* // m remains the same
* // a = [10.0, 11.0, 99.0, 13.0]
* // [14.0, 15.0, 98.0, 17.0]
* // [18.0, 19.0, 97.0, 21.0]
* // [22.0, 23.0, 96.0, 25.0]
*
*/
Matrix4.setColumn = function(matrix, index, cartesian, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -940,6 +985,22 @@ define([
* @exception {DeveloperError} index is required and must be 0, 1, 2, or 3.
*
* @see Cartesian4
*
* @example
* //returns a Cartesian4 instance with values from the specified column
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* //Example 1: Returns an instance of Cartesian
* var a = Matrix4.getRow(m, 2);
*
* //Example 1: Sets values for a Cartesian instance
* var a = new Cartesian4();
* Matrix4.getRow(m, 2, a);
*
* // a.x = 18.0; a.y = 19.0; a.z = 20.0; a.w = 21.0;
*/
Matrix4.getRow = function(matrix, index, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -980,6 +1041,22 @@ define([
* @exception {DeveloperError} index is required and must be 0, 1, 2, or 3.
*
* @see Cartesian4
*
* @example
* //create a new Matrix4 instance with new row values from the Cartesian4 instance
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.setRow(m, 2, new Cartesian4(99.0, 98.0, 97.0, 96.0));
*
* // m remains the same
* // a = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [99.0, 98.0, 97.0, 96.0]
* // [22.0, 23.0, 24.0, 25.0]
*
*/
Matrix4.setRow = function(matrix, index, cartesian, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -1310,6 +1387,22 @@ define([
*
* @exception {DeveloperError} matrix is required.
* @exception {DeveloperError} scalar is required and must be a number.
*
* @example
* //create a Matrix4 instance which is a scaled version of the supplied Matrix4
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.multiplyByScalar(m, -2);
*
* // m remains the same
* // a = [-20.0, -22.0, -24.0, -26.0]
* // [-28.0, -30.0, -32.0, -34.0]
* // [-36.0, -38.0, -40.0, -42.0]
* // [-44.0, -46.0, -48.0, -50.0]
*
*/
Matrix4.multiplyByScalar = function(matrix, scalar, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -1353,6 +1446,22 @@ define([
* @return {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
*
* @exception {DeveloperError} matrix is required.
*
* @example
* //create a new Matrix4 instance which is a negation of a Matrix4
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.negate(m);
*
* // m remains the same
* // a = [-10.0, -11.0, -12.0, -13.0]
* // [-14.0, -15.0, -16.0, -17.0]
* // [-18.0, -19.0, -20.0, -21.0]
* // [-22.0, -23.0, -24.0, -25.0]
*
*/
Matrix4.negate = function(matrix, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -1393,6 +1502,22 @@ define([
* @return {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
*
* @exception {DeveloperError} matrix is required.
*
* @example
* //returns transpose of a Matrix4
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.negate(m);
*
* // m remains the same
* // a = [10.0, 14.0, 18.0, 22.0]
* // [11.0, 15.0, 19.0, 23.0]
* // [12.0, 16.0, 20.0, 24.0]
* // [13.0, 17.0, 21.0, 25.0]
*
*/
Matrix4.transpose = function(matrix, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -1439,6 +1564,28 @@ define([
* @param {Matrix4} [left] The first matrix.
* @param {Matrix4} [right] The second matrix.
* @return {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
*
* @example
* //compares two Matrix4 instances
*
* // a = [10.0, 14.0, 18.0, 22.0]
* // [11.0, 15.0, 19.0, 23.0]
* // [12.0, 16.0, 20.0, 24.0]
* // [13.0, 17.0, 21.0, 25.0]
*
* // b = [10.0, 14.0, 18.0, 22.0]
* // [11.0, 15.0, 19.0, 23.0]
* // [12.0, 16.0, 20.0, 24.0]
* // [13.0, 17.0, 21.0, 25.0]
*
* if(Matrix4.equals(a,b)) {
* console.log("Both matrices are equal");
* } else {
* console.log("They are not equal");
* }
*
* //Prints "Both matrices are equal" on the console
*
*/
Matrix4.equals = function(left, right) {
return (left === right) ||
Expand Down Expand Up @@ -1474,6 +1621,28 @@ define([
* @return {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
*
* @exception {DeveloperError} epsilon is required and must be a number.
*
* @example
* //compares two Matrix4 instances
*
* // a = [10.5, 14.5, 18.5, 22.5]
* // [11.5, 15.5, 19.5, 23.5]
* // [12.5, 16.5, 20.5, 24.5]
* // [13.5, 17.5, 21.5, 25.5]
*
* // b = [10.0, 14.0, 18.0, 22.0]
* // [11.0, 15.0, 19.0, 23.0]
* // [12.0, 16.0, 20.0, 24.0]
* // [13.0, 17.0, 21.0, 25.0]
*
* if(Matrix4.equalsEpsilon(a,b,0.1)){
* console.log("Difference between both the matrices is less than 0.1");
* } else {
* console.log("Difference between both the matrices is not less than 0.1");
* }
*
* //Prints "Difference between both the matrices is not less than 0.1" on the console
*
*/
Matrix4.equalsEpsilon = function(left, right, epsilon) {
if (typeof epsilon !== 'number') {
Expand Down Expand Up @@ -1537,6 +1706,22 @@ define([
* @exception {DeveloperError} matrix is required.
*
* @see Matrix3
*
* @example
* // returns a Matrix3 instance from a Matrix4 instance
*
* // m = [10.0, 14.0, 18.0, 22.0]
* // [11.0, 15.0, 19.0, 23.0]
* // [12.0, 16.0, 20.0, 24.0]
* // [13.0, 17.0, 21.0, 25.0]
*
* var b = new Matrix3();
* Matrix4.getRotation(m,b);
*
* // b = [10.0, 14.0, 18.0]
* // [11.0, 15.0, 19.0]
* // [12.0, 16.0, 20.0]
*
*/
Matrix4.getRotation = function(matrix, result) {
if (typeof matrix === 'undefined') {
Expand Down