Get Rotation (Tilt) Angle In Landscape View - Android Java - java

I've scrounged the web in search of a good example or someone trying to attempt the same thing, but so far I haven't had much luck.
I am trying to get my Devices rotation angle (If you can imagine) starting at 180° (Flat).
As the user tilts the device left and right, the angle adjusts accordingly.
And as it rotates I want to simply update a TextView.
I'm just lost as to what this evolves, some people suggest a gyroscope, accelerometer, even a magnometer, or a combination.
I've gotten a few different sensors to work, but none of the examples I've followed accomplish what I want to achieve.
I don't want anything to do with 3D, just a plan rotation.
Can anybody forward me in the right director, or provide some information?
Thank you very much!

You implement OrientationEventListener this will give you the device rotation. Portrait is 0 degree.

Related

Draw Latitude/Longitude points/lines on screen in Android, offline, without real maps functionality

I'm developing an Android application (in Java/Android Studio) which receives Latitude/Longitude coordinates from a network source, which it has to plot on the screen. The appearance should be much like one of those old 'green-on-black radar screens'.
Constraints/Requirements:
The application doesn't have connection to the internet. (never)
I need to draw points, (custom) markers, lines, and polygons, all based on latitude/longitude information.
The background should be plain black. i.e. no map tiles or anything.
Does anyone know of a library which can help me achieve this?
Other options I'm considering:
Manual direct conversion to screen X/Y coordinates. This seems problematic (?) as you get closer to the poles.
Converting all points to polar coordinates (bearing/distance) from a center position. And then convert these polar coordinates to screen X/Y coordinates. Should work for the radar-style application, but seems cumbersome when there's a good library available.
I'm really interested in what you guys think and if you have suggestions on how to address this.
Thanks a million!
Kind regards,
Joost

Android - How to know when device is flat to ground or not?

I want to know if a device is flat to the ground or not?
Flat Mode:
My Android device is placed flat on a table with its screen upside. Then it is laying flat to the ground.
Not Flat:
And when I picks up the device from its top corner - keeping its bottom corner still on table. Then it starts standing vertical to the ground. And Now it is not lying flat to the ground anymore.
Problems:
How can I know exactly using sensors and SensorEvents in android about this? TYPE_ORIENTATION is now deprecated. But still how can specific sensor values be used to determine if the device is flat to the ground or not. Where would I find such calculation?
I have explored some posts about sensors but I am still confused how my problem is going to get solved?
Related Posts:
How should I calculate azimuth, pitch, orientation when my Android device isn't flat?
Android Compass that can Compensate for Tilt and Pitch
You have to register for sensor type accelerometer and then see how to calculate the tilt at
How to measure the tilt of the phone in XY plane using accelerometer in Android
For your purpose if the inclination in the above link is not zero (give or take a few degrees) then your device is lifted up.
I would see if the device has a gyroscope and if not then use an accelerometer. Both in unison would be even better. With orientation it seems you are worried with rotation, hence the gyroscope. Accelerometers aren't as efficient at measuring rotation.

3rd Person Camera View

I have been trying to make a 3rd person camera in libgdx for the past couple of days and can't seem to figure out how to do it. I have tried the rotateAround function in PerspectiveCamera, but when I move the camera to be just behind the model its suppose to follow, the rotation gets messed up. I am at a loss at what to try now. I want the camera to be set back and just above the model and to follow it. If someone could point me in the correct direction, I would greatly appreciate it.
In your render method of your game you want to update the camera to follow the player at a distance and you also want to make sure that the camera is looking at the right position either at your character or just ahead if you want to get an over the shoulder view.
Depending on the scale of your models you may have to play around with these values.
In the render loop you want something like this:
note that in this example player is a vector3 and cam is a Perspective camera
This will make the camera look at the character. You may want to modify the values to make it look ahead (Change the x and z for that).
cam.lookAt(player.x, 0, player.z);
Here we set the location of the camera so we can see that it will always be floating behind and above the character
cam.position.set(player.x, 10f, player.y-20f)
This updates the camera to apply all of your transformations
cam.update();
About rotation i'm not too sure, i've not tried it. Heres an article that should help.

