Major Spherical issues

Spherical is not behaving as intended:

The red sphere (the spherical converted to a Vector3) should be at the same position as the blue sphere. Instead, it does not render until the mouse is moved and then is not close to the actual coordinates at all. It also moves with the mouse which is very incorrect behavior.

The issue with the sphere moving when you move the mouse I cannot explain. You can solve it by using .clone() as in the PG below. This is where we need someone like @sebavan @RaananW @Evgeni_Popov

The problem with positioning is a maths error in your settings for theta and phi rather than a problem with spherical.


For your target position of (0, 3, 4) the verticalAngle, theta, is tan-1(4 / 3) and phi is π / 2 not the verticalAngle

Spherical works as can be seen in

I changed the camera angle and renamed the sphere meshes with the word sphere rather than spherical to be clearer what is being refered to. All spheres coincide.

1 Like

Heya, looks like the problem with toVector3 is that it returns a temp vector which is used/changed by other parts of the API. Instead you should create a new vector to return, like below for example should work. :slight_smile:

public toVector3(): Vector3 {
     // const ref = TmpVectors.Vector3[0];
     const ref = new Vector3();
     return this.toVector3ToRef(ref);

And also I noticed that the Polar class’s toVector2 method has this same issue of returning a temp vector…


Should get fixed shortly: Fix TmpVectors usage in Polar/Spherical toVector methods by dr-vortex · Pull Request #13053 · BabylonJS/Babylon.js · GitHub


Avoid creating a new vector, use a temporary Vector2 from TmpVectors

Looks like I repeated to you this advice you were given in your first PR in the wrong places. My apologies

Reminder to self do not use TmpVectors to pass a parameter by reference.