FPS Camera

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Römer123
Posts: 6
Joined: Sun Apr 29, 2012 7:27 am
Location: Germany

FPS Camera

Post by Römer123 »

Hi guys,
I added a FPS Camera, but I want to control it with WSAD. The problem is that I'm programming with Delphi and NOT with C++. I made a PSKeymap, but it dosen't run with more than 2 actions.
Here is my code:

Code: Select all

 
var Camera: ICameraSceneNode;
  Steuerung: array[1..4] of PSKeyMap;
[...]
  Steuerung[1].Action:=EKA_MOVE_FORWARD;
  Steuerung[1].KeyCode:=KEY_KEY_W;
  Steuerung[2].Action:=EKA_MOVE_BACKWARD;
  Steuerung[2].KeyCode:=KEY_KEY_S;
  Steuerung[3].Action:=EKA_STRAFE_LEFT;
  Steuerung[3].KeyCode:=KEY_KEY_A;
  Steuerung[4].Action:=EKA_STRAFE_RIGHT;
  Steuerung[4].KeyCode:=KEY_KEY_D;
[...]
  Camera:=smgr.addCameraSceneNodeFPS(nil,100,0.03,-1,Steuerung,4,True,3);
 
I'm new and I hope you can help me :)
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: FPS Camera

Post by randomMesh »

I don't know much about Delphi, let alone the Delphi wrapper, but it'd try to index the array like this

Code: Select all

 
  Steuerung: array[0..3] of PSKeyMap;
[...]
  Steuerung[0].Action:=EKA_MOVE_FORWARD;
  Steuerung[0].KeyCode:=KEY_KEY_W;
  Steuerung[1].Action:=EKA_MOVE_BACKWARD;
  Steuerung[1].KeyCode:=KEY_KEY_S;
  Steuerung[2].Action:=EKA_STRAFE_LEFT;
  Steuerung[2].KeyCode:=KEY_KEY_A;
  Steuerung[3].Action:=EKA_STRAFE_RIGHT;
  Steuerung[3].KeyCode:=KEY_KEY_D;
 
In all(most all) languages the first element of an array has index 0 instead of 1.
"Whoops..."
Römer123
Posts: 6
Joined: Sun Apr 29, 2012 7:27 am
Location: Germany

Re: FPS Camera

Post by Römer123 »

No this is not the problem. The problem is:

Code: Select all

 
Camera:=smgr.addCameraSceneNodeFPS(nil,100,0.03,-1,Steuerung,4,True,3);
 
Steuerung is an array and this procedure don't handle an array.
I use irrDelphi.
DiggiDoggi
Posts: 1
Joined: Thu May 03, 2012 8:50 am

Re: FPS Camera

Post by DiggiDoggi »

Hi Römer123

"Steuerung" is an array indeed, so you have to use: @Steuerung to tell the compiler that you want the address (pointer).

If your compiler use option "Typed @ operator" you'll receive error "Incompatible types PSKeyMap and Pointer". Solution is simple, use:

Addr(Steuerung)

That's all :)
Römer123
Posts: 6
Joined: Sun Apr 29, 2012 7:27 am
Location: Germany

Re: FPS Camera

Post by Römer123 »

Hi,
I don't know how you mean it. Could you please ride the Code? I made it like this:

Code: Select all

 
var Steuerung: array[0..3] of PSKeyMap;  
 
[...]
  Addr(Steuerung);            <- here is the error
  Steuerung[0].Action:=EKA_MOVE_FORWARD;
  Steuerung[0].KeyCode:=KEY_KEY_W;
  Steuerung[1].Action:=EKA_MOVE_BACKWARD;
  Steuerung[1].KeyCode:=KEY_KEY_S;
  Steuerung[2].Action:=EKA_STRAFE_LEFT;
  Steuerung[2].KeyCode:=KEY_KEY_A;
  Steuerung[3].Action:=EKA_STRAFE_RIGHT;
  Steuerung[3].KeyCode:=KEY_KEY_D;
 
  Camera := smgr.addCameraSceneNodeFPS(nil, 100, 0.3, -1, @Steuerung, 3, True, 3);
 
Römer123
Posts: 6
Joined: Sun Apr 29, 2012 7:27 am
Location: Germany

Re: FPS Camera

Post by Römer123 »

I fixed it.

Here:

Code: Select all

 
var Steuerung: array[1..4] of SKeyMap;
[...]
  Steuerung[1].Action:=EKA_MOVE_FORWARD;
  Steuerung[1].KeyCode:=KEY_KEY_W;
  Steuerung[2].Action:=EKA_MOVE_BACKWARD;
  Steuerung[2].KeyCode:=KEY_KEY_S;
  Steuerung[3].Action:=EKA_STRAFE_LEFT;
  Steuerung[3].KeyCode:=KEY_KEY_A;
  Steuerung[4].Action:=EKA_STRAFE_RIGHT;
  Steuerung[4].KeyCode:=KEY_KEY_D;
 
Camera:=smgr.addCameraSceneNodeFPS(nil,100,0.03,-1,@Steuerung,4,True,3);
 
Post Reply