Problem with vectors.
in
Contributed Library Questions
•
8 months ago
I'm using the library Vec3D, and I don't understand why if I assign the value of one vector to another,and then normalize() it, both vectors change.
I'll paste the code explaining :
- import toxi.geom.*;
- Player a;
- void setup(){
- size(400,600);
- smooth();
- Vec3D initpos = new Vec3D(width/2,height/2,0);
- a = new Player(initpos);
- }
- void draw(){
- a.display();
- check();
- }
- void check(){
- Vec3D testpos = a.loc; // assign the value of vector a.loc to a new vector testpos
- testpos.normalize(); // this line also normalizes a.loc IS THIS NORMAL ?
- }
- class Player{
- Vec3D loc;
- Player(Vec3D _loc){
- loc = _loc;
- }
- void display(){
- ellipse(loc.x,loc.y,20,20);
- }
- }
The ellipse is drawn with a.display(); and yet shows in the normalized position.
This is just an example of the same problem in a more complex code.
Any ideas on how to manipulate a copy of a vector preserving the original ?
I'm posting here because I believe this is more vector related and ignorance than a problem with the library.
Thanks in advance.
1