html网页只能看吧,canvas在网站里能看出来,但是在html里却没有

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

lengthManhattan: function() {

return Math.abs( this.x ) + Math.abs( this.y );

},

normalize: function () {

return this.divideScalar( this.length() || 1 );

},

angle: function () {

// computes the angle in radians with respect to the positive x-axis

var angle = Math.atan2( this.y, this.x );

if ( angle < 0 ) angle += 2 * Math.PI;

return angle;

},

distanceTo: function ( v ) {

return Math.sqrt( this.distanceToSquared( v ) );

},

distanceToSquared: function ( v ) {

var dx = this.x - v.x, dy = this.y - v.y;

return dx * dx + dy * dy;

},

distanceToManhattan: function ( v ) {

return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );

},

setLength: function ( length ) {

return this.normalize().multiplyScalar( length );

},

lerp: function ( v, alpha ) {

this.x += ( v.x - this.x ) * alpha;

this.y += ( v.y - this.y ) * alpha;

return this;

},

lerpVectors: function ( v1, v2, alpha ) {

return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );

},

equals: function ( v ) {

return ( ( v.x === this.x ) && ( v.y === this.y ) );

},

fromArray: function ( array, offset ) {

if ( offset === undefined ) offset = 0;

this.x = array[ offset ];

this.y = array[ offset + 1 ];

return this;

},

toArray: function ( array, offset ) {

if ( array === undefined ) array = [];

if ( offset === undefined ) offset = 0;

array[ offset ] = this.x;

array[ offset + 1 ] = this.y;

return array;

},

fromBufferAttribute: function ( attribute, index, offset ) {

if ( offset !== undefined ) {

console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );

}

this.x = attribute.getX( index );

this.y = attribute.getY( index );

return this;

},

rotateAround: function ( center, angle ) {

var c = Math.cos( angle ), s = Math.sin( angle );

var x = this.x - center.x;

var y = this.y - center.y;

this.x = x * c - y * s + center.x;

this.y = x * s + y * c + center.y;

return this;

}

} );

'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function clamp(value, min, max) {

return Math.max(min, Math.min(max, value));

}

var Pointer = function () {

function Pointer(domElement) {

var _ref = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

var _ref$scaleMin = _ref.scaleMin;

var scaleMin = _ref$scaleMin === undefined ? 0.01 : _ref$scaleMin;

var _ref$scaleMax = _ref.scaleMax;

var scaleMax = _ref$scaleMax === undefined ? 10.0 : _ref$scaleMax;

var _ref$pressureMax = _ref.pressureMax;

var pressureMax = _ref$pressureMax === undefined ? 1.0 : _ref$pressureMax;

var _ref$pressureDuration = _ref.pressureDuration;

var pressureDuration = _ref$pressureDuration === undefined ? 1000 : _ref$pressureDuration;

_classCallCheck(this, Pointer);

if (Pointer.instance) {

return Pointer.instance;

}

this.dom = domElement;

this.opt = { scaleMin: scaleMin, scaleMax: scaleMax, pressureMax: pressureMax, pressureDuration: pressureDuration };

this.pressCheckInterval = 20;

this.deltaPressure = this.opt.pressureMax / this.opt.pressureDuration * this.pressCheckInterval;

this.position = new Vector2();

this.zoomSpeed = 1.0;

this.scale = 1.0;

this.dollyStart = new Vector2();

this.dollyEnd = new Vector2();

this.dollyDelta = new Vector2();

this.addMoveListener(this.onMove.bind(this));

this.addDownListener(this.onDown.bind(this));

this.addUpListener(this.onUp.bind(this));

this.dom.addEventListener('touchstart', this._onTouchZoomStart, false);

this.addZoomListener(this.onZoom.bind(this));

this.isPressing = false;

this.pressure = 0.0;

Pointer.instance = this;

}

Pointer.prototype.setScale = function setScale(val) {

this.scale = clamp(val, this.opt.scaleMin, this.opt.scaleMax);

};

Pointer.prototype.updatePosition = function updatePosition(clientX, clientY) {

var size = Math.min(this.dom.clientWidth, this.dom.clientHeight);

this.position.x = (clientX * 2 - this.dom.clientWidth) / size;

this.position.y = ((this.dom.clientHeight - clientY) * 2 - this.dom.clientHeight) / size;

};

Pointer.prototype.onMove = function onMove(e) {

var x = undefined,

y = undefined;

if (e.touches) {

x = e.touches[0].clientX;

y = e.touches[0].clientY;

} else {

x = e.clientX;

y = e.clientY;

}

this.updatePosition(x, y);

// e.preventDefault();

};

Pointer.prototype.addMoveListener = function addMoveListener(cb) {

var _this = this;

['mousemove', 'touchmove'].forEach(function (evtName) {

_this.dom.addEventListener(evtName, cb, false);

});

};

Pointer.prototype.setPressure = function setPressure(val) {

var valid = val <= this.opt.pressureMax && val >= 0.0;

this.pressure = clamp(val, 0.0, this.opt.pressureMax);

// console.log(this.pressure);

return valid;

};

Pointer.prototype.onDown = function onDown(e) {

var _this2 = this;

if (e instanceof MouseEvent && e.button !== Pointer.BUTTON.MOUSE_LEFT) {

return;

}

this.isPressing = true;

if (e.touches) {

var x = e.touches[0].clientX;

var y = e.touches[0].clientY;

this.updatePosition(x, y);

}

var intervalID = setInterval(function () {

if (!_this2.isPressing || !_this2.setPressure(_this2.pressure + _this2.deltaPressure)) {

clearInterval(intervalID);

}

}, this.pressCheckInterval);

var pressingTest = setInterval(function () {

if (_this2.isPressing) {

var event = new CustomEvent('Pointer.pressing', { detail: _this2.pressure });

_this2.dom.dispatchEvent(event);

} else {

clearInterval(pressingTest);

}

}, this.pressCheckInterval);

};

Pointer.prototype.addDownListener = function addDownListener(cb) {

var _this3 = this;

['mousedown', 'touchstart'].forEach(function (evtName) {

_this3.dom.addEventListener(evtName, cb, false);

});

};

Pointer.prototype.addPressingListener = function addPressingListener(cb) {

var _this4 = this;

['Pointer.pressing', 'Pointer.postpressing'].forEach(function (evtName) {

_this4.dom.addEventListener(evtName, cb, false);

});

};

Pointer.prototype.addPressingEndListener = function addPressingEndListener(cb) {

this.dom.addEventListener('Pointer.pressingEnd', cb, false);

};

Pointer.prototype.onUp = function onUp(e) {

var _this5 = this;

if (e instanceof MouseEvent && e.button !== Pointer.BUTTON.MOUSE_LEFT) {

return;

}

this.isPressing = false;

var intervalID = setInterval(function () {

if (_this5.isPressing || !_this5.setPressure(_this5.pressure - _this5.deltaPressure)) {

var event = new CustomEvent('Pointer.pressingEnd', { detail: _this5.pressure });

_this5.dom.dispatchEvent(event);

clearInterval(intervalID);

} else {

var event = new CustomEvent('Pointer.postpressing', { detail: _this5.pressure });

_this5.dom.dispatchEvent(event);

}

}, this.pressCheckInterval);

};

Pointer.prototype.addUpListener = function addUpListener(cb) {

var _this6 = this;

['mouseup', 'touchend'].forEach(function (evtName) {

_this6.dom.addEventListener(evtName, cb, false);

});

};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值