I have a program using the latest snapshot of CS, and it runs OK, but for a small and irritating problem: the camera, which is linked to a csColliderActor, doesn't point in quite the right direction, so pressing the forward key actually slants to the right by about twenty degrees. I've tried rotating it, but it doesn't seem to have any effect whatsoever.
Pertinent code (everything that deals with the camera or ColliderActor):
bool App::Setup() {
g3d = CS_QUERY_REGISTRY(GetObjectRegistry(), iGraphics3D);
if(!g3d) return ReportError("Failure to open 3D renderer.");
engine = CS_QUERY_REGISTRY(GetObjectRegistry(), iEngine);
if(!engine) return ReportError("Failure to open engine.");
vc = CS_QUERY_REGISTRY(GetObjectRegistry(), iVirtualClock);
if(!vc) return ReportError("Failure to open virtual clock.");
kbd = CS_QUERY_REGISTRY(GetObjectRegistry(), iKeyboardDriver);
if(!kbd) return ReportError("Failure to open keyboard driver.");
loader = CS_QUERY_REGISTRY(GetObjectRegistry(), iLoader);
if(!loader) return ReportError("Failure to open loader.");
cdsys = CS_QUERY_REGISTRY(GetObjectRegistry(), iCollideSystem);
if(!cdsys) return ReportError("Failure to open collision detection system.");
((csRef<iVFS>)(CS_QUERY_REGISTRY(GetObjectRegistry(), iVFS)))->Mount("/cache", "cache.zip");
Room *sroot = new Room(this, NULL, "");
Corridor *rroot = new Corridor(this, sroot);
view.AttachNew(new csView(engine, g3d));
canvas = g3d->GetDriver2D();
canvas->GetNativeWindow()->SetTitle("FMRPG");
canvas->Resize(1024, 768);
view->SetRectangle(0, 0, canvas->GetWidth(), canvas->GetHeight());
csColliderHelper::InitializeCollisionWrappers(cdsys, engine);
engine->Prepare();
iSector *root = sroot->GetSector();
view->GetCamera()->SetSector(root);
view->GetCamera()->GetTransform().SetOrigin(csVector3(0, 1, 0));
view->GetCamera()->SetTransform(csOrthoTransform(csMatrix3(csYRotMatrix3(-300)), view->GetCamera()->GetTransform().GetOrigin()));
collider_actor.SetCollideSystem (cdsys);
collider_actor.SetEngine (engine);
csVector3 legs (.2f, .3f, .2f);
csVector3 body (.2f, 1.2f, .2f);
csVector3 shift (0, -1, 0);
collider_actor.InitializeColliders(view->GetCamera(), legs, body, shift);
return true;
}
void App::ProcessFrame() {
csTicks elapsed_time = vc->GetElapsedTicks ();
csVector3 obj_move (0);
csVector3 obj_rotate (0);
if (kbd->GetKeyState (CSKEY_SHIFT)) {
if (kbd->GetKeyState ('d'))
obj_move += CS_VEC_RIGHT * 3.0f;
if (kbd->GetKeyState ('a'))
obj_move += CS_VEC_LEFT * 3.0f;
} else {
if (kbd->GetKeyState (CSKEY_SPACE))
obj_move += CS_VEC_UP * 3.0f;
if (kbd->GetKeyState ('d'))
obj_rotate.Set (0, 1, 0);
if (kbd->GetKeyState ('a'))
obj_rotate.Set (0, -1, 0);
if (kbd->GetKeyState (CSKEY_PGUP))
obj_rotate.Set (1, 0, 0);
if (kbd->GetKeyState (CSKEY_PGDN))
obj_rotate.Set (-1, 0, 0);
if (kbd->GetKeyState ('w'))
obj_move += CS_VEC_FORWARD * 3.0f;
if (kbd->GetKeyState ('s'))
obj_move += CS_VEC_BACKWARD * 3.0f;
}
collider_actor.Move (float (elapsed_time) / 1000.0f, 1.0f, obj_move, obj_rotate);
if (!g3d->BeginDraw (engine->GetBeginDrawFlags () | CSDRAW_3DGRAPHICS))
return;
view->Draw ();
}