Hello Guest

Why do all my Vectors get messed up

  • 6 Replies
  • 123 Views
Why do all my Vectors get messed up
« on: September 19, 2020, 23:41:16 »
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
Code: [Select]
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
Code: [Select]
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.

Re: Why do all my Vectors get messed up
« Reply #1 on: September 20, 2020, 11:37:38 »
The FRONT Constant gets messed up but idk where because its not when it gets created

Re: Why do all my Vectors get messed up
« Reply #2 on: September 20, 2020, 11:44:42 »
Code: [Select]
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

Re: Why do all my Vectors get messed up
« Reply #3 on: September 20, 2020, 11:50:15 »
Ok i just gotta not do Math.toRadians();

*

Offline KaiHH

  • ****
  • 285
Re: Why do all my Vectors get messed up
« Reply #4 on: September 20, 2020, 12:39:55 »
Code: [Select]
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
Code: [Select]
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:
Code: [Select]
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

Re: Why do all my Vectors get messed up
« Reply #5 on: September 20, 2020, 14:47:01 »
somewhere in here https://pastebin.com/Vb1xFir6
is still an error but it propably is'nt related to this question.

Re: Why do all my Vectors get messed up
« Reply #6 on: September 20, 2020, 14:52:09 »
nvm there isnt