libgdx - removing the circle outline rendered on Box2d CircleShape - java

CircleShape circle = new CircleShape();
circle.setRadius(1f);
...
using
...
batch.draw(textureRegion, position.x - 1, position.y - 1,
1f, 1f,
2, 2,
1, 1,
angle);
I use this to set the body for a Box2d collision but I get a silly circle shape around my texture in libGdx, i.e. my textured sprite (ball) has a circle over the top of it with a line running from center along the radius.
Any ideas on how to remove the overlying circle lines?

Not 100% sure, haven't used Box2d with libgdx in a while. But look if you have any Box2DDebugRenderer that renders the box2d world. If so, just don't call its render() method.

yes, uncomment the following line.
debugRenderer.render(world, viewport.getCamera().combined);

Related

Rotating and moving static object in ArCore

I'm using the camera anchor in ArCore to create a static object in the scene.
float scaleFactor = 1.0f;
camera.getPose().toMatrix(cameraAnchorMatrix, 0);
// Update and draw the model and its shadow.
Matrix.rotateM(cameraAnchorMatrix, 0, 110, 0f, 1f, 0f);
virtualObject.updateModelMatrix(cameraAnchorMatrix, scaleFactor / 10);
virtualObject.draw(viewmtx, projmtx, colorCorrectionRgba);
However rotating the object sometimes makes it not visible, also translating it doesn't seem to work. I'm also kinda guessing the values for the rotation. Also the object is visible from the top, how can I make it look more natural? (It's an arrow that's supposed to show a direction.)
How can I move the object to the bottom left corner of the screen and rotate it from left to right?
This is how it looks at the moment. I want to move the arrow down and to the left and also tilt it forward. Then it should be able to rotate left and right. Thank your for your help.
Solved it with the following code:
camera.getPose().compose(Pose.makeTranslation(0.37f, -0.17f, -1f)).extractTranslation().toMatrix(cameraAnchorMatrix, 0);
This makes the object appear 'behind' the camera and moves it to the bottom-left. Then you can rotate the object with the angle value:
Matrix.rotateM(cameraAnchorMatrix, 0, 230 - directionChange, 0f, 1f, 0f);

libGDX collision with texture and ShapeRenderer

I am having a bit of a problem with my collision. I have a dog object with two circles, one for his head, the other for his fat body, and a circle that represent a ball texture that hit\collides with the dog's circles (the first one it touches).
Now, all circles are a bit bigger than the texture the represent them.
When I draw them with the SpriteBatch it seem like the textures move inside each other before the collision affect happen, but when I draw the only the circles with ShapeRenderer, the collision affect take place the moment the circles hit\collide.
Why with the different between the SpriteBatch and ShapeRenderer?
EDIT MY CODE:
Dog's circles:
boundingCircleHead.set(position.x + 9.5f, position.y + 6, 6.5f);
boundingCircleBody.set(position.x + 9.5f, position.y + 16, 6.5f);
Ball's circle:
ball.x = MathUtils.random(0, 121);
ball.y = -13;
ball.radius = 11f;
Draw ball:
batcher.draw(BALL, ball.x, ball.y, 17, 19);
shapeRenderer.circle(ball.x, ball.y, ball.radius);
Draw dog:
batcher.draw(dogAnimation.getKeyFrame(runTime), dog.getX(), dog.getY(), dog.getWidth(), dog.getHeight());
shapeRenderer.circle(dog.getBoundingCircleHead().x, dog.getBoundingCircleHead().y, dog.getBoundingCircleHead().radius);
shapeRenderer.circle(dog.getBoundingCircleBody().x, dog.getBoundingCircleBody().y, dog.getBoundingCircleBody().radius);
Collision:
if (Intersector.overlaps(ball, dog.getBoundingCircleHead()) || Intersector.overlaps(ball, dog.getBoundingCircleBody())) {
gameOver();
}

Attaching body to SpriteBatch

Im trying to get a SpriteBatch drawn to sync up to the position of a body.
Im not sure if this is the proper way to do this (in andengine you would just use physics connectors) But i tried drawing the sprite at the position the body was storing.
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
elapsedTime += Gdx.graphics.getDeltaTime();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(walkAnimation.getKeyFrame(elapsedTime, true),
mrsaiBody.getPosition().x, mrsaiBody.getPosition().y, width/2, height/2);
batch.end();
mWorld.step(1/30f, 6, 2);
mRenderer.render(mWorld, camera.combined);
The problem im having with this is, on the screen i see mrsaiBody's shape and i see the ground i made. When the shape makes contact with the ground the x and y values still continue to be affected by gravity even though the shape isnt. How can i get the current position of this shape to match up with position when i use batch.draw?

