I want to write a platform game, all I done before was puzzle games with no need of physics.
All I need is simple collision detection, what I will supply the physics engine is position of all objects and it should output:
All objects of a specific object type (bullets) that collide with any object (and what object), just a list of pairs.
For every object of a specific object type (players and npcs) if its on ground or in mid air.
All the simulation of move/speed/gravity/hits/reflections will be done using custom code because what I want to implement is a world with strange physics.
Should I roll my own engine? can I use existing ones like chipmunk/box2d? If I need to implement my own how will I make collision detection not a costly operation? (like a naive implementation of just checking everything in O(n^2).
I can use objective-c or c++, I would prefer c++ (it should have better performance).
If you are writing your own physics you probably want to include your own collision detection. There are also some publicly available free physics engines that you might try like bullet. (http://www.bulletphysics.org)
But you might want to just do a google search for collision detection algorithms that might apply to the kind of game you are making with the kinds of intersections you need to test for.
Here is an article I found at random: http://www.gamespp.com/algorithms/collisionDetection.html
For this kind of problem, I'd recommend you write your own library.
Yes, you can find this kind of feature in existing libraries, however you'll learn a lot more from writing your own.
I recommend looking into graph and tree data structures.
Related
We're currently using Matlab's fmincon function to do non-linear optimization for a project I'm working on. We need to port that part of the project to C++ in order to integrate it with other parts of the project. Is there a good way to compile the fmincon function into a library that we can use in C++? Or, is there already a library available somewhere that implements fmincon?
If neither of the above are an option, what optimization libraries are available that would be fairly easy to switch to from fmincon?
Background info:
We're trying to optimize a waypoint flight path of a UAV to follow a given waypoint camera path along the ground as closely as possible. The waypoints between the two paths correspond temporally, so the camera gimbal will be pointed at the i-th camera waypoint when the UAV arrives at the i-th flight path waypoint. The flight path segments will all be the same length since the UAV flies at a constant speed. The turn radius is also constrained by an upper bound. There are no constraints on the camera path, so its segments may be longer or shorter than the flight path segments and it may have sharp turns. The cost function is the sum-squared distance between corresponding flight waypoints and camera waypoints (ignoring altitude differences).
Most of the time, libraries out there won't try to be a black box magic one-size-fits-all optimization tool like fmincon is- instead they'll require you to provide more detail and make more choices on your own, which is simpler for them and should result in your software being faster. You can certainly use the MATLAB Engine or MATLAB Compiler to call fmincon from your program, but most likely your software will run a good deal faster (and you can avoid purchasing the MATLAB Compiler) if you can use a little more knowledge about the structure your optimization problem has and call an appropriate algorithm.
Your background info doesn't describe what you're doing - esp. what your feasible set is- clearly enough for me to be able to tell you what to use, so all I can do is point you in the direction of relevant resources.
Wikipedia's page on optimization links to lists of optimization software- most importantly, it describes more specific kinds of optimization problems (for instance, can you formulate your problem as quadratic programming with linear constraints?) and software appropriate for each situation.
Boyd's book on convex optimization and the linked course materials & videos are really good resources.
I am developing a 2D game with very large levels in which two teams(around 200 objects per team) fight against each other in planes, tanks, turrets,...etc. With every entity shooting bullets at their enemy it is expected that there would be a numerous amount of objects at one instant. What collision detection algorithm could I use to support collision for a massive number of entities? The objects are simple figures(rectangles and circles). Would a brute force approach suffice or break up the level into a grid?
Do not use brute force approach. You will very soon get into troubles with performance. There's plenty of papers and articles about this topic.
But unless you really want to implement your own solution, pick an existing collision/physics engine that can resolve this for you. You are making a 2D game, then the obvious choice is Box2D, which is ported to many platforms and used in many game engines and games (e.g. Angry Birds and its clones). Also this question is probably better suited for Game Development site as you are not really solving any specific programming problem.
Is there a pathfinding algorithm also suited for real 3D environments e.g. real Buildings with multiple stairs etc. A C++ library or open implementation would be splendid ;-)
One solution I saw was Djikstra but I wonder whether there is something more optimal.
Normal A* would not work better then Djikstra since the distance heuristic does not work well (Position one floor above destination).
Another solution that I'm currently pondering is the mapping of the 3d environment on a 2d graph. So if there is some available C++ implementation/library going this way it would be helpful too.
If the path has to take into account the ability to navigate through obstacles (i.e. the movement is that of some entity with known volume in space), then I'd recommend looking into the literature on robot motion planning. The notion of a configuration space allows you to handle changes in pose in order to deal with obstacles. See the classic textbook by Jean-Claude Latombe
For simpler scenarios, you can probably make do with path planning algorithms used in first person computer games, which are similar to Dijkstra, A* (example)
For an approximation algorithm you can easily map the 3d to a 1d curve and traverse an octree with a gray code. That way you can reorder each path. I don't know if there is a guarantee to be within the optimum solution but it must be better then any heuristic method.
I searched and I found some tutorials how to do terrain collision but they were using .raw files, I'm using .x. But, I think i can do same thing they did. They took x,y,z values of an object can checked it against every single triangle in the terrain. It makes sense but It look like it will be slow. It is just like picking checking against every single triangle is slow.
Is there faster way to do it and good?
UPDATE
My terrain is not flat, if it was i would use bounding boxes.
Last time I did this, I used the Bullet library, and it worked great. It has various collision shapes to choose from, optimised for different scenarios, including general triangle meshes and heightfields. You can use the library's collision routines without the physics.
One common way to significantly reduce the time it takes to detect collisions is to organize the space into an octree, which will allow you to very quickly determine whether or not a collision could occur in a particular node. Generally speaking, it's easier to accomplish these sorts of tasks with a game engine.
Does anyone have some useful beginner tutorials and code snippets for playing with basic geometric shapes and geometric proofs in code?
In particular something with the ability to easily create functions and recursively draw them on the screen. Additional requirements, but not absolute, support for Objective-C and basic window drawing routines for OS X and Cocoa.
A specific question how would one write a test to validate that a shape is in fact a square, triangle, etc. The idea being that you could draw a bunch of shapes, fit them together and test and analyze the emergent shape that arises from the set of sub shapes.
This is not a homework question. I am not in school. Just wanted to experiment with drawing code and geometry. And looking for an accessible way to play and experiment with shapes and geometry programming.
I am open to Java and Processing, or Actionscript/Haxe and Flash but would also like to use Objective C and Xcode to build projects as well.
What I am looking for are some clear tutorials to get me started down the path.
Some specific applications include clear examples of how to display for example parts of a Cantor Set, Mandelbrot Set, Julia set, etc...
One aside, I was reading on Wikipedia about the "Russell's Paradox". And the wiki article stated:
Let us call a set "abnormal" if it is
a member of itself, and "normal"
otherwise. For example, take the set
of all squares. That set is not itself
a square, and therefore is not a
member of the set of all squares. So
it is "normal". On the other hand, if
we take the complementary set that
contains all non-squares, that set is
itself not a square and so should be
one of its own members. It is
"abnormal".
The point about squares seems intuitively wrong to me. All the squares added together seem to imply a larger square. Obviously I get the larger paradox about sets. But what I am curious about is playing around with shapes in code and analyzing them empirically in code. So for example a potential routine might be draw four squares, put them together with no space between them, and analyze the dimensions and properties of the new shape that they make.
Perhaps even allowing free hand drawing with a mouse. But for now just drawing in code is fine.
If you're willing to use C++ I would recommend two libraries:
boost::GGL generic geometry library handles lots of geometric primitives such as polygons, lines, points, and so forth. It's still pretty new, but I have a feeling that it's going to be huge when it's officially added into boost.
CGAL, the Computational Geometry Algorithms Library: this thing is huge, and will do almost anything you'll ever need for geometry programming. It has very nice bindings for Qt as well if you're interested in doing some graphical stuff.
I guess OpenGL might not be the best starting point for this. It's quite low-level, and you will have to fight with unexpected behavior and actual driver issues. If you emphasize the "playing" part, go for Processing. It's a programming environment specifically designed to play with computer graphics.
However, if you really want to take the shape testing path, an in-depth study of computer vision algorithms in inevitable. On the other hand, if you just want to compare your shapes to a reference image, without rotation, scaling, or other distortions, the Visual Difference Predictor library might help you.
I highly recommend NeHe for any beginner OpenGL programmer, once you complete the first few tutorials you should be able to have fun with geometry any way you want.
Hope that helps