You can't do this with a primitive float
and an array of type float[]
. Java does not support variables that are pointers or references to primitives.
However, there are a few workarounds.
First, you could make your own mutable reference type holding a float value.
MyFloat[] vector = new MyFloat[3] { new MyFloat(p), new MyFloat(y), new MyFloat(r) };
MyFloat pitch = vector[0];
MyFloat yaw = vector[1];
MyFloat roll = vector[2];
But it would probably be better to wrap your array in an object, and use methods to get the members by meaningful name, rather than variables.
public class Orientation {
private float[] vector = new float[3];
public float[] getArray() { return vector; }
public pitch() { return vector[0]; }
public yaw() { return vector[1]; }
public roll() { return vector[2]; }
public setPitch( float pitch ) { vector[0] = pitch; }
public setYaw( float yaw ) { vector[1] = yaw; }
public setRoll( float roll ) { vector[3] = roll; }
}
This gets you close -- although you can't just say pitch
, you could say o.pitch()
.