What things can I do when it's necessary to show many objects and calculate position, collision detection, reaction, etc. and I want everything look smoothly? Here's an example I'm developing. I want that if I have 100 balls on the screen, I can show them smoothly. But I don't have any idea of how to do it. Every suggestion will be appreciated.
The basic steps to improve performance in canvas can be seen in this HTML5 Rock's Canvas Performance Tutorial.
And, if you are free to handle collision detection without Box2D, check this quad-tree implementation. The quad-tree doesn't deals with collisions directly but can improve performance by reducing the amount of comparisons needed to detect the collisions.
Articles suggestion for further reading:
Broad Phase Collision Detection Using Spatial Partitioning
Collision Detection and Response
Making Games With Box2dWeb
I see you're using box2d--an excellent and mature physics library. Good choice!
Box2d is fairly well optimized already...and a lot of eyeballs have looked at the code to search for further optimizations.
Therefore (if your design needs permit), your path to improvement is replacing this large library with simpler collision functions.
Check out this set of video tutorials. Ignore the fact it targets processingJS, it still provides a good tutorial on game physics and handling collisions. Skip to the second link if you are already good on physics basics:
Tutorial "home":
http://channel9.msdn.com/Series/Sketchbooktutorial
Tutorial chapter on collision of circular objects:
http://channel9.msdn.com/Series/Sketchbooktutorial/Simple-Collision-Detection-and-Response
Related
Let me begin by saying that I am struggling to understand what is going on in deep learning. From what I gather, it is an approach to try to have a computer engineer different layers of representations and features to enable it learn stuff on its own. SIFT seems to be a common way to sort of detect things by tagging and hunting for scale invariant things in some representation. Again I am completely stupid and in awe and wonder about how this magic is achieved. How does one have a computer do this by itself? I have looked at this paper https://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf and I must say at this point I think it is magic. Can somebody help me distill the main points of how this works and why a computer can do it on its own?
SIFT and CNN are both methods to extract features from images in different ways and outputs.
SIFT/SURF/ORB or any similar feature extraction algorithms are "Hand-made" feature extraction algorithms. It means, independent from the real world cases, they are aiming to extract some meaningful features. This approach has some advantages and disadvantages.
Advantages :
You don't have to care about input image conditions and probably you don't need any pre-processing step to extract those features.
You can directly get SIFT implementation and integrate it to your application
With GPU based implementations (i.e. GPU-SIFT), you can achieve high inference speed.
Disadvantages:
It has limitation about finding the features. You will have trouble about getting features over quite plain surfaces.
SIFT/SURF/ORB cannot solve all problems that requires feature classification / matching. Think face recognition problem. Do you think that extracting & classifying SIFT features over face will be enough to recognize people?
Those are hand-made feature extraction techniques, they cannot be improved over time (of course unless a better technique is being introduced)
Developing such a feature extraction technique requires a lot of research work
In the other hand, in deep learning, you can start analyzing much complex features which are impossible by human to recognize. CNNs are perfect approach as today to analyze hierarchical filter responses and much complex features which are created by combining those filter responses (going deeper).
The main power of CNNs are coming from not extracting features by hand. We only define "how" PC has to look for features. Of course this method has some pros and cons too.
Advantages :
More data, better success! It is all depending on data. If you have enough data to explain your case, DL outperforms hand-made feature extraction techniques.
As soon as you extract the features from image, you can use it for many purposes like to segment image, to create description words, to detect objects inside image, to recognize them. The better part is, all of them can be obtained in one shot, rather than complex sequential processes.
Disadvantages:
You need data. Probably a lot.
It is better to use supervised or reinforcement learning methods in these days. As unsupervised learning is still not good enough yet.
It takes time and resource to train a good neural net. A complex hierarchy like Google Inception took 2 weeks to be trained on 8 GPU server rack. Of course not all the networks are so hard to train.
It has some learning curve. You don't have to know how SIFT is working to use it for your application but you have to know how CNNs are working to use them in your custom purposes.
Allow me to explain, so that this doesn't just get marked as an "opinion-based" question.
I'm learning processing.js right now, and I can't help but notice many of the similarities in functionality with what already exists in the Canvas API of Vanilla-JS. Perhaps writing a set of large-scale animations is much more complicated in plain old Canvas than it is in processing?
I'm asking this because, as I continue to learn more about the vanilla APIs, I'm seeing a lot of new functionality added in JS over the years that is starting to (VERY SLOWLY) make certain aspects of popular frameworks, no longer necessary (jQuery being a great example). I'm curious as to whether or not this is the case with Canvas and processing.js as well.
Personally, I'm trying to determine whether or not I should still be spending a lot of time in processing.js (I'm not asking you to make that decision for me though, but I just want some information that can help me decide what's best for me).
Stackoverflow allows specific non-coding questions about programming tools-like ProcessingJS, but your question seems likely to be closed as too broad.
Even so, here are my thoughts...
Native Canvas versus ProcessingJS
Html5 canvas was born with a rich set of possibilities rivaling Photoshop itself. However, native canvas is a relatively low-level tool where you must handle structuring, eventing, serialization and animation with your own code.
ProcessingJS adds structure, eventing, serialization, animation & many (amazing!) mathematical functions to native canvas. IMHO, ProcessingJS is a higher-level tool that's well worth learning.
Extending native canvas into a higher level tool instead of a low-level tool
With about 500 lines of javascript, you can add a reusable framework to native canvas that adds these features in within a higher level structure: eventing (including drag/drop, scaling, rotating, hit testing, etc), serialization / deserialization.
With about 100 more lines you can add a reusable framework to native canvas that does animation with easing.
Even though native canvas was born with most of the capabilities needed to present even complex content, a PathObject is sorely needed in native canvas. The PathObject would serialize paths to make them reusable. With about 50 lines you can create a reusable PathObject.
Here's a fairly useless recommendation :-p
Try to use the right tool for the job (yeah, not specifically helpful).
Learning native canvas alone will let you do, maybe 70% of pixel display tasks.
Coding the extensions (above) will get you to 90%.
Using a tool like ProcessingJS will get you to 98%.
Yes, there are always about 2% edge cases where you either "can't get there" or must reduce your design requirements to accommodate coding limitations.
A slightly more specific recommendation
Since ProcessingJS merely extends native canvas, IMHO it's well worthwhile to take a few days and learn native canvas. This knowledge will let you determine the right tool for the job.
I am in planning of developing HTML5-Canvas based cross platform game targeting Android and iPhone platforms using Box2D js framework. My game contains some of good physics moves, thus I chose Box2D JS(http://box2d-js.sourceforge.net/).
So, I recently ran some of Box2D HTML examples (http://box2d-javascript-fun.appspot.com/) in my android phone/android tablet. I really felt low performance of these pages while running basic physics moves.
Can anyone suggest how to resolve it?
Can anyone suggest other engines that can provide good performance which must have applied physics moves like Box2D?
P.S.: My Android tablet is having 1 GHz of processor and 512 MB of RAM. While i was running above pages, almost 240 MB was free.
Yes, canvas really does have poorer performance on mobile devices -- so box2d will also be slower.
Within box2dJS, you can adjust the timing-interval and resolution-iterations to adapt to the slower mobile devices. Adjusting the timing-interval will cause the game to animate faster or slower. Adjusting the resolution iterations will cause the game to be more/less accurate with it's physics. Perhaps you can "fine-tune" box2d and still use it.
I recommend tuning rather than abandoning box2d. Games like Angry Birds use the box2d physics engine and run well on mobile devices. So efficient programming makes box2d perform well (and poor programming can make box2d perform poorly).
More to your question, though: Matt Greer did some testing of physics engines last month and his results are here: http://buildnewgames.com/game-engine-comparison/
And finally, if you don't need the more advanced physics like restitution and friction, you might just "roll your own"! You can pull the matrix transform and collision code out of one of the many open-source physics engines and the hard part is done for you. In addition to learning how they optimized performance, you will end up with a small & fast physics engine that is tuned to your exact needs.
I'm working on a game coded in AS3 using the Alternativa3D 7.8 engine and it just doesn't have the FPS I was hoping to achieve with it and I'm trying to fully understand why. I get it that having 3D objects in a scene can be very taxing on performance but I'm using only a very limited number of 3d objects and each of those has a relatively small polygon count.
I'm wondering if there is something else like a memory leak causing this on top of the actual rendering of the scene.
I'd like to figure out a way to view how the performance is being distributed in my code to see if there are certain areas that are causing this. I usually only get about 10-15 FPS on my computer and I'd like to get that to around a constant 20-24 or higher if possible.
I don't think that this question should be downvoted necessarily, though it is a bit broad. OP is asking about general performance tips for AS3 applications.
It's true that we can't give him specific pointers without seeing his code, but we could still provide him with more general tips/tricks. Here's some analysis, pretty general:
I don't think your performance problems necessarily have anything to do with your 3D, though they might. The instant the game world comes on screen even the mouse movement is tremendously slowed, whereas the instant I pause it the framerate improves - which suggests to me that you are doing a lot of iteration and calculation on every frame.
I'd start with this: do you have any computationally intensive loops going on inside of your main game loop? For instance, I see that you're working with sea level as it effects landmass - are you doing something like calculating all of your water properties on every frame?
Having a lot of "3D" objects isn't necessarily a problem, because a 3D object is just a set of points. They're more intensive to position than 2d objects because you're including an additional dimension, but not so much more intensive that a few 3d objects would cause this kind of performance. I don't think that they are your problem (though I could be wrong).
Rather, it's what kind of calculations you're performing. Look for loops, figure out what you can comment out and instantly see better performance, and then once you've isolated it see what you can do about caching the outputs of those computations so that you don't have to recalc them on every frame.
Cheers,
mb
Along with all buzz talks about the wonderful Bumptop desktop environment, Im getting this question now. What is the relation with Physics and Bumptop techniques. Basically, I am interested in learning the techniques/algorithms followed in this desktop environment. For example,
Collision Detection -- is used when one icon is about to collide on other one.
Any other known techniques?
It probably uses a quite common rigid body dynamics simulator as used in (simple/older) computer games. If you want to play with one yourself, have a look at Open Dynamics Engine.
I'd say that it uses mechanics (the branch of physics that describes motion) to determine/calculate the outcome of object interaction.
I remember seeing a very early demo of this months ago - it looks very impressive!
Well, it looks as though it's using friction and velocity as well. The friction slows the animations down - if it didn't then things would just fly out of the way. Velocity is used to have things move at speed in certain directions.
More info here
BumpTop
Extensive use of physics effects like
bumping and tossing is applied to
documents when they interact, for a
more realistic experience.