【three.js练习程序】鼠标滚轮缩放
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ceshi</title>
<script type="text/javascript" src=".\build\three.js"></script>
<style>
body
{
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<!-- 作为Three.js渲染器输出元素 -->
<div id="WebGL-output">
</div>
<!-- 第一个 Three.js 样例代码 -->
<script type="text/javascript"> var cube = new Array(100);
var camera, scene, renderer;
var id = null;
var fov = 45;
var near = 0.1;
var far = 1000;
init(); function init() { scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(fov, window.innerWidth / window.innerHeight, near, far); camera.position.x = 100;
camera.position.y = 100;
camera.position.z = 100;
camera.lookAt(scene.position); //创建一个WebGL渲染器并设置其大小
renderer = new THREE.WebGLRenderer();
renderer.setClearColor(new THREE.Color(0xEEEEEE));
renderer.setSize(window.innerWidth, window.innerHeight); var axes = new THREE.AxisHelper(200);
scene.add(axes); for (var i = 0; i < 100; i++) {
var geometry = new THREE.BoxGeometry(5, 5, 5);
for (var j = 0; j < geometry.faces.length; j += 2) {
var hex = Math.random() * 0xffffff;
geometry.faces[j].color.setHex(hex);
geometry.faces[j + 1].color.setHex(hex);
}
var material = new THREE.MeshBasicMaterial({ vertexColors: THREE.FaceColors, overdraw: 0.5 }); cube[i] = new THREE.Mesh(geometry, material); cube[i].position.x = Math.random() * 100 - 50;
cube[i].position.y = Math.random() * 100 - 50;
cube[i].position.z = Math.random() * 100 - 50; scene.add(cube[i]);
id = setInterval(render, 33);
}
document.addEventListener('mousewheel', mousewheel, false); }
function render() {
for (var i = 0; i < 100; i++) {
cube[i].position.x += Math.random() - 0.5;
cube[i].position.y += Math.random() - 0.5;
cube[i].position.z += Math.random() - 0.5; if (Math.abs(cube[i].position.x) > 100)
cube[i].position.x = 0;
if (Math.abs(cube[i].position.y) > 100)
cube[i].position.y = 0;
if (Math.abs(cube[i].position.z) > 100)
cube[i].position.z = 0;
} renderer.render(scene, camera);
} function mousewheel(e) {
e.preventDefault();
//e.stopPropagation();
if (e.wheelDelta) { //判断浏览器IE,谷歌滑轮事件
if (e.wheelDelta > 0) { //当滑轮向上滚动时
fov -= (near < fov ? 1 : 0);
}
if (e.wheelDelta < 0) { //当滑轮向下滚动时
fov += (fov < far ? 1 : 0);
}
} else if (e.detail) { //Firefox滑轮事件
if (e.detail > 0) { //当滑轮向上滚动时
fov -= 1;
}
if (e.detail < 0) { //当滑轮向下滚动时
fov += 1;
}
}
camera.fov = fov;
camera.updateProjectionMatrix();
renderer.render(scene, camera); } document.getElementById("WebGL-output").appendChild(renderer.domElement); </script>
</body>
</html>
【three.js练习程序】鼠标滚轮缩放的更多相关文章
- js 禁止用户使用Ctrl+鼠标滚轮缩放网页
为什么会有人会使用ctrl+鼠标滚轮缩放网页?坚决禁止! <html> <head> <title>测试</title> <script lang ...
- Winform中设置ZedGraph鼠标滚轮缩放的灵敏度以及设置滚轮缩放的方式(鼠标焦点为中心还是图形中心点)
场景 Winforn中设置ZedGraph曲线图的属性.坐标轴属性.刻度属性: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...
- SceneControl+AE+鼠标滚轮缩放
要为SceneControl设置鼠标滚轮缩放必须定义委托,因为SceneControl没有Wheel事件,所以委托From的Wheel事件 public Form1() { InitializeCom ...
- Engine中如何实现鼠标滚轮缩放反置?
来自:http://zhihu.esrichina.com.cn/?/question/6666 [解决办法]:1,禁用IMapControl的默认鼠标滚轮事件.即设置IMapControl4.Aut ...
- PCB Genesis 鼠标滚轮缩放与TGZ拖放 插件实现
一.背景: 做过CAM的人都用过Geneiss软件,由于处理资料强大,目前奥宝公司出品的Genesis占领整个PCB行业,整个行业无人不知呀, 而此软件有一个吐槽点Genesis 无滚轮缩放与TGZ拖 ...
- JS如何判断鼠标滚轮向上还是向下滚动
前几天偶然看到某前端群有人在问:JS如何判断鼠标滚轮向上还是向下滚动? 我想了想,有点蒙蔽,心想难道不是用scrollTop来判断吗? 但我不确定,也出于好奇心,于是开始了一番探索 思路:通过even ...
- Magnifier.js - 支持鼠标滚轮缩放的图片放大镜效果
Magnifier.js 是一个 JavaScript 库,能够帮助你在图像上实现放大镜效果,支持使用鼠标滚轮放大/缩小功能.放大的图像可以显示在镜头本身或它的外部容器中.Magnifier.js 使 ...
- 关于 WebBrowser调用百度地图API 鼠标滚轮缩放地图级别失灵的解决办法
在桌面程序下 百度地图API的鼠标缩放地图功能可能会失灵无效! 这个原因不是API的问题 小弟试了下在WEB上面是没有问题的 于是考虑可能是WebBrowser的获取焦点问题,于是在主窗体 添加了一个 ...
- js中判断鼠标滚轮方向的方法
前 言 LiuDaP 最近无聊,在做自己的个人站,其中用到了一个关于鼠标滚轮方向判断的方法,今天闲来无聊,就给大家介绍一下吧!!!! 在介绍鼠标事件案例前,让我们先稍微了解一下js中的event ...
- js/jq判断鼠标滚轮方向
js判断鼠标滚轮方向: var scrollFunc = function (e) { e = e || window.event; if (e.wheelDelta) { //判断浏览器IE,谷歌滑 ...
随机推荐
- Redis笔记(2)单机数据库实现
1.前言 上节总结了一下redis的数据结构和对象构成,本章介绍redis数据库一个基本面貌,是如何设计的. 2.数据库 服务器结构redisServer: redisDb *db: 一个数组,保存服 ...
- 函数指针与typedef
#include<bits/stdc++.h> using namespace std; //定义一个函数指针 typedef int (*Fun)(int,int); int add(i ...
- javascript中对条件判断语句的优化 分类: JavaScript 2015-06-07 09:54 832人阅读 评论(2) 收藏
不管写什么程序,平时都会用到条件语句,如:if...else... switch这样的语句,来达到对条件的判断.下面看来一段代码: function abc(test){ if (test == 1) ...
- CompoundScope说明
A class scope adds capabilities to keep track of changes in relatedclass scopes - this allows client ...
- sql字符处理
--Description: 字符处理 --使用: 放到查询分析器里执行就可以了 --示例: select * from dbo.splitstr('12 44 45 50 56 87',' ') o ...
- 记一次解决CSS定位bug思路
事因 网站中的遮罩层大都有一个问题,就是在这个遮罩层中滑动,里面的内容也会跟着滑动,我是这样想的,既然都有这个问题,干脆写一个通用的插件出来,省的每个还得单独处理.如果是单独处理这个问题是比较好解决的 ...
- MVC源码分析 - Action/Result 过滤器执行时机
前面 的篇章, 解析了Action方法的查找, 以及 Authorize, Action, Result, Error 过滤器的加载时机. 也花了两篇去看授权和错误过滤器的使用. 但是对于 Actio ...
- tomcat配置说明,配置不用访问工程名
# 配置项目访问不用输入项目名称 # [重要]亲测 <Host>中的 appBass="" 一定不能带目录,必须为空,因为启动tomcat会启动appBass下面的所有 ...
- Centos7 安装字体库&中文字体
1.概述 在安装一些服务的时候,会涉及到字符编码与字体的问题,字符编码一般在数据库或代码级别设置,字体一般是在系统级别设置.如安装使用jira或confluence的时候,使用一些宏的时候经常会出现乱 ...
- elasticSearch6源码分析(9)ActionModule
1.ActionModule概述 /** * Builds and binds the generic action map, all {@link TransportAction}s, and {@ ...