How to use the phaser/src/physics/matter-js/lib/geometry/Vector.cross 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
let edge1 = Vector.sub(m_v2, m_v1);
	edge1 = Vector.normalise(edge1);
	let edge2;
	
	let m_normal0 = edge.normals[0];
	let m_normal1 = edge.normals[1];
	let m_normal2 = edge.normals[2];

	let convex1 = false;
	let convex2 = false;
	
	// Is there a leading edge, is it convex?
	if (hasVertex0) {
		edge0 = Vector.sub(m_v1, m_v0);
		edge0 = Vector.normalise(edge0);
		convex1 = Vector.cross(edge0, edge1) >= 0.0;
	}
	
	// Is there a trailing edge, is it convex?
	if (hasVertex3) {
		edge2 = Vector.sub(m_v3, m_v2);
		edge2 = Vector.normalise(edge2);
		convex2 = Vector.cross(edge1, edge2) >= 0.0;
	}
	
	// Determine collision normal limits for front and back collisions
	if (hasVertex0 && hasVertex3) {
		if (convex1 && convex2) {
			front.normal = m_normal1;
			front.lowerLimit = m_normal0;
			front.upperLimit = m_normal2;
github hexus / phaser-slopes / src / Matter / SAT.js View on Github external
axis = vertexBody.axes[a];
			
			bodyResult = SAT.overlapNormal(vertexBody.vertices, edgeVertices, axis);
			
			// We have a separating axis, skip this edge
			if (bodyResult.overlap <= 0) {
				return bodyResult;
			}
			
			// Make sure the vertexBody normal is in the edge's normal range
			if (crossLimits >= 0) {
				if (!(Vector.cross(range.lowerLimit, axis) >= 0 && Vector.cross(axis, range.upperLimit) >= 0)) {
					continue;
				}
			} else {
				if (Vector.cross(range.upperLimit, axis) >= 0 && Vector.cross(axis, range.lowerLimit) >= 0) {
					continue;
				}
			}
			
			bodyResult.axisBody = vertexBody;
			bodyResult.axisNumber = a;
			bodyResult.edge = edge;
			bodyResult.type = 'body';
			
			// Use this result if it has the smallest overlap we've seen so far
			if (bodyResult.overlap < edgeResult.overlap) {
				edgeResult = bodyResult;
			}
		}
		
		return edgeResult;
github hexus / phaser-slopes / src / Matter / World.js View on Github external
let convex1 = false;
	let convex2 = false;
	
	// Is there a leading edge, is it convex?
	if (hasVertex0) {
		edge0 = Vector.sub(m_v1, m_v0);
		edge0 = Vector.normalise(edge0);
		convex1 = Vector.cross(edge0, edge1) >= 0.0;
	}
	
	// Is there a trailing edge, is it convex?
	if (hasVertex3) {
		edge2 = Vector.sub(m_v3, m_v2);
		edge2 = Vector.normalise(edge2);
		convex2 = Vector.cross(edge1, edge2) >= 0.0;
	}
	
	// Determine collision normal limits for front and back collisions
	if (hasVertex0 && hasVertex3) {
		if (convex1 && convex2) {
			front.normal = m_normal1;
			front.lowerLimit = m_normal0;
			front.upperLimit = m_normal2;

			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal1);
			back.upperLimit = Vector.neg(m_normal1);
		}  else if (convex1) {
			front.normal = m_normal1;
			front.lowerLimit = m_normal0;
			front.upperLimit = m_normal1;
github hexus / phaser-slopes / src / Matter / SAT.js View on Github external
range = edge.normalRanges.front;
		
		edgeResult = SAT.overlapNormal(vertexBody.vertices, edgeVertices, range.normal);
		
		// We have a separating axis, skip this edge
		if (edgeResult.overlap <= 0) {
			return edgeResult;
		}
		
		edgeResult.axisBody = edgeBody;
		edgeResult.axisNumber = edge.index;
		edgeResult.edge = edge;
		edgeResult.type = 'edge';
		
		crossLimits = Vector.cross(range.lowerLimit, range.upperLimit);
		
		// Test each vertexBody normal
		for (a = 0; a < vertexBody.axes.length; a++) {
			axis = vertexBody.axes[a];
			
			bodyResult = SAT.overlapNormal(vertexBody.vertices, edgeVertices, axis);
			
			// We have a separating axis, skip this edge
			if (bodyResult.overlap <= 0) {
				return bodyResult;
			}
			
			// Make sure the vertexBody normal is in the edge's normal range
			if (crossLimits >= 0) {
				if (!(Vector.cross(range.lowerLimit, axis) >= 0 && Vector.cross(axis, range.upperLimit) >= 0)) {
					continue;
github hexus / phaser-slopes / src / Matter / SAT.js View on Github external
crossLimits = Vector.cross(range.lowerLimit, range.upperLimit);
		
		// Test each vertexBody normal
		for (a = 0; a < vertexBody.axes.length; a++) {
			axis = vertexBody.axes[a];
			
			bodyResult = SAT.overlapNormal(vertexBody.vertices, edgeVertices, axis);
			
			// We have a separating axis, skip this edge
			if (bodyResult.overlap <= 0) {
				return bodyResult;
			}
			
			// Make sure the vertexBody normal is in the edge's normal range
			if (crossLimits >= 0) {
				if (!(Vector.cross(range.lowerLimit, axis) >= 0 && Vector.cross(axis, range.upperLimit) >= 0)) {
					continue;
				}
			} else {
				if (Vector.cross(range.upperLimit, axis) >= 0 && Vector.cross(axis, range.lowerLimit) >= 0) {
					continue;
				}
			}
			
			bodyResult.axisBody = vertexBody;
			bodyResult.axisNumber = a;
			bodyResult.edge = edge;
			bodyResult.type = 'body';
			
			// Use this result if it has the smallest overlap we've seen so far
			if (bodyResult.overlap < edgeResult.overlap) {
				edgeResult = bodyResult;