Why do all my Vectors get messed up

Started by coolian, September 19, 2020, 23:41:16

Previous topic - Next topic

coolian

I have  a Camera class:https://pastebin.com/ykmAj8zv
and the xyz components of the Vectors from joml get set to nan for some reason in any other class the only thing hats being done to it is telling the camera to process keypresses mousescroll and mouse position data aswell as getting the view matrix, getting the zoom and creating it
the reason things like
Matrix4f viewMatrix = new Matrix4f();
		Vector3f pos = Position;
		Vector3f up = Up;
		Vector3f front = Front;
		viewMatrix = viewMatrix.lookAt(pos, pos.add(front), up);

that is done because im pretty sure doing
viewMareiy.lookAt(Position, Position.add(Front), Up);

would change the Position vector which for creating the view matrix i obviously dont want.
Why do all the Vectors get messed up.

coolian

The FRONT Constant gets messed up but idk where because its not when it gets created

coolian

front.x = (float) (Math.cos(Math.toRadians(Yaw)) * Math.cos(Math.toRadians(Pitch)));
		front.y = (float) Math.sin(Math.toRadians(Pitch));
		front.z = (float) (Math.sin(Math.toRadians(Yaw)) * Math.cos(Math.toRadians(Pitch)));
		Front = front.normalize(Front);
those calculations are the problem it seems they mess up x

coolian

Ok i just gotta not do Math.toRadians();

KaiHH

Quote from: coolian on September 19, 2020, 23:41:16
Matrix4f viewMatrix = new Matrix4f();
Vector3f pos = Position;
Vector3f up = Up;
Vector3f front = Front;
viewMatrix = viewMatrix.lookAt(pos, pos.add(front), up);

that is done because im pretty sure doing
viewMareiy.lookAt(Position, Position.add(Front), Up);

would change the Position vector which for creating the view matrix i obviously dont want.
There is absolutely zero difference between your first code and the second line... You just assign the same instance to new local variables, that still point to the same object instance.
Therefore, you still modify the vector stored in Position/pos. You can do something like:
viewMareiy.lookAt(Position, Position.add(Front, new Vector3f()), Up);

in order to store the addition result in a new vector object.

Also, please read this first: https://github.com/JOML-CI/JOML/wiki/Common-Pitfalls#methods-without-a-dest-parameter-modify-this-and-return-this

coolian

somewhere in here https://pastebin.com/Vb1xFir6
is still an error but it propably is'nt related to this question.