Crystal Space
Welcome, Guest. Please login or register.
April 21, 2014, 12:55:28 am

Login with username, password and session length
Search:     Advanced search
8990 Posts in 2037 Topics by 7598 Members
Latest Member: Tarafigueroa
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Jaunty camera angles
« previous next »
Pages: [1] Print
Author Topic: Jaunty camera angles  (Read 2235 times)
Twey
Newbie
*
Posts: 4


View Profile Email
« on: June 04, 2006, 06:45:46 pm »

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):
Code:
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 ();
}
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1704


View Profile
« Reply #1 on: June 04, 2006, 07:17:36 pm »

I can't see immediatelly what you're doing wrong but perhaps you should compare your usage of csColliderActor with the 'simpcam' tutorial that you find in CS (apps/tutorial/simpmap). It also uses csColliderActor for a camera so it might be a good reference.

Greetings,
Logged
Twey
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: June 04, 2006, 07:22:13 pm »

It was a good reference... I based the code around it Smiley
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1704


View Profile
« Reply #3 on: June 04, 2006, 07:34:44 pm »

It was a good reference... I based the code around it Smiley

Well try to find the crucial differences then smiley

Greetings,
Logged
Twey
Newbie
*
Posts: 4


View Profile Email
« Reply #4 on: June 04, 2006, 08:32:31 pm »

Were I able to do so, I wouldn't have come here smiley

There don't seem to be any major differences between what I've done and what was done in the tutorial.
Logged
Twey
Newbie
*
Posts: 4


View Profile Email
« Reply #5 on: June 05, 2006, 11:46:20 am »

Aha -- solved it!  I was trying to resize the window to 1024x768, which doesn't work at the moment, and the camera was heading towards that rather than the actual centre of the window.

Thanks! smiley
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 4.868 seconds with 16 queries.