void billBoard(){
ofVec3f objectLookAt = ofVec3f(0,0,1);
ofVec3f objToCam = cam.getGlobalPosition();
objToCam.normalize();
float theta = objectLookAt.angle(objToCam);
ofVec3f axisOfRotation = objToCam.crossed(objectLookAt);
axisOfRotation.normalize();
glRotatef(-zRot->getPos(), 0.0, 0.0, 1.0);
glRotatef(-yRot->getPos(), 0.0, 1.0, 0.0);
glRotatef(-xRot->getPos(), 1.0, 0.0, 0.0);
glRotatef(-theta, axisOfRotation.x, axisOfRotation.y, axisOfRotation.z);
}
or
void billBoard(ofVec3f globalCamPosition, ofVec3f globelObjectPosition){
ofVec3f objectLookAt = ofVec3f(0,0,1);
ofVec3f objToCam = globalCamPosition - globelObjectPosition;
objToCam.normalize();
float theta = objectLookAt.angle(objToCam);
ofVec3f axisOfRotation = objToCam.crossed(objectLookAt);
axisOfRotation.normalize();
glRotatef(-theta, axisOfRotation.x, axisOfRotation.y, axisOfRotation.z);
}
ofPushMatrix();
ofSetRectMode(OF_RECTMODE_CENTER);
billBoard();
// DRAW
ofSetRectMode(OF_RECTMODE_CORNER);
ofPopMatrix();