Why is INTERSECTED used with mouse?

I see that the variable INTERSECTED is often used when making a mouse variable.
I have tried to check the documentation for both Vector2 and mouse and cannot find anywhere explaining why this is the case.

Usually INTERSECTED is not even declared in the code that it is used within.

I usually see it as this:

`var mouse = new THREE.Vector2(), INTERSECTED;`

If someone could explain why it is there, that would be appreciated. The code works with it there, but I just don’t understand why it’s there and why its used when not declared anywhere within the code usually.

An example is this codepen. INTERSECTED is never declared on its own anywhere but used.

Let’s focus on one of the official examples e.g. three.js webgl - interactive cubes

First of all, doing this:

var mouse = new THREE.Vector2(), INTERSECTED;

is equivalent to

var mouse = new THREE.Vector2();
var INTERSECTED;

So the variable INTERSECTED is declared with undefined as value.

The purpose of INTERSECTED is to hold a reference to the current intersected object. If no intersection occurs, it is set to null.

2 Likes

Thank you very much for the reply! That helps me understand it now.