You should be aware that when using PeasyCam the lookAt position is
always moved to the centre of the screen and
all rotation with the mouse is about the centre of the screen.
If the femur is centred on the lookAt position then it will rotate about the centre of the display. If you move the femur away from the lookAt position, then dragging with the mouse will rotate the femur about the lookAt position (so it will 'orbit' the centre of the screen), it will NOT rotate about the centre of the femur.
So there are two rotations to consider
1) rotation of the femur about its mid point
2) rotating the 3D view of the 'world' which is done with PeasyCam.
This means that if you use PeasyCam you cannot use the mouse to rotate the actual femur.
The code below ceates 2 bones. The average position of the xyz data of the white bone is being used as the lookAt point for PeasyCam. The yellow bone has been moved and rotated a little to demonstrate what I have been saying.
- import peasy.*;
- PeasyCam cam;
- Bone b0, b1;
- void setup() {
- size(400, 500, P3D);
- b0 = new Bone("Femur.xyz");
- b1 = new Bone("Femur.xyz");
- // Reposition the second bone and change its rotation
- b1.px = 100;
- b1.py = 60;
- b1.pz = 120;
- b1.rx = PI/2;
- b1.col = color(255,255,0);
-
- cam = new PeasyCam(this, 500);
- cam.setMinimumDistance(50);
- cam.setMaximumDistance(600);
- // Look at average point for the white bone
- cam.lookAt(b0.refPoint.x, b0.refPoint.y, b0.refPoint.z);
- }
- void draw() {
- background(0);
- pushMatrix();
- b0.display();
- b1.display();
- popMatrix();
- }
- class Bone {
- float px, py, pz;
- float rx, ry, rz;
- int col;
- ArrayList<PVector> pointList;
- PVector refPoint; // The average position of all points
- Bone(String fileXYZ) {
- col = color(255);
- pointList = new ArrayList<PVector>();
- refPoint = new PVector();
- String[] strLines = loadStrings(fileXYZ);
- for (int i = 0; i < strLines.length; ++i) {
- String[] arrTokens = split(strLines[i], ' ');
- float xx = float(arrTokens[0]);
- float yy = float(arrTokens[1]);
- float zz = float(arrTokens[2]);
- pointList.add( new PVector(xx/5, yy/5, zz/5) );
- refPoint.add(xx, yy, zz);
- }
- refPoint.div(5 * pointList.size());
- println(refPoint);
- }
- void display() {
- pushMatrix();
- translate(px, py, pz);
- rotateX(rx);
- rotateY(ry);
- rotateZ(rz);
- stroke(col);
- for (PVector v : pointList)
- point(v.x, v.y, v.z);
- popMatrix();
- }
- }