0

I have a scene and an object placed in some coordinates. I can transform the object using glTranslate(center) and then glRotate...

But how do I rotate an object not using angles but rather directions top and forward?

Thanks

What I'm looking is translation between model coordinate system and global coordinate system.

4

2 に答える 2

2

オブジェクト空間でオブジェクトの 3 つの軸を知っているとします。簡単にするために、これらはデカルト軸であると仮定します (そうでない場合は、以下で説明するプロセスを 2 回適用して対処できます)。

ox = (1, 0, 0)
oy = (0, 1, 0)
oz = (0, 0, 1)

また、ワールド空間に他の 3 つの直交する正規化された軸があり、オブジェクトの、前、横の方向を示しているとします [*]:

wx = (wx.x, wx.y, wx.z)
wy = (wy.x, wy.y, wy.z)
wz = (wz.x, wz.y, wz.z)

次に、次の (列ベクトルを想定) は、オブジェクト空間からワールド空間への回転行列です。

    [ wx.x  wx.y  wx.z ]
M = [ wy.x  wy.y  wy.z ]
    [ wz.x  wz.y  wz.z ]

行列式が 1 (直交および正規化された線) であるため、これは回転行列です。ワールド空間からオブジェクト空間に移動することを確認するには、方法M*wx = (1, 0, 0)などに注意してください.

今度は正反対のオブジェクト空間からワールド空間へ。行列を逆にするだけです。その場合、逆は転置と同じであるため、最終的な答えは次のとおりです。

objectToWorld = transpose(M)

2 つのことが残っています。

1) このマトリックスを OpenGL にロードします。glMultMatrixあなたのためにこれを行います(注意してください、glMultMatrix列メジャーであり、4x4マトリックスが必要です):

double objectToWorld[] = [ wx.x, wy.x, wz.x, 0, 
                           wx.y, wy.y, wz.y, 0, 
                           wx.z, wy.z, wz.z, 0,
                              0,    0,    0, 1 ];
glMultMatrixd( objectToWorld ); 

2) 翻訳。これを行うには、これに続いて を呼び出しますglTranslate

[*] 3 つのうち 2 つしかない場合、たとえばに、外積を使用して側面を簡単に計算できます。正規化されていない場合は、単純に正規化します。それらが直交していない場合、すべてが難しくなります。

于 2010-04-10T16:39:08.763 に答える
0

Since OpenGL works just with matrices there is no concept of top, bottom and so on..

you'll have to find a corrispondence between the rotation you wanna give and the orientation needed. Since glRotates(angle,x,y,z,) wants an angle in degrees you can just use a bidimensional array and store all 16 possibilities (from one of top, bottom, left, right to one of the same.. otherwise you can just see how much 90° steps are needed from actual position to new one and multiply the value by 90..

eg:

from top to bottom = 2 steps = 180°

from right to top = 1 step backward = -90°

于 2010-04-10T14:51:52.847 に答える