Browse files

Add inspector for bodies.

  • Loading branch information...
1 parent 40b6457 commit 9266bb51937275693debb13d0e3433118e4d9887 @kpreid committed Sep 2, 2012
Showing with 45 additions and 2 deletions.
  1. +1 −1 body.js
  2. +41 −1 ui-2d.js
  3. +3 −0 util.js
View
2 body.js
@@ -18,7 +18,6 @@
var VELOCITY_EPSILON = 1e-6; // velocities below this are treated as zero
function Body(world, aabb) {
- this.world = world;
this.aabb = aabb;
this.pos = new Float64Array(3);
this.vel = new Float64Array(3);
@@ -27,6 +26,7 @@
this.noclip = false;
// non-persisted properties
+ this.world = world;
this.worldContacts = null; // TODO should be private
this.cameraYLag = 0;
this.debugHitAABBs = []; // filled by collision code
View
42 ui-2d.js
@@ -6,6 +6,7 @@
var Blockset = cubes.Blockset;
var BlockType = cubes.BlockType;
+ var Body = cubes.Body;
var Circuit = cubes.Circuit;
var cyclicSerialize = cubes.storage.cyclicSerialize;
var mkelement = cubes.util.mkelement;
@@ -483,7 +484,46 @@
lightCell.appendChild(lightT);
lightCell.appendChild(lightR);
- }()); else {
+ }()); else if (object instanceof Body) (function () {
+ var body = object;
+
+ var rows;
+ var table = mkelement("table", "",
+ rows = mkelement("tbody", ""));
+ panel.appendChild(table);
+
+ function mkcell(title) {
+ var cell;
+ rows.appendChild(mkelement("tr", "",
+ mkelement("th", "", title + ":"),
+ cell = mkelement("td", "")));
+ return cell;
+ }
+
+ function vectorUI(vector) {
+ var container = document.createElement("span");
+ for (var i = 0; i < vector.length; i++) {
+ if (i !== 0) {
+ container.appendChild(document.createTextNode(", "));
+ }
+ container.appendChild(document.createTextNode(vector[i].toFixed(2)));
+ }
+ return container;
+ }
+
+ mkcell("In world").appendChild(new ObjectChip(refObject(body.world)).element);
+
+ // NOTE: When we allow editing, allow for that AABs are nominally immutable and replaceable whereas pos/vel are mutable and effectively facets
+ mkcell("Size").appendChild(vectorUI(body.aabb));
+ mkcell("Position").appendChild(vectorUI(body.pos));
+ mkcell("Velocity").appendChild(vectorUI(body.vel));
+ mkcell("Yaw").appendChild(document.createTextNode((body.yaw / Math.PI * 180).toFixed(2) + "°"));
+ mkcell("Flying").appendChild(document.createTextNode(body.flying));
+ mkcell("Noclip").appendChild(document.createTextNode(body.noclip));
+
+ // TODO update for changes, editability
+
+ }()); else {
panel.appendChild(mkelement("p", "",
mkelement("em", "", "No details available for this object.")));
}
View
3 util.js
@@ -191,6 +191,9 @@
this[5] = hz;
}
+ // Convenience arraylikeness
+ Object.defineProperty(AAB.prototype, "length", {value: 6});
+
// Convenience for looking up a face by indexes:
// dim -- axis: x=0 y=1 z=2
// dir -- face: low=0 high=1

0 comments on commit 9266bb5

Please sign in to comment.