私はOpenframeworksを使用してReactivision用に開発しています.ofImage(画面のどこにでも配置できます)を円の周りに配置し、特定の角度で回転させる必要があります。これに役立つ画像を含めます。
http://i.stack.imgur.com/WCyPu.png
ご覧のとおり、x 軸と y 軸は 0,0 から 1,1 に移動し、画面の中央に円があり (中心は 0.5,0.5 に配置されています)、半径は 0.42 です (したがって、画面いっぱいにしないでください)。
最終的に、ユーザーは ofImage (この場合は赤いスマイリー) を画面の位置 0.2,0.2 に配置します。幅と高さはどちらも 0.08 で、回転の中心は (通常どおり) 左上隅にあります。
私がする必要があるのは、そのスマイリーを取り、それを円の周りに、最も近い位置に配置することです(簡単に回転する場合は半径に従うことができます)、それを回転させることができるので、中心に面しますサークルの。
また、ofImage 軸から 0.04 0.04 のところにスマイリーの「鼻」を見つけ、それを移動および回転させて、スマイリーの鼻であり、空白の点ではないようにする必要があります。赤いスマイリーに最適なのは、緑のスマイリーです。
私の三角法は少し錆びており、私の最善のアプローチは機能していません。コンストラクター内で最終的な位置を定義し、draw() ステップでスプライトを回転させます。
Smiley::Smiley(int _id, float x, float y)
{
smileyImg.loadImage("smiley.png");
float tangent = (0.5-x)/(0.5-y);
//angle is a private float variable;
angle = atanf(tangent);
//those 0.06 just lets me move the smiley a little over the circle itself
x = 0.5+cos(angle)*(RADIUS+0.06);
y = 0.5+sin(angle)*(RADIUS+0.06);
float xNose = 0.5+cos(angle)*(RADIUS+0.06);
float yNose = 0.5+sin(angle)*(RADIUS+0.06);
angle = ofRadToDeg(angle);
//pos and nose are Vector3 classes which hold three floats. Nothing too much important here
pos.set(x, y, 0.0);
nose.set(xNose, yNose, 0.0);
}
void Smiley::draw()
{
ofPushMatrix();
ofTranslate(pos.x,pos.y);
ofRotateZ(angle);
ofTranslate(-pos.x,-pos.y);
ofSetColor(255,255,255);
ofEnableAlphaBlending();
smileyImg.draw(pos.x,pos.y,0.08,0.08);
ofDisableAlphaBlending();
ofPopMatrix();
}
誰でもこれで私を助けてくれますか?よろしくお願いします。
編集: @datenwolf ソリューションを適応させた後、得られる位置は完璧ですが、回転と平行移動 (または単に平行移動) を変換マトリックスに入れると、スマイリーが消えます。私はマトリックスで間違っていると確信しています:
Smiley::Smiley(int _id, float x, float y)
{
smileyImg.loadImage("smiley.png");
float distance = sqrt( pow((x - 0.46),2) + pow((y - 0.42),2));
Vector3 director((x - 0.46)/ distance, (y - 0.42)/ distance, 0.0);
pos.x = 0.46 + RADIUS * director.x;
pos.y = 0.42 + RADIUS * director.y;
float distanceNose = sqrt( pow((x - 0.46),2) + pow((y - 0.42),2));
Vector3 noseDirector((x - 0.46)/ distanceNose, (y - 0.42)/ distanceNose, 0.0);
nose.x = 0.46 + RADIUS * noseDirector.x;
nose.y = 0.42 + RADIUS * noseDirector.y;
/* matrix is a float matrix[16]. I think the indexing is ok, but even going from
0 4 8 12... to 0 1 2 3..., it still doesn't work*/
matrix[0] = -director.y; matrix[4] = director.x; matrix[8] = 0.0; matrix[12] = pos.x;
matrix[1] = director.x; matrix[5] = director.y; matrix[9] = 0.0; matrix[13] = pos.y;
matrix[2] = 0.0; matrix[6] = 0.0; matrix[10] = 1.0; matrix[14] = 0.0;
matrix[3] = 0.0; matrix[7] = 0.0; matrix[11] = 0.0; matrix[15] = 1.0;
}
void Smiley::draw()
{
ofPushMatrix();
glLoadMatrixf(matrix);
ofSetColor(255,255,255);
ofEnableAlphaBlending();
// Now that I have a transformation matrix that also transposes, I don't need to define the coordinates here, so I put 0.0,0.0
noseImg.draw(0.0,0.0,0.08,0.08);
ofDisableAlphaBlending();
ofPopMatrix();
}
さらに、各スマイリーに合わせて鼻の位置を回転させる必要があります。どれが一番いい方法だと思いますか? どうもありがとう