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.

FPS Camera

Postby Römer123 » Sun Apr 29, 2012 7:39 am

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:

cpp 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 :)
Römer123
 
Posts: 6
Joined: Sun Apr 29, 2012 7:27 am
Location: Germany

Re: FPS Camera

Postby randomMesh » Sun Apr 29, 2012 12:05 pm

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

cpp 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.
"In fact, nearly every sequence of punctuation is used for something in Perl. So, if you get writer’s block, just let the cat walk across the keyboard, and debug the result."

Katastrophe - A free, open source flocking boids simulation
User avatar
randomMesh
 
Posts: 1138
Joined: Fri Dec 29, 2006 12:04 am

Re: FPS Camera

Postby Römer123 » Sun Apr 29, 2012 1:06 pm

No this is not the problem. The problem is:
cpp 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.
Römer123
 
Posts: 6
Joined: Sun Apr 29, 2012 7:27 am
Location: Germany

Re: FPS Camera

Postby DiggiDoggi » Thu May 03, 2012 9:18 am

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 :)
DiggiDoggi
 
Posts: 1
Joined: Thu May 03, 2012 8:50 am

Re: FPS Camera

Postby Römer123 » Fri May 04, 2012 5:21 pm

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

cpp 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

Postby Römer123 » Fri May 04, 2012 6:06 pm

I fixed it.

Here:
cpp 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);
 
Römer123
 
Posts: 6
Joined: Sun Apr 29, 2012 7:27 am
Location: Germany


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 0 guests