4.2.1.5 移動運動 (周りを移動する)


移動運動(周りを移動する)

Staring at that solid wall gets a bit boring after some time. The problem is that we can't move the camera to change our view point. Let's add some code to do exactly this. Edit `simple.cpp' again and change `ProcessFrame?()' as follows:

固体の壁を見ていると、しばらくすると退屈します。問題は、視点を変えるためのカメラ移動ができないことです。これをするために、数行のコードを追加しましょう。`simple.cpp`を再び編集します。`ProcessFrame?()`を次のように変更します。

void Simple::ProcessFrame ()
{
 // First get elapsed time from the virtual clock.
 csTicks elapsed_time = vc->GetElapsedTicks ();

 // Now rotate the camera according to keyboard state
 float speed = (elapsed_time / 1000.0) * (0.03 * 20);

 iCamera* c = view->GetCamera();
 if (kbd->GetKeyState (CSKEY_SHIFT))
 {
   // If the user is holding down shift, the arrow keys will cause
   // the camera to strafe up, down, left or right from it's
   // current position.
   if (kbd->GetKeyState (CSKEY_RIGHT))
     c->Move (CS_VEC_RIGHT * 4 * speed);
   if (kbd->GetKeyState (CSKEY_LEFT))
     c->Move (CS_VEC_LEFT * 4 * speed);
   if (kbd->GetKeyState (CSKEY_UP))
     c->Move (CS_VEC_UP * 4 * speed);
   if (kbd->GetKeyState (CSKEY_DOWN))
     c->Move (CS_VEC_DOWN * 4 * speed);
 }
 else
 {
   // left and right cause the camera to rotate on the global Y
   // axis; page up and page down cause the camera to rotate on the
   // _camera's_ X axis (more on this in a second) and up and down
   // arrows cause the camera to go forwards and backwards.
   if (kbd->GetKeyState (CSKEY_RIGHT))
     rotY += speed;
   if (kbd->GetKeyState (CSKEY_LEFT))
     rotY -= speed;
   if (kbd->GetKeyState (CSKEY_PGUP))
     rotX += speed;
   if (kbd->GetKeyState (CSKEY_PGDN))
     rotX -= speed;
   if (kbd->GetKeyState (CSKEY_UP))
     c->Move (CS_VEC_FORWARD * 4 * speed);
   if (kbd->GetKeyState (CSKEY_DOWN))
     c->Move (CS_VEC_BACKWARD * 4 * speed);
 }

 // We now assign a new rotation transformation to the camera.  You
 // can think of the rotation this way: starting from the zero
 // position, you first rotate "rotY" radians on your Y axis to get
 // the first rotation.  From there you rotate "rotX" radians on the
 // your X axis to get the final rotation.  We multiply the
 // individual rotations on each axis together to get a single
 // rotation matrix.  The rotations are applied in right to left
 // order .
 csMatrix3 rot = csXRotMatrix3 (rotX) * csYRotMatrix3 (rotY);
 csOrthoTransform ot (rot, c->GetTransform().GetOrigin ());
 c->SetTransform (ot);

 ...
}

With this change, you can rotate the camera with the left and right arrow keys and move forward and backward with the up and down arrow keys. Try it out to see the effect. To rotate the camera we use SetTransform?() which expects a transformation matrix.

この変更により、次のことができます。

  • 左矢印・右矢印でのカメラの回転
  • 上矢印・下矢印での前後への移動 結果を見てください。カメラを回転するために、SetTransform?()を使用します。SetTransform?()は変換マトリクスを要求します。

最新の20件

2007-02-18 2007-02-12 2007-01-31 2007-02-12 2007-01-14 2007-01-21 2007-02-12 2007-02-11 2007-01-15 2007-01-14 2007-02-12 2007-02-11 2007-02-01
  • 4.2.1.5 移動運動 (周りを移動する)
2007-01-21 2007-01-19 2007-02-12 2007-01-19 2009-08-27 2007-01-10

今日の6件

  • counter: 67
  • today: 1
  • yesterday: 0
  • online: 1