Hey, I'm currently working on a project that requires me to create a bunch of objects, rotate them locally, then revolve them all around a point.
I have a parent Node that contains all the objects I create so my idea was to create each object, rotate it to my desired orientation, translate it, add it to the parent node, and then rotate the parent node and have it recursively rotate the children.
My problem is that with multiple rotations everything starts to go haywire. I've spent a couple of days on this and haven't made much progress so if someone could point me in the right direction that would be wonderful!
I have a Matrix for the model and a Vector3 to keep track of the translation
protected Matrix4f model = new Matrix4f();
protected Vector3 translation = new Vector3();
This is the code I'm using to rotate the objects.
public SceneNode rotate(float rot, float rx, float ry, float rz) {
for (Node<SceneNode> node : this.getSubnodes()) {
((SceneNode) node).rotate(rot, rx, ry, rz);
}
model.rotate(rot, rx, ry, rz);
return this;
}
public SceneNode rotateLocal(float rot, float rx, float ry, float rz) {
for (Node<SceneNode> node : this.getSubnodes()) {
((SceneNode) node).rotateLocal(rot, rx, ry, rz);
}
float x = getX();
float y = getY();
float z = getZ();
model.translate(-x, -y, -z);
model.rotate(rot, rx, ry, rz);
model.translate(x, y, z);
return this;
}
this is the code I'm using to translate the objects
public SceneNode translate(float x, float y, float z) {
for (Node<SceneNode> node : this.getSubnodes()) {
((SceneNode) node).translate(x, y, z);
}
model.translate(x, y, z);
translation.set(x, y, z);
return this;
}
bondObject.rotateLocal(angle, x, y, z);
bondObject.setTranslation(x, y, z);
parentNode.attach(bondObject);
And I want to rotate it every frame like this
parentNode.rotateLocal(1, 1, 1, 0);