p5.raycaster
Version:
a simple p5js library for semi 3d rendering with ray casting
132 lines (105 loc) • 4.16 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: MouseControl.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: MouseControl.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* class for some basic input control
* you are advise to write you own controller (based on this class or not)
*/
class MouseControl {
/**
*
* @param {HTMLElement} [ele = null] the element to bind the events to
*/
constructor(ele = null) {
// mouse
this.mouseIsDown = false;
this.mouseX = 0;
this.mouseY = 0;
this.pmouseX = 0;
this.pmouseY = 0;
this.mouseButton = -1;
this.mouseCX = 0;
this.mouseCY = 0;
this.pmouseCX = 0
this.pmouseCY = 0;
this.regControl(ele);
}
/**
* register the control to the page
* @param {HTMLElement} ele
*/
regControl(ele) {
let mt = ele || document;
this.targetElement = mt;
mt.ownerDocument.addEventListener("mousedown", this.mouseDown.bind(this));
mt.ownerDocument.addEventListener("mouseup", this.mouseUp.bind(this));
mt.ownerDocument.addEventListener("mousemove", this.mouseMove.bind(this));
}
removeControl() {
this.targetElement.ownerDocument.removeEventListener("mousedown", this.mouseDown.bind(this));
this.targetElement.ownerDocument.removeEventListener("mouseup", this.mouseUp.bind(this));
this.targetElement.ownerDocument.removeEventListener("mousemove", this.mouseMove.bind(this));
}
/**
*
* @param {MouseEvent} ev
*/
mouseDown(ev) {
ev.preventDefault();
this.mouseIsDown = true;
this.mouseButton = ev.button;
}
/**
*
* @param {MouseEvent} ev
*/
mouseMove(ev) {
this.pmouseX = this.mouseX;
this.pmouseY = this.mouseY;
this.pmouseCX = this.mouseCX;
this.pmouseCY = this.mouseCY;
this.mouseX = ev.offsetX;
this.mouseY = ev.offsetY;
this.mouseCX = ev.clientX;
this.mouseCY = ev.clientY;
}
/**
*
* @param {MouseEvent} ev
*/
mouseUp(ev) {
this.mouseIsDown = false;
this.mouseButton = -1;
}
}
export default MouseControl;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Camera.html">Camera</a></li><li><a href="KeyboardControl.html">KeyboardControl</a></li><li><a href="MouseControl.html">MouseControl</a></li><li><a href="PointerLockControl.html">PointerLockControl</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="TransparentWall.html">TransparentWall</a></li><li><a href="Util.html">Util</a></li><li><a href="World.html">World</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createCamera">createCamera</a></li><li><a href="global.html#createSkyBox">createSkyBox</a></li><li><a href="global.html#createSprite">createSprite</a></li><li><a href="global.html#createTextureMap">createTextureMap</a></li><li><a href="global.html#createWorld">createWorld</a></li><li><a href="global.html#initKeyboardControl">initKeyboardControl</a></li><li><a href="global.html#initMouseControl">initMouseControl</a></li><li><a href="global.html#initPointerLockControl">initPointerLockControl</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Feb 01 2024 12:26:09 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>