libgdx viewport segment with orthographic camera - android

Does anybody knows, how to cut out camera viewport to smaller size than screen? e.g if I want to have status bar at the top of the screen and moving camera cut only to the area without this status bar? The problem is that camera viewport is always stretched to full screen.
Thanks in advance

Generally the way I do this is by defining two cameras. One for the UI and one for the game world. The UI camera never changes it's position only the world camera moves around.
Then when rendering your UI (assuming you are using SpriteBatch) you simply do this:
batch.setProjectionMatrix(gameCamera.combined);
// ... render your game code
batch.setProjectionMatrix(uiCamera.combined);
// ... render ui code
Just make sure you update your camera as per normal if it has changed via camera.update()

Related

how to make a rectangle sprite stick to one side in Unity?

I am using a square sprite in Unity for making Android game. I want this rectangle to be always placed at the bottom of the screen. This strip acts as a ground and other objects can fall on it. I want the lower side of this rectangle to stick to the lower side of the screen. How to do it?.If i try to place it there manually then after I change the screen resolution the placement gets disturbed?Also the camera is not moving, so I only want to fix the position of this strip with respect to the camera once. (i think so). What should i do?
We need a little more information. Sprites at the lower side of the screen, usually intend to be in the UI. Is this the case? If it is, the way to do it is very different from a normal sprite in the world.
(Since I am not allowed to comment, I will try to answer for both cases, however I am not at a computer capable of running Unity, so I can't really provide a concrete answer (aka: Code))
UI:
Add an Image to your Canvas. Go to your anchor preset (inside the Rect Transform) and set it to the appropriate position. Then, in case you want the image to not be stretched, go to the Image component and Check on the "Maintain Aspect Ratio" (Or something like that) option. Add the sprite to the image and you are all set.
World:
Here, the situation is way more complicated. You first need to get the screen dimensions, then calculate the size of the object according to the aspect ratio, then have some Camera.ScreenToWorldPoint conversion and finally use the LookAt method in the Update() in order to have the sprite face the camera at all times. Or use the UI layer as described above, let's be honest that is probably what you need.

How to render in Unity without the editor/scene/player being visible?

In my Android-Unity app I have some data such as text, text size, text coordinates etc that I will use to create the output and store it as a screenshot I will later use in my app.
But I need to make this happen when the user isn't seeing the Unity player/scene. So my question is that is it possible to render the contents and then take a screenshot of the same without the user seeing the Unity editor/player/scene whatever one may call it? Is there a way to do it in the background? Thanks!
I'm not sure exactly what you're trying to accomplish but I can clarify the use of a culling mask here. Here is what the scene looks like. I have embedded the view from Camera 2 into the bottom left of the game. You can see that Camera 2 is not displaying the floor. This is because I set it's culling to only respond to objects tagged with a custom layer here. Where as the Main Camera's culling mask is set to everything. Now, anything I tag with the "Custom" layer will be visible in the second camera and everything else would not be. I'm assuming what you want to do from here is to tag the things you want visible when you take a screenshot with a specific layer, then set the Culling Mask of your "Screenshot Camera" to that layer and take a screenshot with that Camera. That way you can specify what Objects/UI want visible in that camera.

Second camera for UI in GoogleVR Unity5

I have a problem on Google VR, as you can see on the screen shot, on the right eye camera, the UI is double. I didn't do anything in the code, I just created another cam for the UI and culling mask is set only to UI, then this is what happened.
What can I do? Please help!

OpenGL: Take screenshot of screen and transform (shrink) it, then draw that on a portion of the screen

I want to use OpenGL for Android to take the screen (make "continuous" screenshots), make it smaller vertically, then paint it back to leave a black bar at the bottom of the display.
Basically:
Read pixels
Transform (shrink the screen vertically)
Paint back the shrunk screenshot on the display.
Repeat 1.-3. continuously.
How can I do this? The bottom line is that I want to have space for some other stuff at the bottom of the screen while still not missing something underneath what I want to display (think the soft home buttons in Android).
This sounds insanely expensive. I'd really try just to render it at the correct size in the first place.
Use glScissor to limit the region of the screen to stop drawing outside of that, and glViewport to correct the transform behaviour.

how to attach overlay to detected object using android and OpenCV

I'm writing an android app using OpenCV for my masters that will be something like a game. The main goal is to a detect a car in selected area. The "prize" will be triggered randomly while detecting cars. When the user will hit the proper car I want to display a 3D object overlay on the screen and attach it to the middle of the car and keep it there so when the user will change the angle of his view on the car, the object will also be seen from diffrent angle.
at the moment I have EVERYTHING beside attaching the object. I've created detection, I'm drawing the 3D overlay, I've created functions that allow me to rotate the camera etc. BUT I do not have any clue how can I attach the overlay to the specific point. Cause I don't have this I have no point to recalculate the renderer to change the overlay perspective.
Please, I really need some help, even a small idea will be fine:
How can I attach the overlay to the specific in real world
(Sorry, I couldn't comment. Need at least 50 points to do that ... :P )
I assume your image of the car is coming from a camera feed and you are drawing 3d car in opengl. If so, then you can try this:
You set the pixel format of the opengl layer as RGBA_8888, so that you can set the background of the opengl camera as a transparent color.
You take a relative layout as layout of your activity.
first you add the opencv camera layout to it as full height and width.
then you add opengl layer as full height and width.
you get the position of the real car from opencv layer as pixel value or something you did.
then scale it to your opengl parameters so that you can draw it on the right spot.
it worked for me. hope it works for you too.

Categories

Resources