I have wheel constructed from 18 rotated by 20 deg in circle.
Only initial position have physics other rotated object have no effect ?
I use STATIC but i rotate them all.
My object have overlaping in that case no physics, if i have no overlaping STATIC object works even in active rotation.
Any suggestion ?
var tex = {
source: ["res/images/wheel-roll/metal/1-low.png"],
mix_operation: "multiply",
};
var tex2 = {
source: ["res/images/bar.png"],
mix_operation: "multiply",
};
var GLOBAL_Z = -16.5
var J = 0;
for(var i = 0;i < 18;i++) {
var b2 = new CANNON.Body({
type: CANNON.Body.STATIC,
mass: 0,
linearDamping: 0.1,
angularDamping: 0.5,
position: new CANNON.Vec3(0, GLOBAL_Z, -1.6)
});
var b3 = new CANNON.Body({
type: CANNON.Body.STATIC,
mass: 0,
linearDamping: 0.1,
angularDamping: 0.5,
position: new CANNON.Vec3(0, GLOBAL_Z, -1.7)
});
var texField = {
source: ["res/images/wheel-roll/" + i + ".png"],
mix_operation: "multiply",
};
matrixEngine.matrixWorld.world.Add("cubeLightTex", 0.2, "roll" + i, texField);
if(i == 0) {
matrixEngine.matrixWorld.world.Add("cubeLightTex", 0.1, "roll__" + i, tex2);
} else {
matrixEngine.matrixWorld.world.Add("cubeLightTex", 0.1, "roll__" + i, tex);
}
var locRot;
var local = (i * 20) * Math.PI / 360;
locRot = new CANNON.Quaternion(0, 0, 0, 0);
locRot.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), local);
var shape = new CANNON.Box(new CANNON.Vec3(0.1, 3.1, 0.1))
b2.addShape(shape, undefined, locRot)
App.scene['roll__' + i].raycast.enabled = false;
// App.scene['roll__' + i].geometry.setScaleByX(-0.1)
// App.scene['roll__' + i].geometry.setScaleByY(-0.3)
App.scene['roll__' + i].geometry.setScaleByZ(2.7)
App.scene['roll__' + i].physics.currentBody = b2;
App.scene['roll__' + i].physics.enabled = true;
this.pWorld.world.addBody(b2);
// NUMBERS FIELDS
var locRotF;
var localF = (i * 20 + 10) * Math.PI / 360;
locRotF = new CANNON.Quaternion(0, 0, 0, 0);
locRotF.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), localF);
var shape = new CANNON.Box(new CANNON.Vec3(0.2, 3, 0.1))
b3.addShape(shape, undefined, locRotF)
App.scene['roll' + i].raycast.enabled = false;
// App.scene['roll' + i].geometry.setScaleByX(-0.1)
App.scene['roll' + i].geometry.setScaleByY(-0.3)
App.scene['roll' + i].geometry.setScaleByZ(2.6)
App.scene['roll' + i].geometry.setTexCoordScaleXFactor(-1);
App.scene['roll' + i].geometry.setTexCoordScaleYFactor(-5);
App.scene['roll' + i].custom.gl_texture = function(object, t) {
var world = matrixEngine.matrixWorld.world;
world.GL.gl.bindTexture(world.GL.gl.TEXTURE_2D, object.textures[t]);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MAG_FILTER, world.GL.gl.LINEAR);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MIN_FILTER, world.GL.gl.LINEAR);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_S, world.GL.gl.REPEAT);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_T, world.GL.gl.REPEAT);
world.GL.gl.texImage2D(world.GL.gl.TEXTURE_2D, 0, world.GL.gl.RGB5_A1,
world.GL.gl.RGB5_A1, world.GL.gl.UNSIGNED_BYTE, object.textures[t].image)
}
App.scene['roll' + i].physics.currentBody = b3;
App.scene['roll' + i].physics.enabled = true;
setTimeout(function() {
for(var i = 0;i < 18;i++) {
App.scene['roll' + i].geometry.setTexCoordScaleXFactor(-1);
App.scene['roll' + i].geometry.setTexCoordScaleYFactor(-5);
}
}, 500)
this.pWorld.world.addBody(b3);
// App.scene.ROLL_ROOT_NUM.subObjs.push(App.scene['roll' + i])
}
animateRoll() {
var STEP = 0;
this.rollTimer = setInterval(() => {
for(var i = 0;i < 18;i++) {
App.scene['roll' + i].rotation.roty =
matrixEngine.utility.radToDeg(App.scene['roll' + i].physics.currentBody.quaternion.toAxisAngle()[1]);
var locRot;
if(STEP > 360) {
STEP = 0
}
var N = (i * 20 + STEP) * Math.PI / 360;
locRot = new CANNON.Quaternion(0, 0, 0, 0);
locRot.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), N);
App.scene['roll' + i].physics.currentBody.quaternion.copy(locRot)
// numbers
App.scene['roll__' + i].rotation.roty =
matrixEngine.utility.radToDeg(App.scene['roll__' + i].physics.currentBody.quaternion.toAxisAngle()[1]);
var locRot;
if(STEP > 360) {
STEP = 0
}
var N = (i * 20 + 10 + STEP) * Math.PI / 360;
locRot = new CANNON.Quaternion(0, 0, 0, 0);
locRot.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), N);
App.scene['roll__' + i].physics.currentBody.quaternion.copy(locRot)
}
STEP = STEP + 1;
this.C = this.C + this.speedRollInit
if(this.speedRollInit < 0.02) {
// clearInterval(this.rollTimer)
} else {
this.speedRollInit = this.speedRollInit - 0.0005
}
}, 12)
}