|
[ < ] |
[ > ] |
|
[ << ] |
[ Up ] |
[ >> ] |
|
|
|
|
[Top] |
[Contents] |
[Index] |
[ ? ] |
Bámulni egy szilád falat igen unalmassá válik egy idő után. A probléma ott van, hogy nem tudjuk mozgatni a kamerát a nézőpontunk megváltoztatása érdekében. Szerkeszd a 'simple.cpp' ismét és változtasd me a PrcoessFrame() részét a következőképen:
|
|
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);
...
}
|
Ezzel a változtatással most mártudod forgatn a kamerát abalés a jobb nyílgombokkal és előre-hátra tudod mozgatni a fel és a le nyílgombokkal. Próbáld ki, hogy lásd a saját szemeddel. A kamera forgatására a SetTransform() fügvényt használjuk transzformációs mátrix helyettesítésére.
Ennyi volt. Ebben a tutorialban megtanultuk, hogyan lehet felállítania Crystal Space rendszert , hogyan készíts egy egyszerű szobát némi fénnyel, hogyan válaszolj eseményekre, és hogyan kezeld az alapvető kamera művelteket.
Most már továbbléphetsz a másodiktutrialra ami megtanítja, hoan adj 3D szprájtokat az alkalmazáshoz. Simple Tutorial 2: Sprites))
|
[ < ] |
[ > ] |
|
[ << ] |
[ Up ] |
[ >> ] |
This document was generated using texi2html 1.76.