Copy one PVector into another?

edited October 2014 in How To...

I have a little exposure to Java and Processing. My simple-minded, self-teaching project generates a curve by linking line segments. The end points are PVectors v1 and v2. The final end point of one segment (v2) becomes the initial end point (v1) of the next. So in setup(), I define (x,y) values for v1 then, in draw(), I define a different (x,y) pair for v2 and call line() using v1 and v2. The obvious next step is to copy v2 into v1 in preparation for creating a new v2 in the next draw() loop.

But there's the problem. In the first pass through draw(), the simple statement "v1 = v2;" doesn't copy values but seems to copy the instance address from v2 into v1. I see all the methods for PVector in the Processing Reference but no ".copy()". I don't know if my ignorance is mostly Java or mostly Processing! If this were C++ I would expect a copy() operator to be defined for PVector instances.

Thanks for input to my question.

Answers

Sign In or Register to comment.