lightmap Posted September 7, 2017 Share Posted September 7, 2017 Hello trying to use controller to rotate player camera // get head position in world coords Player player = engine.game.getPlayer(); Mat4 player_transform = player.getWorldTransform(); Mat4 hmd_transform = engine.oculus.getDevicePose(OCULUS_DEVICE_HMD); Mat4 hmd_transform_world = player_transform * hmd_transform; quat i_rotation = player.getWorldRotation();//(1) woking - but no hmd transform //i_rotation = rotation(hmd_transform_world); (2) - not working - and controllers go unresponsible //i_rotation = hmd_transform_world;// (3) - nothing i_rotation = quat(vec3(1, 0, 0), R_thumb.y) * conjugate(i_rotation) * quat(vec3(0, 0, 1), -R_thumb.x);// apply delta pitch/yaw quat camera_rotation = conjugate(i_rotation); player.setWorldRotation(camera_rotation); with (1) pitch/yaw changing are working - but rotating around wrong axis if hmd rotated with (2) or (3) nothing happening - no errors, no controller responces, no vibratiion at button pressing ( how to account hmd rotation matrix for quat axis rotation? do I incorrectly assign mat4 to quat? also there no .getRight() .getForward() ... methods in uscript? ( Link to comment
alexander Posted September 8, 2017 Share Posted September 8, 2017 Hi! Quote but rotating around wrong axis if hmd rotated First of all, you should rotate player's camera around HMD position (hmd_transform_world.getTranslate()), not Player's position (player_transform.getTranslate()). Look at our Superposition demo (i changed code to you variables): quat rot = quat(0, 0, R_thumb.x * 75.0f * Game::get()->getIFps()); // 75 - degress per second at maximum value of R_thumb.x vec3 offset0 = hmd_transform_world.getTranslate() - player_transform.getTranslate(); vec3 offset1 = rot * offset0; player->setPosition(player->getPosition() + offset0 - offset1); player->setRotation(rot * player->getRotation()); Quote do I incorrectly assign mat4 to quat? I think yes. But you can use explicit quat constructor to it: i_rotation = quat(hmd_transform_world); Quote also there no .getRight() .getForward() ... methods in uscript? ( Unfortunately, no. But you can use Swizzling in UScript:getRight() equals to transform.col03;getForward() equals to transform.col13;getUp() equals to transform.col23; Best regards, Alexander Link to comment
lightmap Posted September 8, 2017 Author Share Posted September 8, 2017 Thank you Alexander, for detailed answer in your example (and in demos\superposition_demo_windows_2.5\source\PlayerVRBase.cpp) - as I can see - only yaw rotation (no pitch trough quat) "but rotating around wrong axis if hmd rotated" related mostly to pitch rotation (I'm was not exact in 0th post) assuming getTranstation() equals to transform.col33; and reusing code from your post with change from yaw to pitch only //quat rot = quat(0, 0, R_thumb.x * 75.0f * engine.game.getIFps()); // yaw 75 - degress per second at maximum value of R_thumb.x quat rot = quat(R_thumb.y * 75.0f * engine.game.getIFps(), 0, 0); // pitch 75 - degress per second at maximum value of R_thumb.y vec3 offset0 = hmd_transform_world.col33 - player_transform.col33; vec3 offset1 = rot * offset0; player.setPosition(player.getPosition() + offset0 - offset1); //player.setRotation( rot * player.getRotation() );// behaves as roll player.setRotation( player.getRotation() * rot );// behaves as pitch, but after hmd.yaw rotation by +-90deg it becomes roll still same wrong pitch(https://en.wikipedia.org/wiki/Aircraft_principal_axes) rotation if hmd rotated, Link to comment
lightmap Posted September 8, 2017 Author Share Posted September 8, 2017 I think I miss something else: I can't revert HMD rotations (as it always applyed somewere, don't know where hmd.transform automaticly applyed when it turned on) Mat4 player_transform = player.getWorldTransform(); Mat4 hmd_transform = engine.oculus.getDevicePose(OCULUS_DEVICE_HMD); //player.setRotation(conjugate(quat(hmd_transform))*quat(player_transform));// almost same incriment rotation of player.camera when HMD is on player.setRotation(quat(player_transform)*conjugate(quat(hmd_transform))); I'm expected with this code to get static camera rotation(compensate back HMD rotation), but instead camera rotates with incriment of HMD rotation ... ? Link to comment
alexander Posted September 8, 2017 Share Posted September 8, 2017 but instead camera rotates with incriment of HMD rotation ... ? Very strange. Player has some parent node? You get world rotation (getWorldTransform()), but set local rotation (setRotation instead of setWorldRotation). Try to use player.setWorldRotation. What if "conjugate" change to "inverse"? "but rotating around wrong axis if hmd rotated" related mostly to pitch rotation What type of movement control do you want to implement? Like Aircraft / Space sim? Not like FPS game? When pitch is not equals to 0 and you move forward, player will take off ground (or falling)? Not staying on the ground (XY plane)? Link to comment
lightmap Posted September 8, 2017 Author Share Posted September 8, 2017 (edited) Player nave no parent nodes - default setup movement type FPS like space/swim - no gravity inverse - mat4 only https://developer.unigine.com/en/docs/2.5/api/library/math/math.matrix?rlang=cpp&words=inverse%2Cinvers#inverse_constdmat4n conjugate - quat only (conjugate == inverse - if only rotations) in uscript "inverse(quat(hmd_transform))" give no errors .... Edited September 8, 2017 by lightmap Link to comment
alexander Posted September 11, 2017 Share Posted September 11, 2017 Hi, Lightmap! Quote inverse - mat4 only https://developer.unigine.com/en/docs/2.5/api/library/math/math.matrix?rlang=cpp&words=inverse%2Cinvers#inverse_constdmat4n conjugate - quat only (conjugate == inverse - if only rotations) in uscript "inverse(quat(hmd_transform))" give no errors .... Oops. Thank you for finding error in our documentation. Inverse can work with mat4, dmat4 and quat. At the moment I can't solve your problem. But, I will try to solve it at the end of the week, when I will make a new VR Template for SDK. If you don't finish with it before - watch this topic. Best regards, Alexander Link to comment
Recommended Posts