mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
prepared for box2d joint tests
This commit is contained in:
parent
b155faa63c
commit
5898f29167
4 changed files with 11017 additions and 0 deletions
55
joint/client.js
Normal file
55
joint/client.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
var id = null;
|
||||
var lastIntervalTime = new Date().getTime();
|
||||
|
||||
function setupCanvas() {
|
||||
var debugDraw = new b2DebugDraw();
|
||||
|
||||
debugDraw.SetSprite(document.getElementById("canvas").getContext("2d"));
|
||||
debugDraw.SetDrawScale(30.0);
|
||||
debugDraw.SetFillAlpha(0.5);
|
||||
debugDraw.SetLineThickness(1.0);
|
||||
debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
|
||||
|
||||
world.SetDebugDraw(debugDraw);
|
||||
}
|
||||
|
||||
function init() {
|
||||
setupWorld(9);
|
||||
setupCanvas();
|
||||
|
||||
window.setInterval(update, 1000 / 60);
|
||||
|
||||
var body;
|
||||
|
||||
function update() {
|
||||
var newTime = new Date().getTime()
|
||||
lastIntervalTime = newTime;
|
||||
world.Step(1 / 60, 10, 10);
|
||||
world.DrawDebugData();
|
||||
world.ClearForces();
|
||||
}
|
||||
}
|
||||
|
||||
//helpers
|
||||
|
||||
//http://js-tut.aardon.de/js-tut/tutorial/position.html
|
||||
function getElementPosition(element) {
|
||||
var elem = element, tagname = "", x = 0, y = 0;
|
||||
|
||||
while((typeof(elem) == "object") && (typeof(elem.tagName) != "undefined")) {
|
||||
y += elem.offsetTop;
|
||||
x += elem.offsetLeft;
|
||||
|
||||
tagname = elem.tagName.toUpperCase();
|
||||
|
||||
if(tagname == "BODY") elem = 0;
|
||||
|
||||
if(typeof(elem) == "object") {
|
||||
if(typeof(elem.offsetParent) == "object") elem = elem.offsetParent;
|
||||
}
|
||||
|
||||
return {x: x, y: y};
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = init;
|
||||
Loading…
Add table
Add a link
Reference in a new issue