var Plane3D = function (img, w, h) {
  this.img = img;
  this.canvas = Plane3D.buildCanvs();
  this.canvas.width = w;
  this.canvas.height = h;
  this.api = this.canvas.getContext('2d');
  this.w = w;
  this.h = h;
  this.x = 0;
  this.y = 0;
  this.z = 0;
  this.r = 0;
  this.tick = 0;
  this.deg = 0;
};

Plane3D.prototype.img     = null;
Plane3D.prototype.canvas  = null;
Plane3D.prototype.api     = null;
Plane3D.prototype.x = null;
Plane3D.prototype.y = null;
Plane3D.prototype.z = null;
Plane3D.prototype.r = null;
Plane3D.prototype.w = null;
Plane3D.prototype.h = null;
Plane3D.prototype.deg = null;

Plane3D.prototype.finish = function () {
  this.deg = 0;
  this.tick = 0;
};

Plane3D.prototype.draw = function () {
  var API = this.api,
      v   = Math.cos(deg2rad(this.deg));
  API.clearRect(0, 0, this.w, this.h);
  API.save();
  // var rot = new Matrix(3, 3);
  // rot[1][1] = rat;
  // rot[2][1] = 0;
  // rot[3][1] = this.w * this.tick;
  // rot[1][2] = 0;
  // rot[2][2] = 1;
  // rot[3][2] = 1;
  // API.transform(v, rot[1][2], rot[2][1], rot[2][2], rot[3][1], rot[3][2]);
  API.transform(v, 0, 0, 1, (this.w * this.tick), 1);
  API.drawImage(this.img, 0, 0);
  API.restore();
};

Plane3D.buildCanvs = function () {
  var c = $('<canvas></canvas>')[0];
  document.body.appendChild(c);
  return c;
};
