How to use the phaser/src/physics/matter-js/lib/geometry/Vector.dot function in phaser

To help you get started, we’ve selected a few phaser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hexus / phaser-slopes / src / Matter / World.js View on Github external
* the neighbouring edge are not exactly the same as the corresponding direction
								 * constant, we can add an axis aligned ignormal
								 */
								
								// Leftwards ignormal
								if (Math.abs(ignormalVertex.x - tileBody.bounds.min.x) < 1 && !containsNormal(Constants.Directions.LEFT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.LEFT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.LEFT) < 1) {
									tileBody.ignormals.push(Constants.Directions.LEFT);
								}
								
								// Upwards ignormal
								if (Math.abs(ignormalVertex.y - tileBody.bounds.min.y) < 1 && !containsNormal(Constants.Directions.UP, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.UP) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.UP) < 1) {
									tileBody.ignormals.push(Constants.Directions.UP);
								}
								
								// Rightwards ignormal
								if (Math.abs(ignormalVertex.x - tileBody.bounds.max.x) < 1 && !containsNormal(Constants.Directions.RIGHT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.RIGHT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.RIGHT) < 1) {
									tileBody.ignormals.push(Constants.Directions.RIGHT);
								}
								
								// Downwards ignormal
								if (Math.abs(ignormalVertex.y - tileBody.bounds.max.y) < 1 && !containsNormal(Constants.Directions.DOWN, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.DOWN) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.DOWN) < 1) {
									tileBody.ignormals.push(Constants.Directions.DOWN);
								}
							}
						}
					}
				}
			}
			
			// Resolve edge normal data, now that we've seen all the neighbours
			// and ensure ghost vertices are set on each edge
			for (i = 0; i < tileVertices.length; i++) {
github hexus / phaser-slopes / src / Matter / World.js View on Github external
// Link edges to each other
								if (neighbourBody.edges) {
									edge.prev = neighbourBody.edges[j];
									neighbourBody.edges[j].next = edge;
								}
							}
							
							if (trailingEdge && !edge.vertices[3]) {
								edge.vertices[3] = buildEdgeVertex(3, nv2.x, nv2.y, tileBody, true);
							}
							
							// Find the ignormals
							let ignormalVertex = leadingEdge ? nv2 : nv1;
							let tileEdgeNormal = tileBody.axes[i];
							let neighbourEdgeNormal = neighbourBody.axes[j];
							let ignormalCandidate = Vector.dot(tileEdgeNormal, neighbourEdgeNormal) > 0;// && !isAxisAligned(tileEdgeNormal) && !isAxisAligned(neighbourEdgeNormal);
							
							// If the tile edge normal and its neighbouring ghost edge normal are less than
							// 90 degrees different, we can set ignormals based on which bounds the joining
							// vertex lands on
							if (ignormalCandidate) {
								/**
								 * If the joining vertex is on a bounds edge, and the normal of its edge and the
								 * the neighbouring edge are not exactly the same as the corresponding direction
								 * constant, we can add an axis aligned ignormal
								 */
								
								// Leftwards ignormal
								if (Math.abs(ignormalVertex.x - tileBody.bounds.min.x) < 1 && !containsNormal(Constants.Directions.LEFT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.LEFT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.LEFT) < 1) {
									tileBody.ignormals.push(Constants.Directions.LEFT);
								}
github hexus / phaser-slopes / src / Matter / SAT.js View on Github external
vertexToBody = Vector._temp[0],
			vertices = bodyB.vertices,
			bodyAPosition = bodyA.position,
			distance,
			vertex,
			vertexA,
			prevIndex,
			vertexB,
			nextIndex;
		
		// Find the closest vertex on bodyB
		for (i = 0; i < vertices.length; i++) {
			vertex = vertices[i];
			vertexToBody.x = vertex.x - bodyAPosition.x;
			vertexToBody.y = vertex.y - bodyAPosition.y;
			distance = -Vector.dot(normal, vertexToBody);
			
			if (distance < nearestDistance) {
				nearestDistance = distance;
				vertexA = vertex;
			}
		}
		
		// Find the next closest vertex using the two connected to it
		prevIndex = vertexA.index - 1 >= 0 ? vertexA.index - 1 : vertices.length - 1;
		vertex = vertices[prevIndex];
		vertexToBody.x = vertex.x - bodyAPosition.x;
		vertexToBody.y = vertex.y - bodyAPosition.y;
		nearestDistance = -Vector.dot(normal, vertexToBody);
		vertexB = vertex;
		
		nextIndex = (vertexA.index + 1) % vertices.length;
github hexus / phaser-slopes / src / Matter / World.js View on Github external
let tileEdgeNormal = tileBody.axes[i];
							let neighbourEdgeNormal = neighbourBody.axes[j];
							let ignormalCandidate = Vector.dot(tileEdgeNormal, neighbourEdgeNormal) > 0;// && !isAxisAligned(tileEdgeNormal) && !isAxisAligned(neighbourEdgeNormal);
							
							// If the tile edge normal and its neighbouring ghost edge normal are less than
							// 90 degrees different, we can set ignormals based on which bounds the joining
							// vertex lands on
							if (ignormalCandidate) {
								/**
								 * If the joining vertex is on a bounds edge, and the normal of its edge and the
								 * the neighbouring edge are not exactly the same as the corresponding direction
								 * constant, we can add an axis aligned ignormal
								 */
								
								// Leftwards ignormal
								if (Math.abs(ignormalVertex.x - tileBody.bounds.min.x) < 1 && !containsNormal(Constants.Directions.LEFT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.LEFT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.LEFT) < 1) {
									tileBody.ignormals.push(Constants.Directions.LEFT);
								}
								
								// Upwards ignormal
								if (Math.abs(ignormalVertex.y - tileBody.bounds.min.y) < 1 && !containsNormal(Constants.Directions.UP, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.UP) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.UP) < 1) {
									tileBody.ignormals.push(Constants.Directions.UP);
								}
								
								// Rightwards ignormal
								if (Math.abs(ignormalVertex.x - tileBody.bounds.max.x) < 1 && !containsNormal(Constants.Directions.RIGHT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.RIGHT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.RIGHT) < 1) {
									tileBody.ignormals.push(Constants.Directions.RIGHT);
								}
								
								// Downwards ignormal
								if (Math.abs(ignormalVertex.y - tileBody.bounds.max.y) < 1 && !containsNormal(Constants.Directions.DOWN, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.DOWN) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.DOWN) < 1) {
									tileBody.ignormals.push(Constants.Directions.DOWN);
github hexus / phaser-slopes / src / Matter / World.js View on Github external
if (Math.abs(ignormalVertex.x - tileBody.bounds.min.x) < 1 && !containsNormal(Constants.Directions.LEFT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.LEFT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.LEFT) < 1) {
									tileBody.ignormals.push(Constants.Directions.LEFT);
								}
								
								// Upwards ignormal
								if (Math.abs(ignormalVertex.y - tileBody.bounds.min.y) < 1 && !containsNormal(Constants.Directions.UP, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.UP) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.UP) < 1) {
									tileBody.ignormals.push(Constants.Directions.UP);
								}
								
								// Rightwards ignormal
								if (Math.abs(ignormalVertex.x - tileBody.bounds.max.x) < 1 && !containsNormal(Constants.Directions.RIGHT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.RIGHT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.RIGHT) < 1) {
									tileBody.ignormals.push(Constants.Directions.RIGHT);
								}
								
								// Downwards ignormal
								if (Math.abs(ignormalVertex.y - tileBody.bounds.max.y) < 1 && !containsNormal(Constants.Directions.DOWN, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.DOWN) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.DOWN) < 1) {
									tileBody.ignormals.push(Constants.Directions.DOWN);
								}
							}
						}
					}
				}
			}
			
			// Resolve edge normal data, now that we've seen all the neighbours
			// and ensure ghost vertices are set on each edge
			for (i = 0; i < tileVertices.length; i++) {
				edge = tileBody.edges[i];
				
				if (edge.ignore) {
					continue;
				}
github hexus / phaser-slopes / src / Matter / World.js View on Github external
function containsNormal(normal, normals) {
	let n;
	
	for (n = 0; n < normals.length; n++) {
		if (!normals[n].ignore && Vector.dot(normal, normals[n]) === 1) {
			return true;
		}
	}
	
	return false;
}
github hexus / phaser-slopes / src / Matter / World.js View on Github external
function isAxisAligned(vector) {
	for (let d in Constants.Directions) {
		let direction = Constants.Directions[d];
		
		if (Vector.dot(direction, vector) === 1) {
			return true;
		}
	}
	
	return false;
}
github hexus / phaser-slopes / src / Matter / SAT.js View on Github external
projectToAxis: function (projection, vertices, axis) {
		let min = Vector.dot(vertices[0], axis),
			max = min,
			i,
			dot;
		
		for (i = 0; i < vertices.length; i += 1) {
			dot = Vector.dot(vertices[i], axis);
			
			if (dot < min) {
				min = dot;
			}
			
			if (dot > max) {
				max = dot;
			}
		}