Skip to content

Commit

Permalink
Add inspector for bodies.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Sep 3, 2012
1 parent 40b6457 commit 9266bb5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion body.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
var VELOCITY_EPSILON = 1e-6; // velocities below this are treated as zero var VELOCITY_EPSILON = 1e-6; // velocities below this are treated as zero


function Body(world, aabb) { function Body(world, aabb) {
this.world = world;
this.aabb = aabb; this.aabb = aabb;
this.pos = new Float64Array(3); this.pos = new Float64Array(3);
this.vel = new Float64Array(3); this.vel = new Float64Array(3);
Expand All @@ -27,6 +26,7 @@
this.noclip = false; this.noclip = false;


// non-persisted properties // non-persisted properties
this.world = world;
this.worldContacts = null; // TODO should be private this.worldContacts = null; // TODO should be private
this.cameraYLag = 0; this.cameraYLag = 0;
this.debugHitAABBs = []; // filled by collision code this.debugHitAABBs = []; // filled by collision code
Expand Down
42 changes: 41 additions & 1 deletion ui-2d.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


var Blockset = cubes.Blockset; var Blockset = cubes.Blockset;
var BlockType = cubes.BlockType; var BlockType = cubes.BlockType;
var Body = cubes.Body;
var Circuit = cubes.Circuit; var Circuit = cubes.Circuit;
var cyclicSerialize = cubes.storage.cyclicSerialize; var cyclicSerialize = cubes.storage.cyclicSerialize;
var mkelement = cubes.util.mkelement; var mkelement = cubes.util.mkelement;
Expand Down Expand Up @@ -483,7 +484,46 @@
lightCell.appendChild(lightT); lightCell.appendChild(lightT);
lightCell.appendChild(lightR); 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", "", panel.appendChild(mkelement("p", "",
mkelement("em", "", "No details available for this object."))); mkelement("em", "", "No details available for this object.")));
} }
Expand Down
3 changes: 3 additions & 0 deletions util.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@
this[5] = hz; this[5] = hz;
} }


// Convenience arraylikeness
Object.defineProperty(AAB.prototype, "length", {value: 6});

// Convenience for looking up a face by indexes: // Convenience for looking up a face by indexes:
// dim -- axis: x=0 y=1 z=2 // dim -- axis: x=0 y=1 z=2
// dir -- face: low=0 high=1 // dir -- face: low=0 high=1
Expand Down

0 comments on commit 9266bb5

Please sign in to comment.