# 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.

hexus / phaser-slopes / src / Matter / SAT.js View on Github
``````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 &lt; 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 &lt; 2 &amp;&amp; Vertices.contains(bodyB.vertices, verticesA[1]))
supports.push(verticesA[1]);
}

// Account for the edge case of overlapping but no vertex containment
if (supports.length &lt; 1)
supports = [verticesB[0]];

return supports;
}
};``````
hexus / phaser-slopes / src / Matter / World.js View on Github
``````// 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);``````
hexus / phaser-slopes / src / Matter / World.js View on Github
``````// 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);``````
hexus / phaser-slopes / src / Matter / World.js View on Github
``````} 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;``````
hexus / phaser-slopes / src / Matter / World.js View on Github
``````}  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);``````
hexus / phaser-slopes / src / Matter / World.js View on Github
``````} 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 = {``````
hexus / phaser-slopes / src / Matter / World.js View on Github
``````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;``````

## phaser

A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.

MIT

92 / 100