• 鼠标控制3维操作 不知道能不能获得一些灵感


    简介

    RT, vensor 里面有关于四元数的处理方案

    参考链接

    https://observablehq.com/@d3/versor-dragging

    代码

    <meta charset="utf-8">
    <style>
    </style>
    <body>
        <script src="./d3.js"></script>
        <script src="./versor.js"></script>
        <script src="https://unpkg.com/topojson@3"></script>
        <canvas id="cc" width="500" height="500"></canvas>
        <!-- <srcipt src="./land-50m.json"></srcipt> -->
        <!-- <script src="./land-110m.json"></script> -->
        <script>
            // var topology = topojson.topology({foo: goejson})
            var land110 = ''
            var land50 = ''
            d3.json('http://localhost:5500/land-110m.json').then((world) => land110 = topojson.feature(world, world.objects.land))
            // console.log("land110", land110)
            // land110 = land_110m.then(world => topojson.feature(world, world.objects.land))
            d3.json('http://localhost:5500/land-50m.json').then(world => land50 = topojson.feature(world, world.objects.land))
            sphere = ({type: "Sphere"})
            projection = d3["geoOrthographic"]().precision(0.1)
            height = getheight()
            
            function getheight() {
                width = 500
                const [[x0, y0], [x1, y1]] = d3.geoPath(projection.fitWidth(width, sphere)).bounds(sphere);
                const dy = Math.ceil(y1 - y0), l = Math.min(Math.ceil(x1 - x0), dy);
                projection.scale(projection.scale() * (l - 1) / l).precision(0.2);
                return dy;
            }
            function drag(projection) {
                let v0, q0, r0;
                
                function dragstarted() {
                    v0 = versor.cartesian(projection.invert([d3.event.x, d3.event.y]));
                    q0 = versor(r0 = projection.rotate());
                    console.log("dargstart", v0, "q0", q0)
                    console.log('land110', land110)
                }
                
                function dragged() {
                    const v1 = versor.cartesian(projection.rotate(r0).invert([d3.event.x, d3.event.y])); // 笛卡尔坐标系
                    const q1 = versor.multiply(q0, versor.delta(v0, v1));
                    projection.rotate(versor.rotation(q1));
                }
                
                return d3.drag()
                    .on("start", dragstarted)
                    .on("drag", dragged);
            }
            function init() {
    
                var c=document.getElementById("cc");
                    var context=c.getContext("2d");
                console.log(context)
                // context = context.getContext("2d")
                const path = d3.geoPath(projection, context)
                function render (land) {
                    
                    var c=document.getElementById("cc");
                    var context=c.getContext("2d");
                    context.clearRect(0, 0, width, height)
                    context.beginPath(), path(sphere), context.fillStyle = '#fff', context.fill()
                    context.beginPath(), path(land), context.fillStyle = '#000', context.fill()
                    context.beginPath(), path(sphere), context.stroke()
                }
                d3.select(context.canvas)
                    .call(drag(projection)
                        .on("drag.render", () => render(land110))
                        .on("end.render", () => render(land50)))
                    .call(() => render(land50))
                    .node();
            }
            init()
        </script>
    </body>
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    百科知识 scm文件如何打开
    百科知识 STEP文件如何打开
    百科知识 tar文件如何打开
    百科知识 kux文件如何打开
    app开发中如何利用sessionId来实现服务端与客户端保持回话
    什么是云虚拟主机以及和云服务器之间的区别
    2016年百度百科怎么创建词条(高级技巧篇)
    使用Jsoup获取网页内容超时设置
    如何让自己在天猫开通的商铺能够在百度中输入关键词就能够搜索到
    百度百科词条义项排名靠前秘诀
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/12862787.html
Copyright © 2020-2023  润新知