Sensor Orientiation -> GLRotation doesn't work properly - opengl-es-2.0

I want to use the Android orientation sensor data for my GLES camera - giving it the rotation matrix. I found a very good example here:
How to use onSensorChanged sensor data in combination with OpenGL
but this is only working with GL1.0 and I need to work on it for GLES2.0. Using my own shaders, everything works, moving the camera manuall is fine. But the moment I use the rotation matrix like in the example, it doesn't really work.
I generate the rotation matrix with:
SensorManager.getRotationMatrix(rotationMatrix, null, bufferedAccelGData, bufferedMagnetData);
My application is running in LANDSCAPe so I use that methode after (like in the example code):
float[] result = new float[16];
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, result);
return result;
It worked fine on my phone in his code but not in mine. My screen looks like that:
The rotation matrix seems to be rotated 90° to the right (almost as if I have forgotten to switch to landscape for my activity).
I was thinking of using the remap() method in a wrong way but in the example it makes sense, the camera movement works now. If I rotate to the left, the screen rotates to the left as well, even though, since everything is turned, it rotates "up" (compared to the ground, which is not on the bottom but on the right). It just looks like I made a wall instead of a ground but I'm sure my coordinates are right for the vertices.
I took a look ath the draw method for the GLSurface and I don't see what I might have done wrong here:
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
MatrixStack.glLoadMatrix(sensorManager.getRotationMatrix()); // Schreibt die MVMatrix mit der ogn. Rotationsmatrix
GameRenderer.setPerspMatrix(); // Schreibt die Perspektivmatrix Uniform für GLES. Daran sollte es nicht liegen.
MatrixStack.mvPushMatrix();
drawGround();
MatrixStack.mvPopMatrix();
As I said, when moving my camera manually everything works perfect. So what is wrong with the rotation matrix I get?

Well, okay, it was a very old problem but now that I took a look at the code again I found the solution.
Having the phone in landscape I had to remap the axis using
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, R);
But that still didn't rotate the image - even though the mapping of the Y and -X Axis worked fine. So simply using
Matrix.rotateM(R, 0, 90, 1, 0, 0);
Does the job. Not really nicely but it works.
I know it was a very old question and I don't see why I made this mistake but perhaps anyone else has the same problem one day.
Hope this helps,
Tobias

If it is (was) working on a specific phone but not on yours, I guess the android version may play a role here. We faced the issue in mixare Augmented Reality Engine where a Surfaceview is superimposed over a Camera view. Pleas consider that the information here may not apply to your case since we are not using OpenGL.
Modern version of android will return a default orientation, whereas previously portrait was the default. You can check how we query this in the Compatibility class. This information is then used to apply different values to the RemapCoordinateSystem call check lines 739 and onwards of this file.
Mixare is as well using landscape mode by default, so I guess our values for the remapping should apply to your case just as well. As I said earlier, we are using the 3x3 matrices, since we are not using OpenGL, but I guess this should be the same for OpenGL compatible matrices.

Take time, play with the orientation matrix, you will find a column that contains useful vaule.
Besides Log vales for each column, see which one is useful, try quaternions, keep playing with values never try the code directly in renderer, first check the values
Because later, you will have more options for input like touch, there too you have to test the values, play with them, use sensitivity constants with matrices too

Related

Unreal Engine 5.1 Retargeted Animation From Manny to Mixamo Model Causes Single Animation Sequence To Rotate 90*

