分享

基于HTML5的WebGL呈现A星算法的3D可视化

 昵称10504424 2015-11-18
result[i].y); ball.s({ '3d.visible': true, 'shape3d.opacity': i/index*0.3 + 0.7, 'shape3d.transparent': true }); } } }); } } }, false); createFormPane(); createGrid(); } function createGrid(){ dm.clear(); var ball; gridRows.length = 0; for(var x = 0; x < m; x++) { var nodeRow = []; gridRows.push(nodeRow); for(var y = 0; y < m; y++) { var isWall = Math.floor(Math.random()*(1/formPane.v('frequency'))); if(isWall === 0){ nodeRow.push(0); createNode(x, y).s({ 'batch': 'wall', 'all.color': '#9CA69D' }); }else{ nodeRow.push(1); ball = createNode(x, y).s({ 'shape3d': 'sphere', 'shape3d.color': '#FF703F', '3d.visible': false }); } } } if(!ball){ createGrid(); return; } startBall = createNode(ball.a('x'), ball.a('y'), 'start').s({ 'shape3d': 'sphere', 'shape3d.color': '#FF703F' }); shape = new ht.Shape(); shape.setPoints(new ht.List([ {x: -d, y: d}, {x: d, y: d}, {x: d, y: -d}, {x: -d, y: -d}, {x: -d, y: d} ])); shape.setThickness(4); shape.setTall(w); shape.setElevation(w/2); shape.setClosePath(true); shape.s({ 'all.color': 'rgba(187, 187, 187, 0.8)', 'all.transparent': true, 'all.reverse.cull': true }); dm.add(shape); } function createNode(x, y, tag){ var node = new ht.Node(); tag = tag || "cell_" + x + "_" + y; node.setTag(tag); node.a({ x: x, y: y }); node.s3(w*0.9, w*0.9, w*0.9); node.p3(-d+w*x+w/2, w/2, -d+w*y+w/2); node.s({ 'all.reverse.cull': true, 'shape3d.reverse.cull': true }); dm.add(node); return node; } function createFormPane() { formPane = new ht.widget.FormPane(); formPane.setWidth(230); formPane.setHeight(70); formPane.getView().className = 'formpane'; document.body.appendChild(formPane.getView()); formPane.addRow(['Wall Frequency', { id: 'frequency', slider: { min: 0, max: 0.8, value: 0.1, onValueChanged: function(){ createGrid(); } } }], [100, 0.1]); formPane.addRow([ { id: 'closest', checkBox: { label: 'Try Closest' } }, { id: 'diagonal', checkBox: { label: 'Allow Diagonal' } } ], [0.1, 0.1]); }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约