I need to write a very simple 3D physics simulator in Java, cube and spheres bumping into each other, not much more. I've never did anything like that, where should I start? Any documentation on how it is done? any libraries I could re-use?
Physics for Game Programmers By Grant Palmer (not Java)
Phys2D (Java code)
Assuming you want to get started on how to do it, best way to start is with a Pen and Paper. Start defining focal points of your app (like the entities sphere, cube etc, rules like gravity, collision etc, decide hierarchy of objects etc..)
If you know how to do this, and want a primer on the technology side, Swing is a good option to make UIs in Java.
Also take a look here: http://www.myphysicslab.com/
NeHe's lesson 39 is a good starting point, it's in C++ but the theory is pretty easy to understand.
A nice java physics library is jmephysics (http://www.jmonkeyengine.com/jmeforum/index.php?topic=6459); it is quite easy to use and sits on top of ODE (http://www.ode.org/) and jmonkeyengine (http://www.jmonkeyengine.com) which gives you a scenegraph (http://en.wikipedia.org/wiki/Scene_graph), again something that you'll need for anything beyond a very simple 3d application.
I haven't used it for some time though, and see that they haven't released since late 2007 so not sure how active the community is now.
How about first defining a class for physical object? It has position, velocity, mass and maybe subclasses with other features like shape, elasticity etc.
Then create an universe (class) where to place these physical objects. Sounds like fun :)
If you all you need to simulate is spheres/circles and cubes then all you need is a bit of Vector math.
Eg to simulate a simple pool game each ball (sphere) would have a position, 3d linear velocity and 3d linear acceleration vector. Your simulation would involve many little frames which continually updates each and every ball. If two or more balls collide you simply sum the vectors and calculate the new velocities for all balls. If a ball hits a wall for instance all that is required is to flip the sign of the ball to have it bounce back...
If you want to do this from scratch, meaning coding your own physics engine, you'll have to know the ins and outs of the math behind to accomplish this. If you have a fairly good math background you'll have a headstart otherwise a steep learning curve is ahead.
You can start on this community forum to gather information on how things are done:
gamedev.net
Ofcourse you could use an opensource engine like Ogre if you don't want to code your own.
Check out bulletphysics. bulletphysics.com is the forum or check out the project on Sourceforge.
Related
Background information
In school we learned 2 languages, Java and Processing
I know that Java and Processing arent the best languages for programming games.
It doesnt cared me ^^ so i started to work on a simple pacman ...
Question 1
Is there something more effective than Sprites/BufferedImages ?
Question 2
For rendering and drawing huge maps, is there a method to do that ?
Normally it would lag when drawing it cause of all the images :)
But how i can render/draw large maps without any fps collapse?
Short answer: Don't bother optimizing before you have a problem.
Longer answer: The most efficient way to do this is by using a game development framework, which handles this kind of thing for you. But really, stick with what you're comfortable with until you actually have a reason to change.
Java and Processing are fine languages for game development. There was a game called Recluse a few years ago that did very well at Ludum Dare (a game programming competition), and it was done in Processing.
On the Java side, there are a ton of very popular game development frameworks. LibGDX is probably the most popular. In fact, the libGDX Jam just happened, and you can check that out for a bunch of examples of what's possible in Java game development. You might also want to check out JMonkeyEngine and LWJGL.
I would say this: program with whatever you're comfortable with. If you're comfortable with Processing and Java and using sprites and BufferedImages, then do that. Don't worry about efficiency until you actually have a problem.
Processing is a great language to make some simple games. Start with Pong and Space Invaders. When you're ready to "graduate" to more complicated games, then check out libGDX. Don't worry about making everything as efficient as possible- focus on finishing games, which is much harder.
You'll also find a very active community of Java game developers on JGO.
Good luck!
Is there something more effective than Sprites/BufferedImages ?
No, not at your level of programming experience.
For rendering and drawing huge maps, is there a method to do that ?
Tiles. Generally tiles are 256 x 256 pixel images of one section of the map. Like floor tiles, you place tiles together until you have a large enough graphic for your view. As the player moves, you add the tiles in the direction the player is moving and remove the tiles from where the player came.
Here's an introduction to creating a tile map engine.
I want to make an top-down RPG game, with multiplayer support for up to 4 players. I have no need for graphics right now, the map can be a black grid and the player a red dot.
The game features are:
A 10000*10000 map that will feature some treasure chests, which will give stat boost
each player will have the basic rpg stats(attk,def,speed,etc) which he should be able to divide 30 points on each of these before the game starts.
The players will move real time using the arrow keys.
Each player will have a visible field of view of 20*20.
If a player comes in proximity of 5*5 or closer to another player there will be a battle which will compare the stats along with some dice rolls.
The game must have a pause feature and also a lobby feature.
The game must be in Java
The reason i am asking is because i have very limited knowledge on the way of programming such a project, and the guides i have found on youtube mostly are two complicated because of graphics or do not support the multiplayer feature.
I would like if this community could give me some directions about how I should start this game, or better if they could give me the link to some internet tutorial/video or book that can teach me the things I need to finish this.
Thank you!
This video is how my good friend learned java development. Obviously you're not going to find any tutorial that follow your exact needs, but this one is semi-close. I believe it goes into networking later in the series. This video is also very good, but it is farther away from your specifications. Another, better thing you can do is follow simpler tutorials until you know what you are doing, then change the source around to fit your specifications.
Generally if you do not know any java at all, starting with a game like this is not a very good idea. But if you are very motivated, it can be done.
By the way, this broad type of question is not very well suited for a Q & A site like this, so expect downvotes from others unless you edit your question.
I would like to implement a visualisation of this video in Java as experience to help me understand all of the 'troubles' in creating visualisations. I have some experience in OpenGL, and a good understanding of how to handle the physics involved. However, if anybody knows of any good game engines that may help (or at least do some of the heavy lifting involved in creating a visualisation of the above) I would be grateful.
Also, I noticed that the linked video must use many separate jets in order to operate in the way it does. Is it likely that it was created using something a little lower level such as C? Is it possible to use a higher level language like Java to control such a system?
Honestly, if you want to implement "just that", I think using a game engine is overkill. Just implement a simple particle engine on your own and you are done.
Seriously, that problem is not so difficult, any language can be used for it. The basic principle behind it is the same as behind steam organs or self player pianos. You have an input data that shows what the pattern to play is and you advance it in a given time.
Here is how I would build the basic control system. You take a black and white image. The width is exactly as wide as the number of "emitters" and the length is as long as the pattern needs to be. You read the image and start at the first line. You walk through each pixel in that line and if the pixel is black you emit a drop and if the pixel is white you don't. You then move in a given interval (maybe 25ms) to the next line and set the emitters accordingly.
The cool thing with images is that you can simply paint them in any graphic program. To get the current time to work you render the time into a image buffer in memory, then pass that into the above code. (You even get fonts if you like...)
You can use jMonkeyEngine.
JAVA OPEN GL GAME ENGINE
I found this (you need Java to play with it) and since have been fascinated by cloth physics. I don't understand the logic behind the code at all though...is there any essential reading or resources for beginners?
Cloth physics is actually only spring physics, where each "point" of the cloth is connected to its immediate neighbors (usually in a square grid) by a spring.
Pulling on a point then stresses the springs surrounding that point, which stretch temporarily. As they retract, they accelerate the neighboring points, which then "pull" on their surrounding springs.
Here's another demo (demonstrating their spring library).
Look to this paper for some details.
It depends on how faithfully you want or need to represent the physics. All models represent a choice of features to include and omit.
Doing it properly means knowing a lot of physics fundamentals: continuum mechanics for large displacements and strains and a good material model for fabric. I'd recommend Malvern or Fung for the former and a literature search for the latter.
paper on mass spring system
Theres something called a mass spring system, I suggest you google it and work it out. It's basically based on beams and points. You have rectangles with points which are the corners and beams which are the lines connecting them. The points can be moved and the beams stretch but the beams can only stretch a certain amount, if they stretch too much they will break allowing the points to disconnect.
What should a small team choose for their first game, when they are low on time but have big ambitions? I'm an experienced programmer, but haven't done any game programming before this. My designer is very talented and artistic, he has worked with 3D about an year ago but hasn't done it since so it could take him some time to learn it again, and i'm not sure if he'll be able to do a good job at it even though his graphic design skills are terrific otherwise.
Our primary concern is to get the game finished as quickly as possible, and also to do it easily since this is my first game programming project. At the same time, we don't want to have any limitations that might hinder our progress later on, or otherwise make the game not fun in certain ways.
For example, i learnt that certain animations aren't possible in 2D such as rotation etc. I would like the ability to have the player's character be able to morph into animals and there must be the ability to shoot at the monsters, (like shooting an arrow and seeing it fly through and hit the other person). Are these things possible in 2D?
In the future, if we wanted to go from 3D to 2D, would it be possible without fully rewriting the game?
You don't have to use 3D to allow for a "3D look". Things like rotations, motions or transformations can be prerecorded or prerendered as animations or image sequences and seamlessly integrated into a 2D game.
The only thing that is not possible in 2D is to navigate freely within your "game space" (like walking or flying freely, turning arbitrarily etc.)
The main concern, however, when deciding for 2D or 3D should be the gameplay. There are games that absolutely need 3D (shooters, simulations), while others do perfectly without (adventures, puzzles, ...). So you don't actually have to decide but to choose the better fit for your game idea.
Personally, I'd avoid using 3D in your first game attempt if possible to eliminate all the constraints and hassles that come with it.
When using 3D you typically have to decide for a 3D framework which will heavily influence your software design, game look and feel and overall performance. Java3D for example brings a complicated class structure that you have to adjust to.
And a lot of effort goes into making that 3D stuff work at all. Simple things like rotating a square evolve into matrix operations incorporating quaternions. Every effect has to be done in the complex 3D world, and in such a way that its 2D projected look turns out the way you intended it.
Not to mention that 3D applications often suffer a very stereotypical look that is very hard to overcome.
In 2D, you literally avoid one dimension of complexity. You do everything exactly the way it is supposed to look, you can use standard graphic applications and open file formats to simplify the workflow between the designer and the developer. And a lot of pseudo-3D effects like parallax motion, depth of field and prerendered artwork allow for astonishing looks in a 2D world.
You should go 2D. You have stated several reasons to take this approach:
You are a small team, and 3D takes
more work.
It's your first game, so
you need to keep it as simple as
possible, or the project may fail
(you are exposed to a lot of risk!)
The 3D artist needs to relearn the
crafts!
You have a (seemingly
self-imposed) deadline.
Etc.
3D takes a lot of time, and it will be best invested in improving the rest of the game. Think of all the awesome games that existed previous to the 3D era.
Do not fear to accept restrictions: whilst 3D might give you lots of possibilities, 2D may result in more creative work!
I would considre a couple of factors:
Is it a mobile or applet game? If so, I would go for the 2D version. It's very hard to get 3D right under those circumstances.
What is your designer more comfortable with? Can he more quickly model, texture and animate a characte, rather than creating all the sprites needed for a 2D character?
Tool support. What output formats can your designer produce in both 2D and 3D? What kind of formats is the middle ware, you are going to use, able to handle? Can your 3D engine load, or at least convert, .obj files (just an example, could have used any other model format.)?
Even if you would like to go the 3D way, you can still make a 2D game (sometimes called 2.5D or pseudo 3D). Also there are some nice third party frameworks out there for both 2D and 3D stuff in Java. You don't have to use java2D/java3D.
Given your requirements, I'd choose 2D . You have more tools to choose from . more available talent to contract for artwork .. and the asset pipeline is simpler. In the end it's going to be all about how good the game is on its own merits. 3D is sometimes more difficult for your average user to figure out.
Depending on what you are conceptualizing, rotations and morphing oughta be quite possible in 2D. You might even consider a pseudo-3d approach ala Paper Mario ..
Moving from 2D to 3D should not be a major issue if you design your code structure with that in mind. ..
I would recommend 2D as well. A 3D game will be more graphically demanding on the user's computer, and many things like collision detection are significantly simpler in 2D. You could even make your character models in 3D and then project them down to 2D to make the sprites for the actual game. Puzzle Pirates (http://www.puzzlepirates.com/) takes this approach and it works very well in terms of consistent lighting, etc.
I think writing a 2D or a full 3D game needs a completely different design approach what cannot be modified easily later: SUN provides a Java 2D API and a Java 3D API for the two development decisions.
For the first game with tight deadline I would vote for a 2D version. If the gameplay is interesting and the design is nice then the 3D is not a must.