Skip to content

Commit 4d04415

Browse files
committed
Replace deprecated __defineGetter__ references in camera.js
1 parent ba4cece commit 4d04415

File tree

1 file changed

+83
-48
lines changed

1 file changed

+83
-48
lines changed

tools/camera.js

Lines changed: 83 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -544,63 +544,98 @@
544544
return this.createTransformForView(element);
545545
};
546546

547-
TransformInterface.prototype.createTransformForView = (function() {
548-
var elementCount = 0;
549-
return function(element) {
550-
var transform = document.createElement("transform");
551-
var tid = "Generated_Camera_Transform_" + elementCount++;
552-
transform.setAttribute("id", tid);
553-
element.parentElement.appendChild(transform);
554-
element.setAttribute("transform", "#"+tid);
555-
return transform;
556-
}
557-
})();
547+
var elementCount = 0;
548+
TransformInterface.prototype.createTransformForView = function(element) {
549+
var transform = document.createElement("transform");
550+
var tid = "Generated_Camera_Transform_" + elementCount++;
551+
transform.setAttribute("id", tid);
552+
element.parentElement.appendChild(transform);
553+
element.setAttribute("transform", "#"+tid);
554+
return transform;
555+
};
558556

559-
TransformInterface.prototype.__defineGetter__("orientation", function() {
560-
return XML3D.Quat.fromAxisAngle(this.transform.rotation);
561-
});
562-
TransformInterface.prototype.__defineGetter__("position", function() {
563-
return this.transform.translation;
564-
});
565-
TransformInterface.prototype.__defineSetter__("orientation", function(orientation) {
566-
var aa = XML3D.AxisAngle.fromQuat(orientation);
567-
this.transform.setAttribute("rotation", aa.toDOMString());
568-
});
569-
TransformInterface.prototype.__defineSetter__("position", function(position) {
570-
this.transform.setAttribute("translation", position.toDOMString());
571-
});
572-
TransformInterface.prototype.__defineGetter__("direction", function() {
573-
var dir = new XML3D.Vec3(0, 0, -1);
574-
return dir.mul(this.orientation);
557+
Object.defineProperty(TransformInterface.prototype, "orientation", {
558+
get: function() {
559+
return XML3D.Quat.fromAxisAngle(this.transform.rotation);
560+
},
561+
562+
set: function(orientation) {
563+
var aa = XML3D.AxisAngle.fromQuat(orientation);
564+
this.transform.setAttribute("rotation", aa.toDOMString());
565+
}
575566
});
576-
TransformInterface.prototype.__defineGetter__("upVector", function() {
577-
var up = new XML3D.Vec3(0, 1, 0);
578-
return up.mul(this.orientation);
567+
568+
Object.defineProperty(TransformInterface.prototype, "position", {
569+
get: function() {
570+
return this.transform.translation;
571+
},
572+
573+
set: function(position) {
574+
this.transform.setAttribute("translation", position.toDOMString());
575+
}
579576
});
580-
TransformInterface.prototype.__defineGetter__("fieldOfView", function() {
581-
var fovh = this.element.querySelector("float[name=fovHorizontal]");
582-
if (fovh) {
583-
var h = fovh.getValue();
584-
return 2 * Math.atan(Math.tan(h / 2.0) * this.xml3d.width / this.xml3d.height);
577+
578+
Object.defineProperty(TransformInterface.prototype, "direction", {
579+
get: function() {
580+
var dir = new XML3D.Vec3(0, 0, -1);
581+
return dir.mul(this.orientation);
582+
},
583+
584+
set: function(dir) {
585+
throw("Direction cannot be set directly.");
585586
}
586-
var fovv = this.element.querySelector("float[name=fovVertical]");
587-
if (fovv) {
588-
return fovv.getValue();
587+
});
588+
589+
Object.defineProperty(TransformInterface.prototype, "upVector", {
590+
get: function() {
591+
var up = new XML3D.Vec3(0, 1, 0);
592+
return up.mul(this.orientation);
593+
},
594+
595+
set: function(up) {
596+
throw("Up vector cannot be set directly");
589597
}
590-
return (45 * Math.PI / 180); //Default FOV
591598
});
592599

593-
TransformInterface.prototype.rotateAroundPoint = (function() {
594-
var tmpQuat = new XML3D.Quat();
600+
/**
601+
* This is always the VERTICAL field of view in radians
602+
*/
603+
Object.defineProperty(TransformInterface.prototype, "fieldOfView", {
604+
get: function() {
605+
var fovh = this.element.querySelector("float[name=fovHorizontal]");
606+
if (fovh) {
607+
var h = fovh.getValue();
608+
return 2 * Math.atan(Math.tan(h / 2.0) * this.xml3d.width / this.xml3d.height);
609+
}
610+
var fovv = this.element.querySelector("float[name=fovVertical]");
611+
if (fovv) {
612+
return fovv.getValue();
613+
}
614+
return (45 * Math.PI / 180); //Default FOV
615+
},
595616

596-
return function(q0, p0) {
597-
this.orientation = this.orientation.mul(q0).normalize();
598-
var aa = XML3D.AxisAngle.fromQuat(q0);
599-
var axis = this.inverseTransformOf(aa.axis);
600-
tmpQuat = XML3D.Quat.fromAxisAngle(axis, aa.angle);
601-
this.position = this.position.subtract(p0).mul(tmpQuat).add(p0);
617+
set: function(fov) {
618+
var fovh = this.element.querySelector("float[name=fovHorizontal]");
619+
if (fovh) {
620+
fovh.parentNode.removeChild(fovh);
621+
}
622+
var fovv = this.element.querySelector("float[name=fovVertical]");
623+
if (!fovv) {
624+
fovv = document.createElement("float");
625+
fovv.setAttribute("name", "fovVertical");
626+
this.element.appendChild(fovv);
627+
}
628+
fovv.setValue(fov);
602629
}
603-
})();
630+
});
631+
632+
TransformInterface.prototype.rotateAroundPoint = function(q0, p0) {
633+
this.orientation = this.orientation.mul(q0).normalize();
634+
var aa = XML3D.AxisAngle.fromQuat(q0);
635+
var axis = this.inverseTransformOf(aa.axis);
636+
var tmpQuat = XML3D.Quat.fromAxisAngle(axis, aa.angle);
637+
this.position = this.position.subtract(p0).mul(tmpQuat).add(p0);
638+
};
604639

605640
TransformInterface.prototype.lookAround = function(rotSide, rotUp, upVector) {
606641
var check = rotUp.mul(this.orientation);

0 commit comments

Comments
 (0)