I apologize if this has been asked before. I tried searching for this first and nothing is coming up. I'm pretty new to Unreal Engine 5.1 so this might be something I'm doing as well.
I've been exploring animation retargeting in unreal and have tried following the steps we learned in class using one of the models from mixamo.com. Everything appears to work fine at the start and I can get the actual IK and IKR objects working just fine. However when I try to export the animations either from the IKR object or by right clicking the ABP object for the source mesh one and only one of the animation sequences rotates 90*. It is always the same animation (the Land animation sequence) and I'm not sure how to go about fixing it.
Also tried looking on google and turned up nothing.
I'm hoping this is some stupid newb mistake that is easy to fix or maybe there's something I'm overlooking. Any help is greatly appreciated and I will continue trying to fix the problem myself as well and will post if I fix it
Tried retargeting using the following steps
Create an IK_Object for the model you wish to project your animations on with chains for each. Mine looked like the following
IK_Remy
Repeat step 1 for the model you wish to source animations from. Mine looked like the following
IK_Manny
Create an IKR_Object Linking the two together, here's what mine looked like
IKR_Remy
Find the ABP for your source model, right click, and select "Retarget Animation Assets->Duplicate and Retarget Animation Assets". Here's what I'm selecting for that
Retarget Dialog
When I do the following most of the animation sequences for "Manny" export just fine. However the "Land" animation flips for some reason (see image below)
Exported Animation Images
Even stranger, when I preview the MM_Land animation in my IKR object it looks fine i.e. not rotated. However, if I try to export the animation from the IKR object the same thing happens i.e. it rotates 90*. I would expect this to be a case of WYSIWYG where if it's working in the preview it would export correctly. However that apparently is not the case
Also I tried modifying the animation sequence manually but it won't let me. If I try to rotate the model in the animation sequence and save it, once I close the sequence it's re-rotated and the changes do not persist.
I can export the sequence as a new sequence, modify it, and save it, and then rename it as my exported "Land" animation to hard force it and it at least looks normal. However when I actually play the game and jump, when the land animation it still flips sideways and in addition causes the character to scale and warp for a second which makes me think there's something going on here that I don't know enough to fix. Really hoping someone with more experience in Unreal Engine can help.
EDIT: Fixed Image Descriptions
I can confirm that this is an issue - I'm seeing the same behaviour. I haven't managed to fix it yet, but my suspicion is that it's due to scaling - in my instance, I have had to scale up my custom character by around 2.5 times to replicate the scale of the default mannequin. Did you scale your custom character at all?

Drawing horizontal or vertical lines won't get drawn on the surface. Vulkan

Have this problem of a line not getting drawn. But only it it's perfectly vertical or horizontal.
Say i have points A{ 400, 300 } and B{ 400, 200 }. Now if I try to draw a line between these points it doesn't find it's way on the screen.
If i however change the point A to be positioned at { 401, 300 } the program runs as i would intend it to run.
Is there a clear reason why straight horizontal or vertical lines doesn't get drawn? And a way to circumvent that? Don't wanna tilt all the straight lines.
Part of the pipeline-setup:
inputAssembly.topology = vk::PrimitiveTopology::eLineStrip;
rasterInfo.polygonMode = vk::PolygonMode::eLine;
using VulkanSDK 1.0.42.1 on intel igpu.
Edit:
Okay if i raise linewidth over 1.f on rasterizer it will draw. However not every gpu is capable of doing that. But atleast a temporal quirk.
(I know it's a very old post, but no answer provided. ;-)).
In case of the lines wider than 1.0f - You are allowed to draw such lines only if You enable wideLines feature and You can enable it only when it is supported by a physical device You are using. Without enabling this feature, You can't provide values other than 1.0 for line width during pipeline creation. So even if it works, it can only be a temporary solution because You are violating the specification.
This kind of behavior suggests it's a bug in a driver. Try the latest version (if You didn't do it already) and if it doesn't help contact Intel's support and submit a bug (if You didn't do it already ;-)).

libgdx tiledmap flicker with Nearest filtering

I am having strange artifacts on a tiledmap while scrolling with the camera clamped on the player (who is a box2d-Body).
Before getting this issue i used the linear filter for the tiledmap which prevents those strange artifacts from happening but results in Texture bleeding (i loaded the tiledmap straight from a .tmx file without padding the tiles).
However now i am using the Nearest filter instead which gets rid of the bleeding but when scrolling the map (by walking the character with the cam clamped on him) it seams like a lot of pixel are flickering around. The flickering results can get better or worse depending on the cameras zoom value.
But when I use the "OrthoCamController" class from the libgdx-Utilities which allows to scroll the map by panning with the mouse/finger i don't get these artifacts at all.
I assume that the flickering might be caused by bad camera-position values received by the box2d-Body's position.
One more thing i should add here: The game instance runs in 1280*720 display mode while my gamecam renders only 800*480. Wen i change the gamecam's rendersolution to 1280*720 i don't get those artifacts but then the tiles are way too tiny.
Has anyone experienced this issue or knows how to fix that? :)
I had a similar problem with this, and found it was due to having too small a decimal value for the camera position.
I think what may be happening is some sort of rounding with certain tile columns/rows in the tilemap renderer.
I fixed this by rounding to a set accuracy, like so:
camera.position.x = Math.round(player.entity.getX() * scalePosition) / scalePosition;
Experiment with various values, but I got it working by using the tile size as the scalePosition value.
About tilesets, I posted a solution here: Getting gaps between tiled textures with libgdx
I've been using that method with Tiled itself. You will have to adjust "margin" and "spacing" when importing tilesets in Tiled to get the effect working.
It's 100% working for me :)

