Jump to content

How to add controller key function for Oculus HMD


photo

Recommended Posts

Hi,
I've a project created from VR template. I would like to add some basic control to my application. By default you can teleport using A and X, while B and Y and analogue triggers are "free" ( since i don't have interactive objects, laser pen or other stuff )
I'm totally a beginner and I would like to add a rotation around one axis of a specific object in the scene ( the sun actually )  to this free buttons. Where I have to start for example to use  B for positive oration, and Y for negative rotation?
The project is build with C++ API.

Thanks

Link to comment

I try to move some little step ahead but now i have some doubt regarding the final buil.
I've edited some code with visual studio, also for some rotation over time in the AppWorldLogic::update() ( always on like fan rotation )
It works fine when I start the application from Visual studio using play button on debugger local pc.
But if I try to create from SDK a build of my projects, all the stuff that is moving by C++ scripts ( and should be works since running from visual studio is fine ) are completely stopped.
How can I create a build that take into account my edited scripts?

Thanks

Link to comment
11 hours ago, silent said:

Hi Andrea,

Please make sure that you built release version as well. By default Debug is selected:

image.png

After many attempt I finally found that switching to release and building solution again from visual studio solve my issue of the binaries packages.

I also finally mange to get my behavior works to rotate a specific object by VR controllers. It was little bit tricky since I suppose documentation is not updated and some times provide example only for Double precision that is available only in Sim or Enginering edition.

I'll try to explain all the step that I made to help others people with similar needing or if it can be helpful to update documentation as well by Unigine team.

The starting point is the documentation relative to the "new interaction" for VR that is available here: https://developer.unigine.com/en/docs/future/start/vr/#new_interaction

It's suggested to edit the render() method of VRPlayer class in the VRPlayer.ccp file. Unfortunately it looks like this is an old method not available anymore in that class. Looking at similar code I found that ( I suppose ) the part of the code was migrated to the postUpdate() method.

So I add my custom code in this method and it works ;) Just a tip, I found more easy using Hand number with getNumHands()  instead edit the standard code to identify which is the key pressed between Y and B.

What about rotation of an objects? Well as described in the really beginner tutorial of C++ ( https://developer.unigine.com/en/docs/2.13/code/cpp/application?rlang=cpp ), it should be an easy task, but I found some trouble ( since I'm really novice in Unigine ) trying to replicate the code suggested in this particular tutorial. Luckily the video in the page it was shown on Float precision and community version, but I lost some time before get it!

I know it will be an extra effort but since there are this big difference I would suggest to consider to make both float and double version code available in the tutorial, even the beginner one like this.

btw....my final code it's all inside VRPlayer class and looks like:

 

NodePtr nodeSun;
float angle = 5.0f;

void VRPlayer::init()
{
	nodeSun = World::getNodeByName("sun");
}

void VRPlayer::postUpdate()
{
	for (int i = 0; i < getNumHands(); i++)
	{
		int hand_state = getHandState(i);

		if (getControllerButtonDown(i, BUTTON::YB))
		{
			if (nodeSun) {
				if ( i == 0) {
					nodeSun->setTransform(nodeSun->getTransform() * Math::rotateY(angle));
				}
				else {
					nodeSun->setTransform(nodeSun->getTransform() * Math::rotateY(-angle));
				}
			}
		}

		if (hand_state != HAND_FREE)
		{
				.......STANDARD CODE HERE ETC. ETC. ETC.

I hope It's not so bad :D

Edited by andrea.padovani
  • Like 1
Link to comment
×
×
  • Create New...