Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
html { overflow: hidden; touch-action: none; content-zooming: none; } body { position: absolute; margin: 0; padding: 0; width: 100%; height: 100%; background: #000; } #canvas { position: absolute; width: 100%; height: 100%; background: #000; cursor: crosshair; }
JavaScript
~ function() { 'use strict'; function run() { requestAnimationFrame(run); webgl.clear(0, 0.05, 0.1); if (pointer.isDown) { cx += (pointer.x - pointer.xb) / 2000; cy += (pointer.y - pointer.yb) / 2000; cz = 0.015; } cx *= 0.98; cy *= 0.98; cz *= 0.98; camera.move(cx, cy, cz+0.01); gl.drawArrays(gl.TRIANGLES, 0, 30 * nCubes); pointer.xb = pointer.x; pointer.yb = pointer.y; } // init var size = 64, vertices = new Float32Array(90 + 90 * size * size), normals = new Float32Array(90 + 90 * size * size), nCubes = 0, cx = 0, cy = 0, cz = 0; // webgl var gl = webgl.context('canvas'); gl.enable(gl.DEPTH_TEST); gl.enable(gl.CULL_FACE); // create cubes function createCube (x, y, z, l, h, w) { l /= 2; w /= 2; h /= 2; // vertices vertices.set([ x-l,y-h,z+w,x+l,y-h,z+w,x+l,y+h,z+w,x-l,y-h,z+w,x+l,y+h,z+w,x-l,y+h,z+w, x-l,y-h,z-w,x-l,y+h,z-w,x+l,y+h,z-w,x-l,y-h,z-w,x+l,y+h,z-w,x+l,y-h,z-w, x-l,y+h,z-w,x-l,y+h,z+w,x+l,y+h,z+w,x-l,y+h,z-w,x+l,y+h,z+w,x+l,y+h,z-w, x+l,y-h,z-w,x+l,y+h,z-w,x+l,y+h,z+w,x+l,y-h,z-w,x+l,y+h,z+w,x+l,y-h,z+w, x-l,y-h,z-w,x-l,y-h,z+w,x-l,y+h,z+w,x-l,y-h,z-w,x-l,y+h,z+w,x-l,y+h,z-w ], nCubes * 5 * 18); // normals normals.set([ 0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1, 0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1, 0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0, 1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0, -1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0 ], nCubes * 5 * 18); nCubes++; } // create pointer var pointer = { x: 0, y: 0, xb: 0, yb: 0, isDown: false, add: function(elem, events, fn) { for (var i = 0, e = events.split(','); i < e.length; i++) { elem.addEventListener(e[i], fn.bind(pointer), false); } }, pointer: function(e) { var touchMode = e.targetTouches, pointer; if (touchMode) { e.preventDefault(); pointer = touchMode[0]; } else pointer = e; this.x = pointer.clientX; this.y = pointer.clientY; } }; // pointer events pointer.add(window, 'mousemove,touchmove', function(e) {this.pointer(e);}); pointer.add(webgl.canvas, 'mousedown,touchstart', function(e) { this.pointer(e); this.xb = this.x; this.yb = this.y; this.isDown = true; }); pointer.add(window, 'mouseup,touchend,touchcancel', function(e) {this.isDown = false;}); // camera var camera = webgl.camera.init(60); camera.x = 0; camera.y = -2; camera.z = size / 3; camera.ax = 0; camera.ay = 0; camera.move = function (deltaX, deltaY, deltaZ) { this.ax -= deltaX / 10; this.ay -= deltaY / 10; this.x -= Math.sin(this.ax) * deltaZ; this.z -= Math.cos(this.ax) * deltaZ; this.y -= Math.sin(this.ay) * deltaZ; if (this.y > -0.5) this.y = -0.5; if (this.x > size * 0.5) this.x = size * 0.5; else if (this.x < -size * 0.5) this.x = -size * 0.5; if (this.z > size * 0.5) this.z = size * 0.5; else if (this.z < -size * 0.5) this.z = -size * 0.5; this.mvMatrix.identity().rotateX(-this.ay).rotateY(-this.ax).translate([-this.x, this.y, -this.z]); this.webgl.uniforms.uMVMatrix.set(this.mvMatrix); this.normalMatrix.normalFromMat4(this.mvMatrix); this.webgl.uniforms.uNMatrix.set(this.normalMatrix); }; // create world createCube(0, -0.1, 0, size * 20, 0.1, size * 20); for (var x = 0; x < size; x++) { for (var y = 0; y < size; y++) { var xf = x - size * 0.5, yf = y - size * 0.5, d = Math.sqrt(xf * xf + yf * yf), h = 0.25 + 30 * Math.random() / d, w = 0.7; if (d < size * 0.5) createCube(xf, h * 0.5, yf, w, h, w); } } webgl.attributes.aVertexPosition.load(vertices, 3); webgl.attributes.aVertexNormal.load(normals, 3); // set lightning webgl.uniforms.uAmbientColor.set(0,0,0); webgl.uniforms.uPointLightingLocation.set(0, -1, -10); webgl.uniforms.uPointLightingSpecularColor.set(1,0.55,0.15); webgl.uniforms.uPointLightingDiffuseColor.set(0,0.25,0.5); run(); } ();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>3D城市-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号