Game Development, strange image effect while moving camera

I'm developing Side Scroll 2D Game, using AndEngine
I'm using their SVG extension (I'm using vector graphic)
But I discovered strange and ugly effect, while moving my player (while camera is chasing player exactly, means while camera is changing its position)
Images of my sprites looks just different, they are like blurred or there is effect like those images would be moving (not changing their possition, just jittery effect, really hard to explain and call this effect properly) Hopefully this image may explain it a bit:
Its more or less, how does it look in the game, where:
a) "FIRST" image is showing square, while player is moving (CAMERA isn't) image looks as it should
b) "SECOND" the same image, but with this strange effect "which looks like image moving/blurring during camera moving [chasing player])
Friend of mine told me that it might be hardware problem:
"the blurring that you notice is actually a hardware problem. Some phones "smooth" the content on the screen to give a nicer feel to applications. I don't know if it's the screen or the graphics processor, but it doesn't occur on my wife's Samsung Captivate. It happens on my Atrix and Xoom though. It's really noticable on the Xoom due to the large screen size."
But seems there is way to prevent it, since I have tested many similar games, where camera is chasing player, and I could not notice such effect.
Is there a way to turn this off in code?
I'm grateful for previous answers, unfortunately, still problem exist.
Till now, I have tried:
casting (int) on setCenter method which is being executed on updateChaseEntity
testing game using PNG images, instead of SVG extension and vector graphic
different TextureOptions
hardwareAcceleration
If someone have different idea, what may cause this strange effect, I would be really grateful for help - thank you.
Some devices (Xperia Play) bleed everywhere when trying to draw things that are moving quickly. For example a red icon on the application list leaves a blur behind it. You could try hardwareAcceleration in the manifest (on and off) to see if it makes a difference.
You'd probably get the same effect if you weren't using svg
When your player's just going to the right and camera begins chasing him, all other sprites except player are moving to the left. Try to print the absolute coordinates of your "blurring" sprite (or some of its anchor points) to the log. The X-coord of sprite should be decreasing linearly. If you notice it's increasing some times, it could be a reason of blur.
Hope this will help.
It sounds like it's due to the camera moving in real increments, making the SVG components rest on non-integer bounds, and the SVG renderer making anti-aliasing come into effect to demonstrate this. Try moving the camera in integer increments by casting camera values to int.
I'm not familiar with this engine but I wonder why would you use vector graphics for pixelated art style. I'll be surprised if your character in the screenshot is really a vector art... maybe it's texture imported in SVG? I attempted back in the day to use flash a few times and I was making the same mistake... I'm not saying it's not possible but it's not intended to create pixel art with flash or any other vector software. There is a reason why most flash games have similar look.
Best way to debug it, is try a different looking sprite.
Maybe it is just the slow response time of your device display.
I'm also an Andengine developer, and never seen such behavior.
Sometimes you fix jittering using FixedStepEngine, it might help.
If you can post your code maybe we can better help you.

How to draw from point A to point B like in navigation systems

It's going to be a very generic question.
By the way, I am trying to replicate this :
I created a web page that displays the lat/long information for whoever. It refreshes itself every X second.
I open my android, navigate to my web page, put the phone somewhere in the car and start driving. The idea is to capture my entry/exit lines to see how good/bad my approach to an apex is.
I guess I need to understand how typical in car navigation systems work. They track you to the point. Any ideas?
I don't think GPS is going to be accurate enough for this.
Assuming you have a good fix on 5 or 6 satellites, your coordinates are typically going to be 15-30ft from your actual position. This is barely enough to determine which side of the road you're on, and probably won't help you.
Car navigation systems fake it to make it seem that they are far more accurate. They use information such as your current position, heading, and the road data it has to plot more precisely your location.
You can prove this easily. Take a car GPS system, and start walking away from the road. You will have to get a decent distance away from the road before it shows you aren't on it anymore. That is because the software is trying to compensate for the inaccuracy of the coordinates coming from the GPS.

Categories

Resources