LibGDX: Inscribing a texture in trapezoid - libgdx

Lets say I have an image of a spaceship and when it's moving from side to side it should be twisted by some angle. When it's steady and not moving it's parallel to the ground and to the viewports projection matrix. During the movement the shape of the spaceship for the observer turns into a trapezoid. So I am seeking for a way of distorting the image in order to "fit" it into a trapezoid. Here is an image for clarification.
This could be easily achieved by using PerspectiveCamera and 3D environment. The big trouble is that the game is already written using OrthographicCamera and 2D logic. Is there a way of solving this problem without creating a new set of animations and overwriting the whole project in 3D?

Related

LibGDX Hitbox / Polygonshape and Physics

Hello I have two smaller questions:
Is it possible to map the Shape of the Body 1:1 to the texture so I have a perfect collision detection ? Because right now I only know of two ways to do it: Create the Shape before and load it up with a texture or load the texture first and then set the shape as a box ... But that is too simple I think.
Also does anyone know how I can turn off the physics of the world ? When Body A hits Body B I want the Body to do a certain animation and fall to the ground with some sound effects, but when the two objects collide they bounce off each other in different directions etc. When two objects collide I want it to be "Game over" basically and stop calculating momentum etc.
I dont care about the solution itself, just telling me if its possible at all for both questions would be enough.
I guess you are using Box2d
Is it possible to map the Shape of the Body 1:1 to the texture so I
have a perfect collision detection ?
It possible, you can use PolygonShape in Box2D, but it has to be a convex polygon. Furthermore it slower then predefined shapes.
Also does anyone know how I can turn off the physics of the world ?
With box2d Physics you can simply stop the simulation on your own by not executing the world.step() command

How to make the sprite.BoundingRectangle fit the sprite exactly

In LibGDX, I'm trying to create a game where you play a character who must survive waves of zombies. The plan is, when a zombie touches the player, the player loses health, and the zombie despawns; this works well until any of the sprites are rotated. Here's a screenshot of what I can imagine to be why:
To check the collisions, I use:
if (sprite.getBoundingRectangle().overlaps(Game.pl1.sprite.getBoundingRectangle())) {}
.. this is inside the Zombie class, and Game.pl1.sprite refers to the sprite belonging to the player.
So the red box is where I'm assuming the bounding rectangle is, based on where zombies despawn around it.
This is what I want the bounding rectangle to be:
I'm not sure if I can achieve this just using sprite.getBoundingRectangle so I was thinking perhaps I would need to use Box2D or maybe convert the sprite to a texture.
You could get the dimensions for a rectangle the size of the sprite if it wasn't rotated, and then rotate that.

How to create a circular constrained paddle using Box2D?

I am trying to create the ball and paddle setup just like in Circle Pong. It is basically a paddle which revolves about a circular path as if it is tied by a rope to the center of the circular orbit.
here is a video of Circle Pong: https://www.youtube.com/watch?v=9sitwBolywY
I want to use Box2D for the physics. How do I constrain the paddle to move in a circular orbit? I might even want to have multiple paddles for a circular orbit (with a fixed angular distance from each other).
A distance joint with a static central body won't work because the central body might obstruct / come in the way of the ball. Also it won't work with multiple paddles.
Any ideas?
for the first I'm not sure if you need physics engine in game like this at all - it seems to be such simple that simple scene2d actions + setting origins should be enough - please notice that it would improve your game performance and make it easier to deploy.
But - if you are sure you want to use box2d please consider using distance joint with a body which has a fixture with isSensor = true. It won't take part in collision calculations, letting you to achieve your point.
FixtureDef fixtureDef = yourMaterial;
fixtureDef.shape = yourShape;
fixtureDef.isSensor = true;

How do I create collision detection with an object and part of a background?

I am just starting to attempt to make my own game using java and libgdx, and the extent of my success so far has been showing the background image on screen, and spawning a little square the user controls with WASD. The background is just a solid color, with a vertical rectangle that is red inside and has black edges. I want to make it so the tiny square (player) can move anywhere within the red rectangle, but not be able to cross over the black edges (out of the rectangle). How would I go about doing this?
Since I am a complete beginner to this stuff I must ask these related questions...
Should the player be just a texture? Should the background be a texture? or a sprite?
I'm not sure the difference between the two yet.
I recommand you to read tutorials about libGDX and Box2D like this one : http://www.gamefromscratch.com/post/2014/08/27/LibGDX-Tutorial-13-Physics-with-Box2D-Part-1-A-Basic-Physics-Simulations.aspx
to answer you're questions, in short :
a texture is an image in memory
a sprite is a part of a texture (or the whole texture) transformed (translation, scale, rotation) to be drawn on screen.
so basically, in the view model, your player is represented by a sprite, your background is a sprite as well.
Player 1 and 2 are 2 different sprites but may reffer to the same texture (bitmap).
with box2D, in the physics model, your player will be represented as a dynamic body and your background as a static body.

Rotating a rectangular solid about the y axis without image distortion using canvas renderer (three.js)

I've spent several hours trying to work around this issue... when rendering really simple shape (ie. a cube with very low complexity) and using a texture map feature of Three.js, when you rotate the cube the image seems to be distorted while in rotation, and then you can see a line which runs across the surface of the cube which appears as distortion.
http://screencast.com/t/VpSPRsr1Jkss
I understand that is a limitation of canvas rendering - but it seems like this is is a really simple thing to do - rotate a cube that has an image on one face without the distortion.
Is there another canvas library or approach i can take? I was really looking forward to using Three.js for animating some logos and other elemnets - but we can't have distortion like that in a logo or a customer facing landing page.
Thanks for reading, I'm open to suggestions here.
I don't accept increasing the complexity of the face as a solution because that just distributes the distortion through out the face. I really just want to render the image to a flat surface and be able to rotate that object.
The distortion you see is because only two triangles make that plane.
A quick fix is to have more detailed plane.
If you are using PlaneGeometry, increase the number of segments.
If you are using CubeGeometry, increase the number of segments on the plane you need (2 out of 3).
It will take a bit of fiddling to find the best balance between a decent look and optimal performance (as more segments will require more computing). Hopefully for simple scene you'll get away with no major delays.