How to use the phaser/src/physics/matter-js/lib/geometry/Vector.neg 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 / SAT.js View on Github external
let bodyB = collision.bodyB;
		
		// Find the support points; there is always either exactly one or two
		let verticesB = SAT.findSupports(bodyA, bodyB, collision.normal),
			supports = [];
		
		// Find the supports from bodyB that are inside bodyA
		if (Vertices.contains(bodyA.vertices, verticesB[0]))
			supports.push(verticesB[0]);
		
		if (Vertices.contains(bodyA.vertices, verticesB[1]))
			supports.push(verticesB[1]);
		
		// Find the supports from bodyA that are inside bodyB
		if (supports.length < 2) {
			let verticesA = SAT.findSupports(bodyB, bodyA, Vector.neg(collision.normal));
			
			if (Vertices.contains(bodyB.vertices, verticesA[0]))
				supports.push(verticesA[0]);
			
			if (supports.length < 2 && Vertices.contains(bodyB.vertices, verticesA[1]))
				supports.push(verticesA[1]);
		}
		
		// Account for the edge case of overlapping but no vertex containment
		if (supports.length < 1)
			supports = [verticesB[0]];
		
		return supports;
	}
};
github hexus / phaser-slopes / src / Matter / World.js View on Github external
// 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;
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal2);
			back.upperLimit = Vector.neg(m_normal1);
		} else if (convex2)	{
			front.normal = m_normal1;
			front.lowerLimit = m_normal1;
			front.upperLimit = m_normal2;
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal1);
github hexus / phaser-slopes / src / Matter / World.js View on Github external
// 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;
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal2);
			back.upperLimit = Vector.neg(m_normal1);
		} else if (convex2)	{
			front.normal = m_normal1;
			front.lowerLimit = m_normal1;
			front.upperLimit = m_normal2;
			
			back.normal = Vector.neg(m_normal1);
github hexus / phaser-slopes / src / Matter / World.js View on Github external
} else {
			front.normal = m_normal1;
			front.lowerLimit = m_normal1;
			front.upperLimit = m_normal1;

			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal2);
			back.upperLimit = Vector.neg(m_normal0);
		}
	} else if (hasVertex0) {
		if (convex1) {
			front.normal = m_normal1;
			front.lowerLimit = m_normal0;
			front.upperLimit = Vector.neg(m_normal1);
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = m_normal1;
			back.upperLimit = Vector.neg(m_normal1);
		} else {
			front.normal = m_normal1;
			front.lowerLimit = m_normal1;
			front.upperLimit = Vector.neg(m_normal1);
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = m_normal1;
			back.upperLimit = Vector.neg(m_normal0);
		}
	} else if (hasVertex3) {
		if (convex2) {
			front.normal = m_normal1;
			front.lowerLimit = Vector.neg(m_normal1);
			front.upperLimit = m_normal2;
github hexus / phaser-slopes / src / Matter / World.js View on Github external
}  else if (convex1) {
			front.normal = m_normal1;
			front.lowerLimit = m_normal0;
			front.upperLimit = m_normal1;
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal2);
			back.upperLimit = Vector.neg(m_normal1);
		} else if (convex2)	{
			front.normal = m_normal1;
			front.lowerLimit = m_normal1;
			front.upperLimit = m_normal2;
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal1);
			back.upperLimit = Vector.neg(m_normal0);
		} else {
			front.normal = m_normal1;
			front.lowerLimit = m_normal1;
			front.upperLimit = m_normal1;

			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal2);
			back.upperLimit = Vector.neg(m_normal0);
		}
	} else if (hasVertex0) {
		if (convex1) {
			front.normal = m_normal1;
			front.lowerLimit = m_normal0;
			front.upperLimit = Vector.neg(m_normal1);
			
			back.normal = Vector.neg(m_normal1);
github hexus / phaser-slopes / src / Matter / World.js View on Github external
} else if (hasVertex3) {
		if (convex2) {
			front.normal = m_normal1;
			front.lowerLimit = Vector.neg(m_normal1);
			front.upperLimit = m_normal2;

			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal1);
			back.upperLimit = m_normal1;
		} else {
			front.normal = m_normal1;
			front.lowerLimit = Vector.neg(m_normal1);
			front.upperLimit = m_normal1;

			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal2);
			back.upperLimit = m_normal1;
		}
	} else {
		front.normal = m_normal1;
		front.lowerLimit = Vector.neg(m_normal1);
		front.upperLimit = Vector.neg(m_normal1);

		back.normal = Vector.neg(m_normal1);
		back.lowerLimit = m_normal1;
		back.upperLimit = m_normal1;
	}
	
	edge.convexPrev = convex1;
	edge.convexNext = convex2;
	
	edge.normalRanges = {
github hexus / phaser-slopes / src / Matter / World.js View on Github external
back.lowerLimit = Vector.neg(m_normal1);
			back.upperLimit = Vector.neg(m_normal0);
		} else {
			front.normal = m_normal1;
			front.lowerLimit = m_normal1;
			front.upperLimit = m_normal1;

			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = Vector.neg(m_normal2);
			back.upperLimit = Vector.neg(m_normal0);
		}
	} else if (hasVertex0) {
		if (convex1) {
			front.normal = m_normal1;
			front.lowerLimit = m_normal0;
			front.upperLimit = Vector.neg(m_normal1);
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = m_normal1;
			back.upperLimit = Vector.neg(m_normal1);
		} else {
			front.normal = m_normal1;
			front.lowerLimit = m_normal1;
			front.upperLimit = Vector.neg(m_normal1);
			
			back.normal = Vector.neg(m_normal1);
			back.lowerLimit = m_normal1;
			back.upperLimit = Vector.neg(m_normal0);
		}
	} else if (hasVertex3) {
		if (convex2) {
			front.normal = m_normal1;