#クォータニオン使わず球面上の2点を補間したい
##球面の方程式
ofPoint getPositionOnSphere(float azimuth, float elevation, float rad){
float a = ofDegToRad(azimuth);
float e = ofDegToRad(elevation);
//zの+が天
ofPoint pos;
pos.x = rad * sin(e) * cos(a);
pos.y = rad * sin(e) * sin(a);
pos.z = rad * cos(e);
return pos;
};
##やり方 1、球面上の2点を求め、原点(0,0,0)からのベクトルとして扱う
2、2つのベクトルの角度を求める
3、2つのベクトルの法線を求めて回転軸に
4、2で求めた角度までベクトルを回転軸で回す
ofPoint mBegin;
ofPoint mEnd;
ofPoint mCurrent;
void setup(){
mBegin = getPositionOnSphere(40, 30, 300);
mEnd = getPositionOnSphere(-40, 70, 300);
}
void update(){
//正規化しない者から死んでいきます
ofPoint begin = mBegin.getNormalized();
ofPoint end = mEnd.getNormalized();
//2つのベクトルが成す角度
float dot = begin.dot(end);
float angle = ofRadToDeg(acos(dot));
// 法線は回転軸です
ofPoint axis = begin.getCrossed(end);
//0.0 ~ 1.0。好きなようにせえ
float t = (ofGetFrameNum() % 120) / 120.0;
//欲しかった点
mCurrent = mBegin;
mCurrent.rotate( angle * t, ofPoint(0,0,0), axis);
}