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

hexus / phaser-slopes / src / Matter / World.js View on Github
``````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;``````
hexus / phaser-slopes / src / Matter / SAT.js View on Github
``````axis = vertexBody.axes[a];

bodyResult = SAT.overlapNormal(vertexBody.vertices, edgeVertices, axis);

// We have a separating axis, skip this edge
if (bodyResult.overlap &lt;= 0) {
return bodyResult;
}

// Make sure the vertexBody normal is in the edge's normal range
if (crossLimits &gt;= 0) {
if (!(Vector.cross(range.lowerLimit, axis) &gt;= 0 &amp;&amp; Vector.cross(axis, range.upperLimit) &gt;= 0)) {
continue;
}
} else {
if (Vector.cross(range.upperLimit, axis) &gt;= 0 &amp;&amp; Vector.cross(axis, range.lowerLimit) &gt;= 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 &lt; edgeResult.overlap) {
edgeResult = bodyResult;
}
}

return edgeResult;``````
hexus / phaser-slopes / src / Matter / World.js View on Github
``````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;``````
hexus / phaser-slopes / src / Matter / SAT.js View on Github
``````range = edge.normalRanges.front;

edgeResult = SAT.overlapNormal(vertexBody.vertices, edgeVertices, range.normal);

// We have a separating axis, skip this edge
if (edgeResult.overlap &lt;= 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 &lt; 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 &lt;= 0) {
return bodyResult;
}

// Make sure the vertexBody normal is in the edge's normal range
if (crossLimits &gt;= 0) {
if (!(Vector.cross(range.lowerLimit, axis) &gt;= 0 &amp;&amp; Vector.cross(axis, range.upperLimit) &gt;= 0)) {
continue;``````
hexus / phaser-slopes / src / Matter / SAT.js View on Github
``````crossLimits = Vector.cross(range.lowerLimit, range.upperLimit);

// Test each vertexBody normal
for (a = 0; a &lt; 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 &lt;= 0) {
return bodyResult;
}

// Make sure the vertexBody normal is in the edge's normal range
if (crossLimits &gt;= 0) {
if (!(Vector.cross(range.lowerLimit, axis) &gt;= 0 &amp;&amp; Vector.cross(axis, range.upperLimit) &gt;= 0)) {
continue;
}
} else {
if (Vector.cross(range.upperLimit, axis) &gt;= 0 &amp;&amp; Vector.cross(axis, range.lowerLimit) &gt;= 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 &lt; edgeResult.overlap) {
edgeResult = bodyResult;``````

## phaser

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

MIT