How to rotate model in 3D?
in
Programming Questions
•
1 year ago
I am working on a sketch, based on the flocking algorithm from daniel shiffman. I extended the code to work in 3D. Thats all working fine, so far. I wanted to make a sketch with a swarm of fish, and fish don't swim with their stomachs up. My fish do. So i really can not figure out, how to rotate the model to avoid the "dead fish" behavior.
Thanks Thomas!
Thanks Thomas!
- PVector modelOrientation = new PVector(0, 0, 1);
PVector heading=new PVector(vel.x, vel.y, vel.z);
heading.normalize();
float angle = acos(modelOrientation.dot(heading));
PVector axis = modelOrientation.cross(heading);
pushMatrix();
translate(loc.x, loc.y, loc.z);
rotate(angle, axis.x, axis.y, axis.z);
flockFish.draw();
popMatrix();
1