Using filledcircle and pixmap in libgdx

I am using Libgdx.
I want to simulate fog in my game using pixmap, but I have a problem during generating the "fogless" circle. First, I make a pixmap, filled with black (it is transparent a little bit). After filling I want to draw a filled circle onto it, but the result is not that I expected.
this.pixmap = new Pixmap(640, 640, Format.LuminanceAlpha);
Pixmap.setBlending(Blending.None); // disable Blending
this.pixmap.setColor(0, 0, 0, 0.9f);
this.pixmap.fill();
//this.pixmap.setColor(0, 0, 0, 0);
this.pixmap.fillCircle(200, 200, 100);
this.pixmapTexture = new Texture(pixmap, Format.LuminanceAlpha, false);
In the procedure render()
public void render() {
mapRenderer.render();
batch.begin();
batch.draw(pixmapTexture, 0, 0);
batch.end();
}
If I use Format. Alpha when creating the Pixmap and Texture, I neither see the more translucent circle.
Here is my problem:
Problem
Could somebody help me? What should I do, what should I init before to draw a full transparent circle? Thanks.
UPDATE
I have found the answer for my problem. I have to disable blending to avoid the problem.
Now my code:
FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, 620, 620, false);
Texture tex = EnemyOnRadar.assetManager.get("data/sugar.png", Texture.class);
batch.begin();
// others
batch.end();
fbo.begin();
batch.setColor(1,1,1,0.7f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw( tex, 100, 100);
batch.end();
fbo.end();
But I don't see the circle (it's a png image, represents transparent bg, white filled circle).
I am not sure if this works for you but i just share it:
You could use FrameBuffers and do the following:
Draw everything you want to draw on screen.
End your SpriteBatch and begin your FrameBuffer, begin the SpriteBatch again.
Draw the Fog, which fills the whole "screen" (FrameBuffer) with a black, non transparent color.
Draw the "Fogless" circle as a white circle, at the position you want to delete the fog.
Set the FrameBuffers alpha channel (transparancy) to 0.7 or something like that.
End the SpriteBatch and the FrameBuffer to draw it to screen.
What happens? You draw the normal scene, without fog. You create a "virtual screen", fill it with black and overdraw the black with a white circle. Now you set a transparacy to this "virtual screen" and overdraw your real screen with it. The part of the screen, which is under the white circle seems to be bright, while the black rest makes your scene darker.
Something to read: 2D Fire effect with libgdx, more or less the same as fog.
My question to this: Libgdx lighting without box2d
EDIT: another Tutorial.
Let me know if it helps!
EDIT: Some Pseudocode:
In create:
fbo = new FrameBuffer(Format.RGBA8888, width, height, false);
In render:
fbo.begin();
glClearColor(0f, 0f, 0f, 1f); // Set the clear color to black, non transparent
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Clear the "virtual screen" with the clear color
spriteBatch.begin(); // Start the SpriteBatch
// Draw the filled circles somehow // Draw your Circle Texture as a white, not transparent Texture
spriteBatch.end(); // End the spritebatch
fbo.end(); // End the FrameBuffer
spriteBatch.begin(); // start the spriteBatch, which now draws to the real screen
// draw your textures, sprites, whatever
spriteBatch.setColor(1f, 1f, 1f, 0.7f); // Sets a global alpha to the SpriteBatch, maybe it applies alo to the stuff you have allready drawn. If so just call spriteBatch.end() before and than spriteBatch.begin() again.
spriteBatch.draw(fbo, 0, 0); // draws the FBO to the screen.
spriteBatch.end();
tell me if it works

How to have rotated Ellipse shape in Java?

How to have rotated ellipse Shape in java? I.e. so that its semi-axes are not parallel to coordinate axes?
P.S. I need not just draw this ellipse but have it in memory as a shape object.
Just take an Ellipse2D object and apply an AffineTransform rotation to it, no?
AffineTransform.getRotateInstance(Math.PI / 4)
.createTransformedShape(new Ellipse2D.Double(0, 0, 2, 1));

Categories

Resources