Use Xbox controller to move the gameview operator

Use Xbox controller to move the gameview operator

raashid_mohammed1
Not applicable
2,154 Views
7 Replies
Message 1 of 8

Use Xbox controller to move the gameview operator

raashid_mohammed1
Not applicable

Hi

Model in the link below. It converts the operator into game mode where operator can move using keyboard up,down,left and right button

see link for more info

https://answers.flexsim.com/questions/30134/is-there-a-way-to-create-a-game-in-flexsim.html

Is there a way I can move the operator using Xbox controller in VR mode. both first and third person view

Thanks

Raashid

0 Likes
Accepted solutions (1)
2,155 Views
7 Replies
Replies (7)
Message 2 of 8

ralf_gruber
Collaborator
Collaborator

Raashid,

have you seen this:

https://answers.flexsim.com/questions/30260/how-i-can-use-and-configure-the-xbox-controller-in.html

This describes where the logic can be found to manipulate control through Xbox controller.

0 Likes
Message 3 of 8

raashid_mohammed1
Not applicable

Yes I did

I don't really understand what below sentence means in the answer

"If you want to change what the controller sticks and buttons do, you can modify the FlexScript code in the node VIEW:/standardviews/documentwindows/Perspective>eventfunctions/XboxInput"

But this is more on how can I link the xbox controller to the custom GUI

Thanks for quick reponse

Raashid

0 Likes
Message 4 of 8

philboboADSK
Autodesk
Autodesk
Accepted solution

Attached is an updated version of the model from the original question, modified to use the Xbox Input code from the default Perspective View in the custom 3D Game View.

That game model was purposefully built with a minimal amount of extra stuff in it so that it is easier to understand. Adding Xbox Inputs adds more complexity to the code, as described below:

The things added to this version to make the xbox input work:

  1. OnPreOpen was added to the view that calls stick(num, 20) to determine what xbox controllers are connected to the computer.
  2. Variables were added to the Perspective view to store what xbox controllers are connected and their last update time.
  3. A function called XboxInput was added with custom code to read the xbox inputs and use them to move the operator and viewpoint.
  4. OnPreDraw was updated to call the XboxInput function.
  5. The code to load/unload an item was moved to its own function so that the xbox A button and the spacebar handler can both call the function.

To handle Xbox input, I copied and modified stuff from the existing Perspective view code that is in the tree at VIEW:/standardviews/documentwindows/Perspective>eventfunctions/XboxInput

If you don't understand how referencing in the tree works, then this type of development may be more advanced than you can do by yourself right now. You may want to contact FlexSim for additional training or consulting work.



Phil BoBo
Sr. Manager, Software Development
Message 5 of 8

raashid_mohammed1
Not applicable

Thanks Phil

We do have a PO for training for FLEXSIM. thinking of taking it on month of December

looks like it works. the GUI does not work for VR MODE

Is there a way we can also add VR mode to the perceptive view

Thanks

Raashid

I have OCULUS RIFT

0 Likes
Message 6 of 8

philboboADSK
Autodesk
Autodesk

Attached is an updated version that adds a VR Mode button that turns on the Oculus Rift for the Perspective view in the custom Game View.

Changes in this version:

The button calls applicationcommand("switchviewvrmode", view, getchecked(c)), which toggles VR Mode on the specified view.

The XboxInput function handles re-centering the headset when you press the Back button:

if (wButtons & XINPUT_GAMEPAD_BACK)
    applicationcommand("recenteroculusrift");

The OnPreDraw sets a timer to repaint the view with the function IdleRepaint when in VR Mode or an Xbox controller is connected. (This makes the view continuously repaint when the model isn't running.)

3513-game-operator-moving-boxes-first-person-xbox-input.png



Phil BoBo
Sr. Manager, Software Development
Message 7 of 8

raashid_mohammed1
Not applicable

Thanks Phil

This is super cool. the extent on what flexsim can do is mind boggling

Only thing is the when I move the right toggle thumb to turn and watch, the left toggle turns is right and right toggle turns it left. look like they are switched

Thanks again for everything so far

Regards

Raashid

0 Likes
Message 8 of 8

philboboADSK
Autodesk
Autodesk

The control mechanism I implemented behaves as if the control stick was sticking out of the back of the camera. Moving the stick down rotates the camera to look up, and moving the stick left makes the camera rotate to look right. Like the stick attached to the camera in this image:

3520-camera-operator-jobs.jpg

Most games will let you invert the X and Y axes within their settings if you don't like the defaults.

You are welcome to change the XboxInput controls if you want them to behave differently, or add more UI elements that let you customize the controls.

If you don't want the X-axis to be inverted, Change line 71 in the XboxInput function from:

double rx = -normalizedRY;

to:

double rx = normalizedRY;

You can add a negative on line 72 if you want the Y axis to not be inverted.

You could also customize the controls by adding check boxes that link to variables on the view and read those variables to adjust whether to multiply those values by -1 or not.



Phil BoBo
Sr. Manager, Software Development
0 Likes