I am trying to create a simple Flappy Bird clone but in my own way ( so it's not a complete clone ).
However I am having problems applying a constant downwards acceleration to the Bird. When I create a World it says that it gets a gravity variable but that's not gravity I think ? It should say something like velocity because that is all it does. My Bird is falling downwards at a constant speed. And I believe most of you know how gravity works. When I use functions like applyForceTo I basically get the same.
I have already my own simple implementation of gravity but I wanna use libGDX to its fullest and practice with it.
I found the answer myself and the solution is pretty simple. The objects I render, the whole "System" is way too big for Box2D and its properties to make any difference on the display. Everything accelerates accordingly but you can't see it. So I scaled down every object so it had properties of a couple of pixels and adjusted the camera. Now I can get very high accelerations and velocitys.
Related
Similar to the game Factorio im trying to create "3D" terrain but of course in 2D Factorio seems to do this very well, creating terrain that looks like this
Where you can see edges of terrain and its very clearly curved. In my own 2D game Ive been trying to think of how to do the same thing, but all the ways I can think of seem to be slow or CPU intensive. Currently my terrain looks like this:
Simply 2D quads textured and drawn on screen, each quad is 16x16 (except the water thats technically a background but its not important now), How could I even begin to change my terrain to look more like a Factorio or other "2.5D" games, do they simply use different textures and check where the tile would be relative to other tiles? Or do they take a different approach?
Thanks in advance for your help!
I am a Factorio dev but I have not done this, so I can only tell you what I know generally.
There is a basic way to do it and then there are optional improvements.
Either way you will need two things
Set of textures for every situation you want to handle
Set of rules "local topology -> texture"
So you have your 2d tile map, and you move a window across it and whenever it matches a pattern, you apply an appropriate texture.
You probably wouldn't want to do that on the run in every tick, but rather calculate it all when you generate the map (or map segment - Factorio generates new areas when needed).
I will be using your picture and my imba ms paint skills to demonstrate.
This is an example of such rule. Green is land, blue is water, grey is "I don't care".
In reality you will need a lot of such rules to cover all cases (100+ I believe).
In your case, this rule would apply at the two highlighted spots.
This is all you need to have a working generator.
There is one decision that you need to make here. As you can see, the shoreline runs inside the tile, not between tiles. So you need to chose whether it will run through the last land tile, or the last water tile. The picture can therefore be a result of these two maps (my template example would be from the left one):
Both choices are ok. In fact, Factorio switched from the "shoreline on land" on the left to the "shoreline on water" on the right quite recently. Just keep in mind that you will need to adjust the walking/pathfinding to account for this.
Now note that the two areas matched by the one pattern in the example look different. This can be a result of two possible improvements that make the result nicer.
First is that for one case you can have more different textures and pick a random one. You will need to keep that choice in the game save so that it looks the same after load.
Another one is more advanced. While the basic algorithm can already give you pretty good results, there are things it can't do.
You can use larger templates and larger textures that span over several tiles. That way you can draw larger compact pieces of the terrain without being limited by the fact that all the tiles need to be connectable to all (valid) others.
The example you provided are still 2D textures (technically). But since the textures themselves are 'fancy 3D', they appear to be 3D/2D angled.
So your best bet would be to upgrade your textures. (and add shadow to entities for extra depth).
Edit:
The edges you asked about are probably layed-out by checking if a 'tile' is an edge, and if so it adds an edge-texture on top the background. While the actual tile itself is also a flat image (just like the water). Add some shadow afterwards and the 3D illusion is complete.
I hope this answers your question, otherwise feel free to ask clarification.
Lets assume your eye is in the surface point P1 on an object A and there is a target object B and there is a point-light source behind object B.
Question: am i right if i look to the light source and say "i am in a shadow" if i cannot see the light because of object B ?. Then i flag that point of object A as "one of the shadow points of B on A" .
If this is true, then can we build a "shadow geometry"(black-colored) object on the surface of A then change it constantly because of motion of light,B,A, etc... in realtime ? Lets say a sphere(A) has 1000 vertices and other sphere (B)has 1000 vertices too, so does this mean 1 milion comparations? (is shadowing, O(N^2) (time) complexity?). I am not sure about the complexity becuse the changing the P1(eye) also changes the seen point of B (between P1 and light source point). What about the second-order shadows and higher (such as lights being reflecting between two objects many times) ?
I am using java-3D now but it doesnt have shadow capabilities so i think of moving to other java-compatible libraries.
Thanks.
Edit: i need to disable the "camera" when moving the camera to build that shadow. How can i do this? Does this decrease the performance badly?
New idea: java3D has built-in collision detection. I will create lines(invisible) from light to target polygon-vertex then check for a collision from another object. If collision occurs, add that vertex corrd. to the shadow list but this would work only for point-lights :( .
Anyone who supplys with a real shade library for java3d, will be much helpful.
Very small sample Geomlib shadow/raytracing in java3D would be the best
Ray-tracing example maybe?
I know this is a little hard but could have been tried by at least a hundred people.
Thanks.
Shadows is probably the most complex topic in 3D graphics programming, and there are many approaches, but the best option should be identified according to the task requirements. The algorithm you are talking about is the simplest way to implement shadows from a spot light source onto the plane. It should not be done on the CPU, as you already use GPU for 3D rendering.
Basically the approach is to render the same object twice: once from the camera view point, and once from the light source point. You will need to prepare model view matrices to convert between these two views. Once you render the object from the light point, you get the depth map, in which each point lies closest to the light source. Then, for each pixel of the normal rendering, you should convert its 3D coordinates into the previous view, and check against the corresponding depth value. This essentially gives you a way to tell which pixels are covered by shadow.
The performance impact comes from rendering the same object twice. If your task doesn't assume high scalability of shadow casting solution, then it might be a way to go.
A number of relevant questions:
How Do I Create Cheap Shadows In OpenGL?
Is there an easy way to get shadows in OpenGL?
What is the simplest method for rendering shadows on a scene in OpenGL?
Your approach can be summarised like this:
foreach (point p to be shaded) {
foreach (light) {
if (light is visible from p)
// p is lit by that light
else
// p is in shadow
}
}
The funny fact is that's how real-time shadows are done today on the GPU.
However it's not trivial for this to work efficiently. Rendering the scene is a streamlined process, triangle-by-triangle. It would be very cumbersome if for every single point (pixel, fragment) in every single triangle you'd need to consider all other triangles in other to check for ray intersection.
So how to do that efficiently? Answer: Reverse the process.
There's a lot fewer lights than pixels on the scene, usually. Let's take advantage of this fact and do some preprocessing:
// preprocess
foreach (light) {
// find all pixels p on the scene reachable from the light
}
// then render the whole scene...
foreach (point p to be shaded) {
foreach (light) {
// simply look up into what was calculated before...
if (p is visible by the light)
// p is lit
else
// p is in shadow
}
}
That seems a lot faster... But two problems remain:
how to find all pixels visible by the light?
how to make them accessible quickly for lookup during rendering?
There's the tricky part:
In order to find all points visible by a light, place a camera there and render the whole scene! Depth test will reject the invisible points.
To make this result accessible later, save it as a texture and use that texture for lookup during the actual rendering stage.
This technique is called Shadow Mapping, and the texture with pixels visible from a light is called a Shadow Map. For a more detailed explanation, see for example the Wikipedia article.
Basically yes, your approach will produce shadows. But doing it point by point is not feasible performance wise (for realtime), unless its done at the GPU. I'm not familiar with what the API's offer today, but I'm sure any recent engine will offer some shadow out of the box.
Your 'New idea' is how shadows were implemented back in the days when rendering was still done with the CPU. If the number of polygons isn't too big (or you can efficently reject entire bunches by having grouping volumes etc.) it can be done with fairly little CPU power.
3D shadow rendering on vanilla Java is never going to be efficient. You best use graphical libraries written to utilize the full capabilities range of the graphical card, such as OpenGL or DirectX. As you are using Canvas (from the screenshot you provided), you can even paint that Canvas from native code using JNI. So you could use all the technology from graphial libraries, do just a little fiddling and paint your Canvas directly from the native code. There would be very little work involved to make it work, compared to writing your own 3D engine.
Wiki link about AWT native access: http://en.wikipedia.org/wiki/Java_AWT_Native_Interface
Documentation: http://docs.oracle.com/javase/7/docs/technotes/guides/awt/AWT_Native_Interface.html
I have an object that continuously follows the users touch coordinates. I would like to make it so the object has an easing effect.
by which i mean, the object has a start point and when the user touches the screen, said object would move to the users touch coordinates. which it already does but it jumps to the coordinates. i want a controlled transistion from point A to point B.
this easing or tween affect would need to happen on every frame if the user dragged or swipped their touch coordinates.
i have been reading about interpolation and animation affects for the android sdk but i dont really understand how to implement them on an object and not a view. or continuously as well.
any direction would be great. thank you!
I built a complete tweening engine for Java. It doesn't allocate anything dynamically so it's totally safe for Android (I made it primarily to develop games on Android).
http://code.google.com/p/java-universal-tween-engine/
Your tween would look like:
Tween.to(yourObject, Type.POSITION, 1000)
.target(touchX, touchY)
.ease(Quad.OUT)
.start(aManager);
I used a similar syntax as the TweenMax engine, so you shouldn't be lost too long :)
I am trying to code a cessna flying around the world using the accelerometer with the min3D framework for android but the rotation is a bit weird.
I'm using this to apply the accelerometer rotation to the object:
cessna.rotation().x = rotX;
cessna.rotation().z = rotZ;
This works fine. I haven't figured out yet how to move in the direction of rotation (I think I have to use trigonometry).
I rotated the object with
cessna.rotation().y++;
just to test what will happen. At 180° the rotation around the x axis is mirrored. So the nose of the plane turns down instead of up.
I think I rotate the Objects around the world axis and not around the local axis from the object. How can I do this? I didn't find any documentation about the min3D framework in the internet :/ .
Thank you if you can help me.
(sorry for the bad English)
If you want to rotate around object local axis. Do this
(in pseudo code - you'll need to find similar functions in min3d)
Translate(object.pos.x,object.pos.y,object.pos.z);
object.rotation().x+=radians(45);// or whatever
if that doesn't work, try wrapping the above two lines in
pushMatrix()
...
popMatrix()
Or similar functions in min 3d to save and then restore the current camera rotation translation matrix.
Have you considered, Processing, which also comes with an Android 'output'?
I'm using jMonkeyEngine to develop a desktop PC game. It's still in early stages (always starting, never finishing, eh?).
With no physics (just moving the camera), faces disappear when you enter the inside of a Geometry model. So my question is, how do you apply a Material (texture) to the inside of a mesh?
Have a look at this: material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
This should show the texture on both sides. If you need the material only on the inside of your mesh, use FaceCullMode.Front, although in that case you should probably redefine your mesh instead so that its normals are pointing inwards.
Since most meshes don't have an 'inside' you can't do it with the same geometry, a good workaround that worked for me was to use a clone of the mesh but with a negative size though this only works for symmetrical meshes.