mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
only adds lastMovedBy when there was no damage - fixes #99
This commit is contained in:
parent
e370adf746
commit
0edde06d67
8 changed files with 403 additions and 21 deletions
|
|
@ -35,9 +35,9 @@ function(Parent, Nc, Parser, Settings) {
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerController.prototype.handActionRequest = function(options) {
|
PlayerController.prototype.handActionRequest = function(options) {
|
||||||
options.x = parseFloat(options.x) || 0;
|
options.x = parseFloat(options.x) || 0.0;
|
||||||
options.y = parseFloat(options.y) || 0;
|
options.y = parseFloat(options.y) || 0.0;
|
||||||
options.av = parseFloat(options.av) || 0;
|
options.av = parseFloat(options.av) || 0.0;
|
||||||
if (options) this.player.handActionRequest(options);
|
if (options) this.player.handActionRequest(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,17 @@ function (Parent, Layer, Settings, Nc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
RubeDoll.prototype.render = function() {
|
RubeDoll.prototype.render = function() {
|
||||||
Parent.prototype.render.call(this);
|
//Parent.prototype.render.call(this);
|
||||||
|
|
||||||
|
Nc.trigger(Nc.ns.client.view.mesh.update,
|
||||||
|
this.layerId,
|
||||||
|
this.mesh,
|
||||||
|
{
|
||||||
|
x: this.body.GetPosition().x * Settings.RATIO,
|
||||||
|
y: this.body.GetPosition().y * Settings.RATIO,
|
||||||
|
rotation: this.body.GetAngle()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if(this.limbs) {
|
if(this.limbs) {
|
||||||
for(var name in this.limbMeshes) {
|
for(var name in this.limbMeshes) {
|
||||||
|
|
@ -187,6 +197,10 @@ function (Parent, Layer, Settings, Nc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
RubeDoll.prototype.flip = function(direction) {
|
RubeDoll.prototype.flip = function(direction) {
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Parent.prototype.flip.call(this, direction);
|
Parent.prototype.flip.call(this, direction);
|
||||||
|
|
||||||
// flipping depth of right body side arm/leg images with left
|
// flipping depth of right body side arm/leg images with left
|
||||||
|
|
|
||||||
|
|
@ -421,7 +421,7 @@ function () {
|
||||||
"height": "9",
|
"height": "9",
|
||||||
|
|
||||||
"type": "rubedoll",
|
"type": "rubedoll",
|
||||||
"grabAngle": "0.1",
|
"grabAngle": "0.001", // seems to be a bug, that 0 does not work!
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ function () {
|
||||||
BOX2D_WORLD_AABB_SIZE: 3000,
|
BOX2D_WORLD_AABB_SIZE: 3000,
|
||||||
BOX2D_ALLOW_SLEEP: true,
|
BOX2D_ALLOW_SLEEP: true,
|
||||||
BOX2D_GRAVITY: 26,
|
BOX2D_GRAVITY: 26,
|
||||||
BOX2D_VELOCITY_ITERATIONS: 200,
|
BOX2D_VELOCITY_ITERATIONS: 20,
|
||||||
BOX2D_POSITION_ITERATIONS: 100,
|
BOX2D_POSITION_ITERATIONS: 10, // 200/100 created problems (awful teleporting when repositioning joints)
|
||||||
BOX2D_TIME_STEP: 1 / 60,
|
BOX2D_TIME_STEP: 1 / 60,
|
||||||
|
|
||||||
// PATHS
|
// PATHS
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ function (Parent, Box2D, Options, Settings, Exception, Nc, Assert) {
|
||||||
);
|
);
|
||||||
this.body.SetPosition(position);
|
this.body.SetPosition(position);
|
||||||
this.flip(direction);
|
this.flip(direction);
|
||||||
this.body.SetAngle((this.options.grabAngle || 0) * direction);
|
this.body.SetAngle((this.options.grabAngle || 0.0) * direction);
|
||||||
};
|
};
|
||||||
|
|
||||||
Item.prototype.getGrabPoint = function() {
|
Item.prototype.getGrabPoint = function() {
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
|
||||||
chestPosition.y + this.options.limbs.head.y / Settings.RATIO
|
chestPosition.y + this.options.limbs.head.y / Settings.RATIO
|
||||||
);
|
);
|
||||||
this.limbs.head.SetPosition(position);
|
this.limbs.head.SetPosition(position);
|
||||||
this.limbs.head.SetAngle((this.options.grabAngle || 0) * direction);
|
this.limbs.head.SetAngle((this.options.grabAngle || 0.0) * direction);
|
||||||
};
|
};
|
||||||
|
|
||||||
RagDoll.prototype.throw = function(options, carrierVelocity) {
|
RagDoll.prototype.throw = function(options, carrierVelocity) {
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,11 @@ define([
|
||||||
"Game/Config/Settings",
|
"Game/Config/Settings",
|
||||||
"Lib/Utilities/Assert",
|
"Lib/Utilities/Assert",
|
||||||
"Lib/Utilities/NotificationCenter",
|
"Lib/Utilities/NotificationCenter",
|
||||||
|
"Lib/Utilities/Matrix",
|
||||||
"json!Game/Asset/RubeDoll.json" // using requirejs json loader plugin
|
"json!Game/Asset/RubeDoll.json" // using requirejs json loader plugin
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, Matrix, RubeDollJson) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
@ -66,11 +67,21 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
||||||
|
|
||||||
this.joints = scene.joints;
|
this.joints = scene.joints;
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
for (var i in this.joints) {
|
for (var i in this.joints) {
|
||||||
this.limits[i] = {
|
this.limits[i] = {
|
||||||
lower: this.joints[i].GetLowerLimit(),
|
lower: this.joints[i].GetLowerLimit(),
|
||||||
upper: this.joints[i].GetUpperLimit(),
|
upper: this.joints[i].GetUpperLimit(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.joints[i].EnableLimit(false);
|
||||||
|
|
||||||
|
if(count < 4 && this.joints[i] instanceof Box2D.Dynamics.Joints.b2RevoluteJoint) {
|
||||||
|
console.log(i);
|
||||||
|
} else {
|
||||||
|
body.GetWorld().DestroyJoint(this.joints[i]);
|
||||||
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -82,7 +93,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
||||||
|
|
||||||
RubeDoll.prototype.flip = function(direction) {
|
RubeDoll.prototype.flip = function(direction) {
|
||||||
|
|
||||||
Parent.prototype.flip.call(this, direction);
|
//Parent.prototype.flip.call(this, direction);
|
||||||
/*
|
/*
|
||||||
|
|
||||||
for (var i in this.joints) {
|
for (var i in this.joints) {
|
||||||
|
|
@ -109,24 +120,45 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
||||||
};
|
};
|
||||||
|
|
||||||
RubeDoll.prototype.reposition = function(handPosition, direction) {
|
RubeDoll.prototype.reposition = function(handPosition, direction) {
|
||||||
|
console.log('repo');
|
||||||
|
|
||||||
var oldPosition = this.getPosition();
|
var oldPosition = this.getPosition();
|
||||||
|
var oldAngle = this.body.GetAngle();
|
||||||
Parent.prototype.reposition.call(this, handPosition, direction);
|
Parent.prototype.reposition.call(this, handPosition, direction);
|
||||||
|
var differenceAngle = oldAngle - this.body.GetAngle();
|
||||||
|
|
||||||
//this.body.SetType(Box2D.Dynamics.b2Body.b2_staticBody)
|
//this.body.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0));
|
||||||
|
|
||||||
var newPosition = this.getPosition();
|
var offset = Box2D.Common.Math.b2Math.SubtractVV(this.getPosition(), oldPosition);
|
||||||
var b2Math = Box2D.Common.Math.b2Math;
|
var grabAngle = (this.options.grabAngle || 0.001);
|
||||||
var offset = b2Math.SubtractVV(newPosition, oldPosition);
|
|
||||||
|
|
||||||
for(var limb in this.limbs) {
|
for(var key in this.limbs) {
|
||||||
var position = this.limbs[limb].GetPosition().Copy();
|
var limb = this.limbs[key];
|
||||||
|
|
||||||
|
// Setting position offset first (floor to hand)
|
||||||
|
var position = limb.GetPosition().Copy();
|
||||||
position.Add(offset);
|
position.Add(offset);
|
||||||
this.limbs[limb].SetPosition(position);
|
limb.SetPosition(position);
|
||||||
//this.limbs[limb].SetType(Box2D.Dynamics.b2Body.b2_staticBody)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// grabing local point to "rotate" around (x, y position transform only)
|
||||||
|
var localPoint = this.body.GetLocalPoint(limb.GetPosition().Copy());
|
||||||
|
|
||||||
|
// create rotation matrix from chest rotation difference
|
||||||
|
var mat = Box2D.Common.Math.b2Mat22.FromAngle(differenceAngle);
|
||||||
|
|
||||||
|
// matrix multiplication with local limb position
|
||||||
|
position = Box2D.Common.Math.b2Math.MulTMV(mat, localPoint);
|
||||||
|
|
||||||
|
// translating back to global position
|
||||||
|
var globalPoint = this.body.GetWorldPoint(position);
|
||||||
|
limb.SetPosition(globalPoint);
|
||||||
|
|
||||||
|
// relative limb rotating by chest rotation difference
|
||||||
|
limb.SetAngle(limb.GetAngle() - differenceAngle);
|
||||||
|
|
||||||
|
//limb.SetType(Box2D.Dynamics.b2Body.b2_staticBody);
|
||||||
|
//limb.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RubeDoll.prototype.setVelocities = function(options) {
|
RubeDoll.prototype.setVelocities = function(options) {
|
||||||
|
|
@ -152,6 +184,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
||||||
|
|
||||||
Parent.prototype.setUpdateData.call(this, update);
|
Parent.prototype.setUpdateData.call(this, update);
|
||||||
|
|
||||||
|
/*
|
||||||
for(var name in update.limbs) {
|
for(var name in update.limbs) {
|
||||||
Assert.number(update.limbs[name].p.x, update.limbs[name].p.y);
|
Assert.number(update.limbs[name].p.x, update.limbs[name].p.y);
|
||||||
Assert.number(update.limbs[name].a);
|
Assert.number(update.limbs[name].a);
|
||||||
|
|
@ -164,6 +197,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
||||||
this.limbs[name].SetLinearVelocity(update.limbs[name].lv);
|
this.limbs[name].SetLinearVelocity(update.limbs[name].lv);
|
||||||
this.limbs[name].SetAngularVelocity(update.limbs[name].av);
|
this.limbs[name].SetAngularVelocity(update.limbs[name].av);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
RubeDoll.prototype.destroy = function() {
|
RubeDoll.prototype.destroy = function() {
|
||||||
|
|
|
||||||
334
app/Lib/Utilities/Matrix.js
Normal file
334
app/Lib/Utilities/Matrix.js
Normal file
|
|
@ -0,0 +1,334 @@
|
||||||
|
define([
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
Stolen from Pixi V2
|
||||||
|
*/
|
||||||
|
|
||||||
|
function () {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
|
||||||
|
*
|
||||||
|
* @class Point
|
||||||
|
* @constructor
|
||||||
|
* @param x {Number} position of the point on the x axis
|
||||||
|
* @param y {Number} position of the point on the y axis
|
||||||
|
*/
|
||||||
|
var Point = function(x, y)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @property x
|
||||||
|
* @type Number
|
||||||
|
* @default 0
|
||||||
|
*/
|
||||||
|
this.x = x || 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property y
|
||||||
|
* @type Number
|
||||||
|
* @default 0
|
||||||
|
*/
|
||||||
|
this.y = y || 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a clone of this point
|
||||||
|
*
|
||||||
|
* @method clone
|
||||||
|
* @return {Point} a copy of the point
|
||||||
|
*/
|
||||||
|
Point.prototype.clone = function()
|
||||||
|
{
|
||||||
|
return new Point(this.x, this.y);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the point to a new x and y position.
|
||||||
|
* If y is omitted, both x and y will be set to x.
|
||||||
|
*
|
||||||
|
* @method set
|
||||||
|
* @param [x=0] {Number} position of the point on the x axis
|
||||||
|
* @param [y=0] {Number} position of the point on the y axis
|
||||||
|
*/
|
||||||
|
Point.prototype.set = function(x, y)
|
||||||
|
{
|
||||||
|
this.x = x || 0;
|
||||||
|
this.y = y || ( (y !== 0) ? this.x : 0 ) ;
|
||||||
|
};
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
Point.prototype.constructor = Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Matrix class is now an object, which makes it a lot faster,
|
||||||
|
* here is a representation of it :
|
||||||
|
* | a | b | tx|
|
||||||
|
* | c | d | ty|
|
||||||
|
* | 0 | 0 | 1 |
|
||||||
|
*
|
||||||
|
* @class Matrix
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
var Matrix = function()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @property a
|
||||||
|
* @type Number
|
||||||
|
* @default 1
|
||||||
|
*/
|
||||||
|
this.a = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property b
|
||||||
|
* @type Number
|
||||||
|
* @default 0
|
||||||
|
*/
|
||||||
|
this.b = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property c
|
||||||
|
* @type Number
|
||||||
|
* @default 0
|
||||||
|
*/
|
||||||
|
this.c = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property d
|
||||||
|
* @type Number
|
||||||
|
* @default 1
|
||||||
|
*/
|
||||||
|
this.d = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property tx
|
||||||
|
* @type Number
|
||||||
|
* @default 0
|
||||||
|
*/
|
||||||
|
this.tx = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property ty
|
||||||
|
* @type Number
|
||||||
|
* @default 0
|
||||||
|
*/
|
||||||
|
this.ty = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:
|
||||||
|
*
|
||||||
|
* a = array[0]
|
||||||
|
* b = array[1]
|
||||||
|
* c = array[3]
|
||||||
|
* d = array[4]
|
||||||
|
* tx = array[2]
|
||||||
|
* ty = array[5]
|
||||||
|
*
|
||||||
|
* @method fromArray
|
||||||
|
* @param array {Array} The array that the matrix will be populated from.
|
||||||
|
*/
|
||||||
|
Matrix.prototype.fromArray = function(array)
|
||||||
|
{
|
||||||
|
this.a = array[0];
|
||||||
|
this.b = array[1];
|
||||||
|
this.c = array[3];
|
||||||
|
this.d = array[4];
|
||||||
|
this.tx = array[2];
|
||||||
|
this.ty = array[5];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an array from the current Matrix object.
|
||||||
|
*
|
||||||
|
* @method toArray
|
||||||
|
* @param transpose {Boolean} Whether we need to transpose the matrix or not
|
||||||
|
* @return {Array} the newly created array which contains the matrix
|
||||||
|
*/
|
||||||
|
Matrix.prototype.toArray = function(transpose)
|
||||||
|
{
|
||||||
|
if(!this.array) this.array = new Float32Array(9);
|
||||||
|
var array = this.array;
|
||||||
|
|
||||||
|
if(transpose)
|
||||||
|
{
|
||||||
|
array[0] = this.a;
|
||||||
|
array[1] = this.b;
|
||||||
|
array[2] = 0;
|
||||||
|
array[3] = this.c;
|
||||||
|
array[4] = this.d;
|
||||||
|
array[5] = 0;
|
||||||
|
array[6] = this.tx;
|
||||||
|
array[7] = this.ty;
|
||||||
|
array[8] = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
array[0] = this.a;
|
||||||
|
array[1] = this.c;
|
||||||
|
array[2] = this.tx;
|
||||||
|
array[3] = this.b;
|
||||||
|
array[4] = this.d;
|
||||||
|
array[5] = this.ty;
|
||||||
|
array[6] = 0;
|
||||||
|
array[7] = 0;
|
||||||
|
array[8] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a new position with the current transformation applied.
|
||||||
|
* Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
|
||||||
|
*
|
||||||
|
* @method apply
|
||||||
|
* @param pos {Point} The origin
|
||||||
|
* @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input)
|
||||||
|
* @return {Point} The new point, transformed through this matrix
|
||||||
|
*/
|
||||||
|
Matrix.prototype.apply = function(pos, newPos)
|
||||||
|
{
|
||||||
|
newPos = newPos || new Point();
|
||||||
|
|
||||||
|
newPos.x = this.a * pos.x + this.c * pos.y + this.tx;
|
||||||
|
newPos.y = this.b * pos.x + this.d * pos.y + this.ty;
|
||||||
|
|
||||||
|
return newPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a new position with the inverse of the current transformation applied.
|
||||||
|
* Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
|
||||||
|
*
|
||||||
|
* @method applyInverse
|
||||||
|
* @param pos {Point} The origin
|
||||||
|
* @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input)
|
||||||
|
* @return {Point} The new point, inverse-transformed through this matrix
|
||||||
|
*/
|
||||||
|
Matrix.prototype.applyInverse = function(pos, newPos)
|
||||||
|
{
|
||||||
|
newPos = newPos || new Point();
|
||||||
|
|
||||||
|
var id = 1 / (this.a * this.d + this.c * -this.b);
|
||||||
|
|
||||||
|
newPos.x = this.d * id * pos.x + -this.c * id * pos.y + (this.ty * this.c - this.tx * this.d) * id;
|
||||||
|
newPos.y = this.a * id * pos.y + -this.b * id * pos.x + (-this.ty * this.a + this.tx * this.b) * id;
|
||||||
|
|
||||||
|
return newPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates the matrix on the x and y.
|
||||||
|
*
|
||||||
|
* @method translate
|
||||||
|
* @param {Number} x
|
||||||
|
* @param {Number} y
|
||||||
|
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||||
|
**/
|
||||||
|
Matrix.prototype.translate = function(x, y)
|
||||||
|
{
|
||||||
|
this.tx += x;
|
||||||
|
this.ty += y;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a scale transformation to the matrix.
|
||||||
|
*
|
||||||
|
* @method scale
|
||||||
|
* @param {Number} x The amount to scale horizontally
|
||||||
|
* @param {Number} y The amount to scale vertically
|
||||||
|
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||||
|
**/
|
||||||
|
Matrix.prototype.scale = function(x, y)
|
||||||
|
{
|
||||||
|
this.a *= x;
|
||||||
|
this.d *= y;
|
||||||
|
this.c *= x;
|
||||||
|
this.b *= y;
|
||||||
|
this.tx *= x;
|
||||||
|
this.ty *= y;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a rotation transformation to the matrix.
|
||||||
|
* @method rotate
|
||||||
|
* @param {Number} angle The angle in radians.
|
||||||
|
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||||
|
**/
|
||||||
|
Matrix.prototype.rotate = function(angle)
|
||||||
|
{
|
||||||
|
var cos = Math.cos( angle );
|
||||||
|
var sin = Math.sin( angle );
|
||||||
|
|
||||||
|
var a1 = this.a;
|
||||||
|
var c1 = this.c;
|
||||||
|
var tx1 = this.tx;
|
||||||
|
|
||||||
|
this.a = a1 * cos-this.b * sin;
|
||||||
|
this.b = a1 * sin+this.b * cos;
|
||||||
|
this.c = c1 * cos-this.d * sin;
|
||||||
|
this.d = c1 * sin+this.d * cos;
|
||||||
|
this.tx = tx1 * cos - this.ty * sin;
|
||||||
|
this.ty = tx1 * sin + this.ty * cos;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends the given Matrix to this Matrix.
|
||||||
|
*
|
||||||
|
* @method append
|
||||||
|
* @param {Matrix} matrix
|
||||||
|
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||||
|
*/
|
||||||
|
Matrix.prototype.append = function(matrix)
|
||||||
|
{
|
||||||
|
var a1 = this.a;
|
||||||
|
var b1 = this.b;
|
||||||
|
var c1 = this.c;
|
||||||
|
var d1 = this.d;
|
||||||
|
|
||||||
|
this.a = matrix.a * a1 + matrix.b * c1;
|
||||||
|
this.b = matrix.a * b1 + matrix.b * d1;
|
||||||
|
this.c = matrix.c * a1 + matrix.d * c1;
|
||||||
|
this.d = matrix.c * b1 + matrix.d * d1;
|
||||||
|
|
||||||
|
this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx;
|
||||||
|
this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets this Matix to an identity (default) matrix.
|
||||||
|
*
|
||||||
|
* @method identity
|
||||||
|
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||||
|
*/
|
||||||
|
Matrix.prototype.identity = function()
|
||||||
|
{
|
||||||
|
this.a = 1;
|
||||||
|
this.b = 0;
|
||||||
|
this.c = 0;
|
||||||
|
this.d = 1;
|
||||||
|
this.tx = 0;
|
||||||
|
this.ty = 0;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
return Matrix;
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue