PDA

View Full Version : communication between c++ program and unrealscript program ?


shihchiy
1st Feb 2005, 06:47 PM
Hi,

I am new to Unreal script.

I would like to control the player's camera using "Magnetic Tracker" instead of using mouse or joystick. However, the driver of "Magnetic Tracker" is coded through C++. How can I connect C++ code to Unrealscript ? So that the Unrealscript program can keep receiving data from "Magnetic Tracker".

Best

Luke

Sir_Brizz
2nd Feb 2005, 12:43 AM
The only way would be for "Magnetic Tracker" to write information to an INI file that the UScript can read from, afaik.

shihchiy
2nd Feb 2005, 03:09 AM
The only way would be for "Magnetic Tracker" to write information to an INI file that the UScript can read from, afaik.


"Megnetic Tracker" is operated in real time that data of 6 Degree of Freedom (DOF) will keep outputing to Unrealscript. The amount of data will be 1000 sets/sec. Each set of data will include x,y,z,rx,ry,rz. Will it be fast enough to transfer data through INI file in real time?

Best

Luke

[SAS]Solid Snake
2nd Feb 2005, 03:46 AM
The only way would be for "Magnetic Tracker" to write information to an INI file that the UScript can read from, afaik.Not neccessarily. You can also use TCP or UDP to connect from Unreal to an external program, being able to share data between programs (Send, receive). But I am in doubt at how fast you could send/receive data because that kind of connection is best used for latent type connections such as website. There are also other methods, but I am in doubt whether they would be fast enough to be used as an input type.

Sir_Brizz
2nd Feb 2005, 11:49 AM
I am doubtful that using an INI would be fast enough either, at that rate. There is really no faster way to interface between Unreal and another program.

Switch`
8th Feb 2005, 06:04 PM
There are many ways to link reliably unrealscript with c++ code however in this case it hopefully wont be required. I'd suggest reusing the existing joystick support.

Here's my *guess* of how the input system works:

- Unreal Engine Input module can cause 256 unique "input events".
- Those events are listed in user.ini file and named after keys and axes.
- Next to their name is the action they are supposed to cause.
-- ie:
-- W = MoveForward
-- MoveForward is an alias for "Axis aBaseY Speed=+300.0"
-- aBaseY is an unrealscript input variable in class PlayerController
-- pressing "W" will result in c++ input code modifying the PlayerController.aBaseY unrealscript input variable
- In each frame variables like aBaseY are processed by script and player acceleration/rotation is adjusted.

Judging by the event names mouses can have 4 axes (X,Y,Z,W) and joysticks 6 (X,Y,Z,R,U,V) + 2 sliders + 16 buttons.
The script that translates input variable most likely WILL have to be modified as you may wany ie unlimited rotations in all axes without gimbal lock.

I'd suggest getting a joystick, making sure joystick support works in runtime build, modifying runtime script so it matches requirements and then modifying your "magnetic tracker" driver so it's recognizable as joystick.

The idea sounds interesting, if you need any further help with unrealscript pm me and I'll gladly help you if I can.

shihchiy
9th Feb 2005, 07:56 PM
Some further questions:
(1) How can I make c++ based dirver of "magnetic tracker" be recognized as joystick ?
(2) If I would like to make my own player move such like 100 in X direction, how can I achieve it in Unrealscript? (Which class / which function ...)

Thanks

Luke

There are many ways to link reliably unrealscript with c++ code however in this case it hopefully wont be required. I'd suggest reusing the existing joystick support.

Here's my *guess* of how the input system works:

- Unreal Engine Input module can cause 256 unique "input events".
- Those events are listed in user.ini file and named after keys and axes.
- Next to their name is the action they are supposed to cause.
-- ie:
-- W = MoveForward
-- MoveForward is an alias for "Axis aBaseY Speed=+300.0"
-- aBaseY is an unrealscript input variable in class PlayerController
-- pressing "W" will result in c++ input code modifying the PlayerController.aBaseY unrealscript input variable
- In each frame variables like aBaseY are processed by script and player acceleration/rotation is adjusted.

Judging by the event names mouses can have 4 axes (X,Y,Z,W) and joysticks 6 (X,Y,Z,R,U,V) + 2 sliders + 16 buttons.
The script that translates input variable most likely WILL have to be modified as you may wany ie unlimited rotations in all axes without gimbal lock.

I'd suggest getting a joystick, making sure joystick support works in runtime build, modifying runtime script so it matches requirements and then modifying your "magnetic tracker" driver so it's recognizable as joystick.

The idea sounds interesting, if you need any further help with unrealscript pm me and I'll gladly help you if I can.

Switch`
20th Feb 2005, 12:21 AM
1 - I don't have any experience in this field but I guess writing a joystick driver for it should do the trick. Windows has also some support for a range of generic joystick-like devices.

2 - I'll try to describe player movement in context of input processing in unrealscript.

Config:
At the lowest level are input binds in User.ini.
The binds describe how to translate internal input variables into unrealscript input variables or function calls.

Unrealscript:
The unrealscript input variables are located in class Engine.PlayerController.
Initial processing is done in class Engine.PlayerInput, function PlayerInput().
Engine.PlayerInput is an 'internal' PlayerController class - it has direct access to PlayerController variables.
The PlayerInput() function prepares a smaller set of variables for further use (ie: aForward, aTurn, aStrafe, aLookUp) and zeroes some of the processed input variables (ie: aBaseX, aBaseY).
Further processing is done in PlayerController class, in one of the PlayerMove() functions, most likely the one in 'PlayerWalking' state.
In PlayerMove(), among other things, Pawn's Accceleration is set to aForward & aStrafe values, using current Pawn rotation.

Engine:
The Velocity and Location of Pawn are calculated mostly in C++ engine physics.
The Acceleration is clamped to Pawn.AccelRate.
Velocity is clamped to Pawn.Ground/Air/WaterSpeed (multiplied by Pawn.WalkingPct when walking).
When Acceleration(input) is 0, Velocity drops down very rapidly.
Somewhere in the middle of physics calculations a Pawn.ModifyVelocity() event is called, allowing you to modify Velocity in unrealscript before the Pawn is moved.

Observations:
I've used an old steering wheel for testing the input values. Pedals were controlling player acceleration with bind command "JoyY=Axis aBaseY SpeedBase=1 DeadZone=0.01 Invert=-1". In my case the data in aBaseY was framerate-dependent and very noisy, multiplying it by time since last frame removed the noise and left me with data between -10 and +10.
Keyboard MoveForward bind "Axis aBaseY Speed=1.0" in my case has x20 multiplier, it's framerate independent.


There are many ways to move a player around, depending on how the magnetic tracker works and how the camera should move like.

mrbungle
29th Apr 2005, 09:32 AM
So I am interested in controlling the player over a socket, but using (possibly) a text file that moves the player around accordingly. Basically we are trying to create an agent that seems to move by itself so that it will go to predefined points and perform an analysis of an image (this would occur through a secondary program).

So far I have created the socket connection and am able to send and receive information between Unreal and a small Tcl script. What I am trying to do now is move the player forward via commands sent thru the socket.

Is it simply a case of updating the aBaseX or aBaseY variables to move a player? Would I do this thru a custom Pawn? Thanks in advance for any suggestions.

Angel_Mapper
29th Apr 2005, 03:58 PM
1 - I don't have any experience in this field but I guess writing a joystick driver for it should do the trick. Windows has also some support for a range of generic joystick-like devices.That's what I was thinking. Instead of trying to communicate directly with Unreal, why not have the Magnetic Tracker be recognized as a joystick through Windows?