Breakable objects
4 posts • Page 1 of 1
Breakable objects
I've try it few times since we get "readables" but succeed enough to show only now.
code for someone who care
code for someone who care

- Code: Select all
Scene.my.xFor := (n1, n2, code)=>{
n2 > n1 ? {
m := (n1 + n2) / 2;
scene.my.xFor(n1, m, code);
scene.my.xFor(m + 1, n2, code)
} : {code(n1)}
};
scene.my.dl2 := (v) => {v(0)*v(0) + v(1)*v(1)};
Scene.my.near := (s, sl, cpos) => {
I := 0;
L := +inf;
scene.my.xFor (0, sl-1, (n) => {
dl := scene.my.dl2(s(n) - cpos);
dl < L ? {I = n; L = dl} : {};
});
I
};
scene.my.qTrans := (c, cos_a, sin_a, pp) => {
nc := [c(0) * cos_a + c(1) * sin_a, c(1) * cos_a - c(0) * sin_a];
nc + pp;
};
scene.my.clonePoly := (poly, newSurf, newCS, br, nvel) => {
scene.addPolygon({
vel := poly.vel + nvel;
angvel := poly.angvel;
_breakable := br;
surfaces := [newSurf];
collideWater := poly.collideWater;
color := poly.color;
friction := poly.friction;
restitution := poly.restitution;
zDepth := poly.zDepth;
drawBorder := poly.drawBorder;
density := poly.density;
texture := poly.texture;
textureClamped := poly.textureClamped;
textureMatrix := poly.textureMatrix;
collideSet := newCS;
})
};
Scene.my.breakPoly := (poly, cpos, vimp) => {
ps := (readable(poly)).surfaces(0);
sl := string.length(ps);
s := [];
cos_a := math.cos(poly.angle); sin_a := - math.sin(poly.angle); pp := poly.pos;
scene.my.xFor(0, sl-1, (i)=>{s = s ++ [scene.my.qTrans(ps(i), cos_a, sin_a, pp)]});
n := scene.my.near(s, sl, cpos);
ns := [s(n) + vimp];
scene.my.xFor (n+1, n+sl-1, (i) => {ns = ns ++ [s(i%sl)]});
ns1 := [s(n),s((n+1)%sl),s(n)+vimp];
ns2 := [s(n),s((n-1+sl)%sl),s(n)+vimp];
scene.my.clonePoly(poly, ns, 3, true, [0,0]);
scene.my.clonePoly(poly, ns1, 2, false, +vimp*50);
scene.my.clonePoly(poly, ns2, 2, false, +vimp*50);
scene.removeEntity(poly)
};
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Breakable objects
v2 with textures support
- Code: Select all
Scene.my.tmTrans := (tm, ang, shift) => {
print("Transform: "+ ang + " " + shift);
sin_a := math.sin(ang);
cos_a := math.cos(ang);
m1 := [[tm(0),tm(1)], [tm(3),tm(4)]];
m2 := [[cos_a, sin_a], [-sin_a, cos_a]];
mx := [[m1(0)(0)*m2(0)(0) + m1(0)(1)*m2(1)(0), m1(0)(0)*m2(0)(1) + m1(0)(1)*m2(1)(1)],
[m1(1)(0)*m2(0)(0) + m1(1)(1)*m2(1)(0), m1(1)(0)*m2(0)(1) + m1(1)(1)*m2(1)(1)]];
sx := [shift(0)*mx(0)(0) + shift(1)*mx(0)(1), shift(0)*mx(1)(0) + shift(1)*mx(1)(1)];
[mx(0)(0), mx(0)(1), tm(2)+sx(0), mx(1)(0), mx(1)(1), tm(5)+sx(1), tm(6), tm(7), tm(8)]
};
Scene.my.txTrans := (tm, ang, shift) => {
sin_a := math.sin(ang);
cos_a := math.cos(ang);
m1 := [[tm(0),tm(1)], [tm(3),tm(4)]];
m2 := [[cos_a, sin_a], [-sin_a, cos_a]];
mx := [[m1(0)(0)*m2(0)(0) + m1(0)(1)*m2(1)(0), m1(0)(0)*m2(0)(1) + m1(0)(1)*m2(1)(1)],
[m1(1)(0)*m2(0)(0) + m1(1)(1)*m2(1)(0), m1(1)(0)*m2(0)(1) + m1(1)(1)*m2(1)(1)]];
[mx(0)(0), mx(0)(1), tm(2)+shift(0), mx(1)(0), mx(1)(1), tm(5)+shift(1), tm(6), tm(7), tm(8)]
};
Scene.my.xFor := (n1, n2, code)=>{
n2 > n1 ? {
m := (n1 + n2) / 2;
scene.my.xFor(n1, m, code);
scene.my.xFor(m + 1, n2, code)
} : {code(n1)}
};
scene.my.dl2 := (v) => {v(0)*v(0) + v(1)*v(1)};
Scene.my.near := (s, sl, cpos) => {
I := 0;
L := +inf;
scene.my.xFor (0, sl-1, (n) => {
dl := scene.my.dl2(s(n) - cpos);
dl < L ? {I = n; L = dl} : {};
});
I
};
Scene.my.impactVel2 := (g0, g1, n) => {
v := g0.vel + g1.vel;
i := v(0)*n(0) + v(1)*n(1);
i*i
};
scene.my.trans := (geom, c) => {
nc := c - geom.pos;
cos_a := math.cos(geom.angle);
sin_a := math.sin(geom.angle);
[nc(0) * cos_a + nc(1) * sin_a, nc(1) * cos_a - nc(0) * sin_a];
};
scene.my.deTrans := (geom, c) => {
nc := c + geom.pos;
cos_a := math.cos(geom.angle);
sin_a := - math.sin(geom.angle);
[nc(0) * cos_a + nc(1) * sin_a, nc(1) * cos_a - nc(0) * sin_a];
};
scene.my.qTrans := (c, cos_a, sin_a, pp) => {
nc := [c(0) * cos_a + c(1) * sin_a, c(1) * cos_a - c(0) * sin_a];
nc + pp;
};
scene.my.clonePoly := (poly, newSurf, newCS, br, nvel) => {
p := scene.addPolygon({
vel := poly.vel + nvel;
angvel := poly.angvel;
_breakable := br;
surfaces := [newSurf];
collideWater := poly.collideWater;
color := poly.color;
friction := poly.friction;
restitution := poly.restitution;
zDepth := poly.zDepth;
drawBorder := poly.drawBorder;
density := poly.density;
texture := poly.texture;
textureClamped := poly.textureClamped;
collideSet := newCS;
});
p.textureMatrix = scene.my.tmTrans(poly.textureMatrix, poly.angle, p.pos - poly.pos);
};
Scene.my.breakPoly := (poly, cpos, vimp) => {
ps := (readable(poly)).surfaces(0);
sl := string.length(ps);
s := [];
cos_a := math.cos(poly.angle); sin_a := - math.sin(poly.angle); pp := poly.pos;
scene.my.xFor(0, sl-1, (i)=>{s = s ++ [scene.my.qTrans(ps(i), cos_a, sin_a, pp)]});
n := scene.my.near(s, sl, cpos);
ns := [s(n) + vimp];
scene.my.xFor (n+1, n+sl-1, (i) => {ns = ns ++ [s(i%sl)]; nsc = nsc + s(i%sl)});
ns1 := [s(n),s((n+1)%sl),s(n)+vimp];
ns2 := [s(n),s((n-1+sl)%sl),s(n)+vimp];
scene.my.clonePoly(poly, ns, 3, true, [0,0]);
scene.my.clonePoly(poly, ns1, 2, false, +vimp*30);
scene.my.clonePoly(poly, ns2, 2, false, +vimp*40);
scene.removeEntity(poly)
};
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Breakable objects
What am i missing? The logs just get deleted when i run it.
- halacar
- Posts: 4
- Joined: Wed Apr 25, 2012 10:51 am
Re: Breakable objects
halacar wrote:What am i missing? The logs just get deleted when i run it.
Probably last Algodoo version 2.0.2b15 ...

Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 8 guests