XNA model translation is bizzarre

When using Matrix.CreateTranslation(x,y,z) I get bizarre results. I have tested using fixed values, one variable at a time and have determined the following:
When altering the X coordinates, the model moves from the top left corner to the bottom right corner.
When altering the Y coordinates, the model moves up and down as it should.
I do not plan to alter the Z coordinates, but because of the nature of my program I can't figure out exactly what it does.
I have my model drawn. Rotation works fine. I am performing my translations in the correct order (at least I think): scale * rotation * translation.
I think the problem lies in my camera settings, but I have no idea exactly what the problem is. I am trying to create a top-down-style RTS camera.
Here are my camera settings:
campos = new Vector3(5000.0F, 5000.0F, 5000.0F)
effect.View = Matrix.CreateLookAt(campos, Vector3.Down, Vector3.Up)
I can provide more information as needed.
The second argument of Matrix.CreateLookAt is not the direction the camera is facing, but the targeted point.
If you try to make the camera look down, use
Matrix.CreateLookAt(campos, campos + Vector3.Down, Vector3.Forward)
This will tell the camera to always look at the point one unit below the camera.
Your translation probably doesn't work well because the camera is not looking at the point you want it to, and therefore looks like the model is moving diagonally.

GLKit Rendering and iOS Device Orientation (Face Up / Down)

I have an app with some projection matrix set-up code based on Xcode 4.5.2's OpenGL Game template. In the update function I set appropriate z-translation values for baseModelViewMatrix by querying [[UIDevice currentDevice] userInterfaceIdiom] as well as UIDeviceOrientationIsLandscape: and UIDeviceOrientationIsPortrait:. This effectively lets me set the scale of the area rendered on screen on a per-orientation basis for each device. I also call update from willAnimateRotationToInterfaceOrientation:duration: to maintain the correct rendering proportions for each orientation of the device during runtime.
This all works fine, however I've noticed that when the device is oriented either face-up or face-down my scene is not displayed, and I only see what appears to be an empty GLKView. Rotating the device to any orientation perpendicular to the ground plane restores the scene to its expected behavior. I tried checking UIDeviceOrientationIsValidInterfaceOrientation:, which seems like it should handle what I need, but did not see any difference in behavior.
My guess is that GLKit does some automatic updating of the GLKView when a change in orientation is detected, but I didn't find any clear answers on what might be causing this particular behavior. Any thoughts on what's going on? Thanks in advance.
If you are using a function like GLKMatrix4MakeLookAt, you need to make sure your look direction is not parallel with the up direction. In the case of looking straight up or down, you'll need to adjust the camera's "up" vector to another value such as 0,0,-1 or 0,0,1.