Reputation: 71
So I am looking at this 2-D physics impulse engine and I really like to know what is going on in each part of the code. There is one part that I am not understanding at all in the polygon class that defines a polygon.
Here is the link to the code: https://github.com/ClickerMonkey/ImpulseEngine/tree/master/src/org/magnos/impulse
click on the polygon class and scroll down to the method named public Shape clone(). In this method there is "p.u.set( u );". I am not understanding what the meaning of this is at all or what it even does. I would be grateful for anyone that could explain what this single line in the code is doing.
thanks for reading
Upvotes: 0
Views: 338
Reputation: 347314
Start by understanding that Polygon
extends Shape
...
public class Polygon extends Shape
In Shape
, it defines u
as public final Mat2 u = new Mat2();
.
So, in Polygon#clone
, it first creates a new instance of a Polygon
and the sets this new instance's u
object with the current instance of u
...
Polygon p = new Polygon();
p.u.set( u ); // or p.u.set( this.u ); if it's easier to understand...
Now, in Mat2
, the set(Mat2)
method simply copies the properties of the parameter to those of it's own values...
public void set( Mat2 m )
{
m00 = m.m00;
m01 = m.m01;
m10 = m.m10;
m11 = m.m11;
}
So, basically, what this is doing is copying the properties of the parent Polygon.u
(Mat2
) to the child/cloned version...
Upvotes: 2