Rotating Asteroids - java

I'm trying to make asteroids that spin in my 2D game.
Using the graphics class I am drawing an image I created onto the screen (the asteroid) and moving it across the screen.
My next step was to make it rotate however I am lost at to how to do this.
I was able to make it rotate when I was simply drawing a polygon by changing the vertices of the asteroid however there are no vertices when drawing images, only (x,y) and (length,width).
How can I rotate an image? Is there any inbuilt functionality that does it?
I'm not asking for someone to tell me exactly how to do this, I'm just looking for a push in the right direction as I am a bit lost.

Either use a AffineTransform or use Graphics#rotate. In either case, you should make a copy of the Graphics context first (Graphics#create) first, which will preserve the state of the original context. Just make sure you dispose of the copy when you're done (Graphics#dispose)
Something like this perhaps

Related

opencv java - detect all the rectangles and fill them with an image

I am currently working on a solution for an automatic image edit.
And I have used Canny Edge Detection and Closing.
But What I ultimately want to accomplish is to find all the rectangles from blueprint and fill them with an image what I have.
I want to know the process that I need to take, not the exact code or solution!
Please suggest me what steps should I take to accomplish it, thx.
Image that has the rectangles
Image that needs to go into all the rectangles
what i have done so far
2018-02-12 EDITTED(clean rectangle detected)
// I have done finding the rectangles and drawing lines over them, but the result is not really reliable than I expected(it draws line on rectangles those are not a parking space), and I do not know how to put an image on those rectangle instead of drawing line on them. please help me out!
P.S : Only in JAVA please !
In your case, you don't need Canny. Your image is really clean and edges are really visible already. A simple Threshold, will work better.
For rectangle detection take a look at this example (included with opencv) that uses findcontours and checks the angles: https://github.com/opencv/opencv/blob/master/samples/cpp/squares.cpp
In your case, you can skip the Canny step because you don't have gradients. You may need to modify the filtering, like side dimensions for your case.
Once the rectangles look good, you just need to copy your image in the location. If rectangles are rotated, you will have to rotate your image as well.
EDIT:
To copy the small image onto the big image you can do the following
Mat submatImg = bigImage.submat(new Rect(x, y, smallImage.width(), smallImage.height());
smallImage.copyTo(submatImg);
If you need to do resizing and rotations, take a look at geometric transformations

Stage is bigger than the screen in LibGDX, how to fit it in the screen?

I'm developing a game in libGDX, and the levels in my grid contains a grid actor which contains mirrors inside (see my game). The problem is that the grid is too big and I want to be able to see all the stage.
I'm using an OrthographicCamera and an ExtendViewport.
I tried using frustrum (I don't really know what it is): I create four BoundingBox (left, right, top and down) which are placed out of the grid. I set the camera position to the middle of the grid actor and i make a loop zooming the camera until the boxes are in the frustrum, but I don't know if it is the best solution...
I think you want to use a FitViewport, which will make sure you don't 'spill' off the screen.
FYI, the frustum is used to determine depth of your camera- how far it can see. I agree that that won't help you in this situation.

render what's goes outside of the screen in 2d

how can I render whats right outside of the screen on the left side? Like in Super Mario Bros for example? I want to move clouds endless over the screen.
Here's an example of what I mean:
http://image-upload.de/file/nSzNhe/612a71bf0d.png
You simply create the entity with coordinates that are offscreen, and have a draw function that draws the entities, and when they move onscreen, they will be drawn. Might also want to make sure they get deleted once the go offscreen again though.

How to make transparent part of a sprite in a Java 2D Game?

I'm making a 2D tile based game and I need to make part of a sprite transparent.
I assume I should choose a determinate color and tell Java "Please Java, don't draw any pixel of this color.", but I don't know how to do it.
I already googled it but I only get results about "alpha".
Also how can I "set priority" to my sprites so that the ones with high priority are always drawn in the front?
Thanks.
Use png files for the sprites. Java will draw transparent parts of png files transparently.
As for the sprite ordering, this is difficult to advise without any knowledge of your game's code structure. You could give each sprite a Z-index, sort and draw in order.
This KineticModel creates multiple, translucent instances of GradientImage as part of a simulation.

OpenGL: Create a sky box?

I'm new to OpenGL. I'm using JOGL.
I would like to create a sky for my world that I can texture with clouds or stars. I'm not sure what the best way to do this is. My first instinct is to make a really big sphere with quadric orientation GLU_INSIDE, and texture that. Is there a better way?
A skybox is a pretty good way to go. You'll want to use a cube map for this. Basically, you render a cube around the camera and map a texture onto the inside of each face of the cube. I believe OpenGL may include this in its fixed function pipeline, but in case you're taking the shader approach (fixed function is deprecated anyway), you'll want to use cube map samplers (samplerCUBE in Cg, not sure about GLSL). When drawing the cube map, you also want to remove translation from the modelview matrix but keep the rotation (this causes the skybox to "follow" the camera but allows you to look around at different parts of the sky).
The best thing to do is actually draw the cube map after drawing all opaque objects. This may seem strange because by default the sky will block other objects, but you use the following trick (if using shaders) to avoid this: when writing the final output position in the vertex shader, instead of writing out .xyzw, write .xyww. This will force the sky to the far plane which causes it to be behind everything. The advantage to this is that there is absolutely 0 overdraw!
Yes.
Making a really big sphere has two major problems. First, you may encounter problems with clipping. The sky may disappear if it is outside of your far clipping distance. Additionally, objects that enter your sky box from a distance will visually pass through a very solid wall. Second, you are wasting a lot of polygons(and a lot of pain) for a very simple effect.
Most people actually use a small cube(Hence the name "Sky box"). You need to render the cube in the pre-pass with depth testing turned off. Thus, all objects will render on top of the cube regardless of their actual distance to you. Just make sure that the length of a side is greater than twice your near clipping distance, and you should be fine.
Spheres are nice to handle as they easily avoid distortions, corners etc. , which may be visible in some situations. Another possibility is a cylinder.
For a really high quality sky you can make a sky lighting simulation, setting the sphere colors depending on the time (=> sun position!) and direction, and add some clouds as 3D objects between the sky sphere and the view position.

Categories

Resources