Skip to content
Snippets Groups Projects
Commit 1aea5332 authored by Jake Read's avatar Jake Read
Browse files

rectangular collision OK, going to try to cleanup

parent f3a52926
Branches
No related tags found
No related merge requests found
......@@ -45,6 +45,7 @@ export default function(radius) {
}
function apply(quad, x0, y0, x1, y1) {
let updated = false
var data = quad.data, r
if (data) {
var rj = data.r
......@@ -52,18 +53,16 @@ export default function(radius) {
// prevents from op'ing twice
if (data.index > node.index) {
let lg = false
if(data.index === 2 && node.index === 0 && true){
if(data.index === 2 && node.index === 0 && false){
lg = true
}
// quad.data is the node,
// quad contains the x0, y0, x1, y1 ?
// atm, this is websocket and link (I think)
// oook ..
// by domain intersections...
// | -------- x ------ |
// | ------------ x ------ |
// | ---- x --- |
// node left, right (shouldn't be 1-based ...)
// node left, right (a note: .bb.x- should be 0-based
let nxl = node.x + node.bb.x1
let nxr = node.x + node.bb.x2
// data left, right
......@@ -78,60 +77,47 @@ export default function(radius) {
let dyb = data.y + data.bb.y2
// and check,
if(nyt < dyt && dyt < nyb || nyt < dyb && dyb < nyb){
updated = true
// ok then, compute centers to find a direction for force-exertion
// maybe should also do this in prepare also (and the node data, only once)
if(lg) console.log('col')
let cnx = (nxr - nxl) / 2 + nxl
let cny = (nyb - nyt) / 2 + nyt
let cdx = (dxr - dxl) / 2 + dxl
let cdy = (dyb - dyt) / 2 + dyt
if(lg) console.log(cnx, cny, 'to', cdx, cdy)
// x overlap term
let xo = 0
if(cnx < cdx){
xo = nxr - dxl
} else {
xo = nxl - dxr
}
if(lg) console.log('xo', xo)
// y overlap term
let yo = 0
if(cny < cdy){
yo = nyb - dyt
} else {
yo = nyt - dyb
}
if(lg) console.log('yo', yo)
let damp = 0.4
// just assert one axis, otherwise everything ends up
if(Math.abs(xo) > Math.abs(yo)){
node.vy -= yo * damp
data.vy += yo * damp
} else {
node.vx -= xo * damp
data.vx += xo * damp
}
}
}
// x-and-y domains must be intersecting before any action necessary
// so walk a tree of possibilities
// xi, yi are this node's next positions, so x and y are intersections ?
// l is the l of the intersection, by sqrt (len c) and we are comp' to r sqrd
// to avoid the sqrt calc, nice
/*
var x = xi - data.x - data.vx,
y = yi - data.y - data.vy,
l = x * x + y * y
if (l < r * r) {
if (x === 0) x = jiggle(), l += x * x
if (y === 0) y = jiggle(), l += y * y
l = (r - (l = Math.sqrt(l))) / l * strength
//if(node.index === 3) console.log(node)
node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj))
node.vy += (y *= l) * r
data.vx -= x * (r = 1 - r)
data.vy -= y * r
}
*/
}
return
} // end if-data
// If the callback returns true for a given node,
// then the children of that node are not visited; otherwise, all child nodes are visited.
// just gonna do it exhaustively, then
return false //x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r
return updated //x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r
} // end apply()
}
/*
function prepare(quad) {
// git r back ... from our list,
// so: we will want to mod this to put the quad's nodes's w/h ?
if (quad.data) return quad.r = radii[quad.data.index]
// so quads are *just* the tree, but related to nodes by the .index, nice
for (var i = quad.r = 0; i < 4; ++i) {
if (quad[i] && quad[i].r > quad.r) {
quad.r = quad[i].r
}
}
} */
function initialize() {
if (!nodes) return
var i, n = nodes.length, node
......
......@@ -115,10 +115,7 @@ function Floop(View) {
this.sim = d3.forceSimulation(nodes)
.force('link', d3.forceLink(links).distance((link) => {
// nodes are floaters, links have indice, could do like
return 50
}))
.force('collide', d3.forceCollide((node, i, nodes) => {
return 10
return 400
}))
.force('rectcollide', frect((node, i, nodes) => {
return node.r
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment