This is a Theoretical question about the use of classes, something which I haven't yet had too much experience. I just want some opinions about whether this would be the best way to go about programming for my task.
The goal of my project is to track objects that move across the frame of the camera, I have been able to detect the objects and store their centre point for each frame (note that this point is only stored until the next frame is read and new points are stored).
I am thinking of using a class store the previous positions of the objects as well as an ID of some kind so that I can differentiate the objects from each other.
Would this be over complicating things? or would it be better to simply store the history points into a basic array of points?
For some more insight, I will be tracking people from an overhead counter, so realistically there shouldn't be more than 15 objects present in the frame at one time. The images below show the detected heads and their centre points (these are the objects being tracked).
Related
I have a painting app which at any given time interactively shows content from an array of 200 or so CALayers via an UIImageView. I get reasonable performance, but I'm wondering if there could be any performance benefits with using CAMetalLayers instead. In particular, I'm curious if I could benefit from blitting textures directly to each CAMetalLayer, and would there be any hardware considerations with stacking/displaying so many CAMetalLayers at once.
Are there any gotchas I should consider before implementing, and should I continue using an UIImageView (or other) to host these newly Metal-backed sublayers? Any thoughts would be appreciated.
That’s not going to work. You should be keeping track of your stroke’s data. For example an array of points would be a single stroke and then you should have an array of those strokes. It could be only points (x, y) or more probably also containing color, size and other variables. You should know what do you need to describe your stroke.
Then use that to draw (stamp at those locations). When you want to undo, just start drawing from the beginning all the strokes in the array until n-1, n-2, etc...
I am trying to create multiple SKSpriteNodes that each have their own independent variables that I can change/modify. I would like to be able to run a function when the app starts, for example "createSprites(5)" which would create 5 sprites with the image/texture "shape.png" at random x and y coordinates and add all 5 Sprites to an array that I can access and edit different Sprite's positioning based on the index value. I would then like to be able to have another function "addSprite()" which, each time it is called, create a new Sprite with the same "shape.png" texture, place it at another random X and Y coordinate and also add it to the array of all Sprites to, again, be able to access later and change coordinates etc.
I have been looking through so many other Stack Overflow pages and can not seem to find a solution. My ideal solution would simply be the two functions I stated earlier. One to create an "n" number of Sprites and another function to create and add one more sprite to the array each time it is called.
Hope that makes sense, I'm fairly new to Swift and all this Sprite stuff, so simple informative answers would be very much appreciated.
You're not going to find an ideal solution from the past because nobody has likely had exactly the same desire with both Swift and SpriteKit. Having said that, there's likely partial answers you can blend together, and get the result you want or, at least, an understanding of how to do it.
Sprite Positioning in SK is probably the first thing to read up on:
https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Sprites/Sprites.html
having gotten that figured out, you can move to random positions.
Random positioning of Sprites:
Duplicate Sprite in Random Positions with SpriteKit
Sprite Kit random positions
Both use earlier versions of randomisation that aren't as powerful as what's available now, in GameplayKit. So... Generating random numbers in Swift with GameplayKit:
https://www.hackingwithswift.com/read/35/overview
It's hard to overstate the importance of understanding the various possibilities of game design implications of varying types of randomisation, so probably wise to read this, from Apple:
https://developer.apple.com/library/content/documentation/General/Conceptual/GameplayKit_Guide/RandomSources.html
After that, it's a case of needing to determine what constitutes a time or event at which to create more sprites at more random positions, and how fussy you want to be about proximity to other sprites, and overlaps.
I want to divide my map in clusters and implement HPA*. Where do I start, each time I try this I run into problems. I need to implement this on a random and dynamically changing map.
I am unsure how to write an algorithm that places these "nodes", to connect the parts, in between sections/clusters of the map and update them. I guess every time open tiles lie in between closed tiles on the edge of a cluster/section there should be a node since inside the cluster it could be that multiple openings into the cluster do not connect to each other within this section.
Normally I would just have a big Tile[,] map. I guess I could just leave this be and create a cluster/section class that holds all the paths and nodes. And have a node class/struct that holds the 2 tiles that are connected between sections. I have read several articles about HPA* but I just can not wrap my head around implementing this correctly on a random and dynamical map. I hope to get some good pointers here although the question is not very clear.
-edit-
What i am trying to do is making cluster class that holds 10x10 tiles/nodes with on each side an entry point (several if there is a obstruction on the edge). The entries link to the next cluster.
I'm interested in different algorithms people use to visualise millions of particles in a box. I know you can use Cloud-In-Cell, adaptive mesh, Kernel smoothing, nearest grid point methods etc to reduce the load in memory but there is very little documentation on how to do these things online.
i.e. I have array with:
x,y,z
1,2,3
4,5,6
6,7,8
xi,yi,zi
for i = 100 million for example. I don't want a package like Mayavi/Paraview to do it, I want to code this myself then load the decomposed matrix into Mayavi (rather than on-the-fly rendering) My poor 8Gb Macbook explodes if I try and use the particle positions. Any tutorials would be appreciated.
Analysing and creating visualisations for complex multi-dimensional data is complex. The best visualisation almost always depends on what the data is, and what relationships exists within the data. Of course, you are probably wanting to create visualisation of the data to show and explore relationships. Ultimately, this comes down to trying different posibilities.
My advice is to think about the data, and try to find sensible ways to slice up the dimensions. 3D plots, like surface plots or voxel renderings may be what you want. Personally, I prefer trying to find 2D representations, because they are easier to understand and to communicate to other people. Contour plots are great because they show 3D information in a 2D form. You can show a sequence of contour plots side by side, or in a timelapse to add a fourth dimension. There are also creative ways to use colour to add dimensions, while keeping the visualisation comprehensible -- which is the most important thing.
I see you want to write the code yourself. I understand that. Doing so will take a non-trivial effort, and afterwards, you might not have an effective visualisation. My advice is this: use a tool to help you prototype visualisations first! I've used gnuplot with some success, although I'm sure there are other options.
Once you have a good handle on the data, and how to communicate what it means, then you will be well positioned to code a good visualisation.
UPDATE
I'll offer a suggestion for the data you have described. It sounds as though you want/need a point density map. These are popular in geographical information systems, but have other uses. I haven't used one before, but the basic idea is to use a function to enstimate the density in a 3D space. The density becomes the fourth dimension. Something relatively simple, like the equation below, may be good enough.
The point density map might be easier to slice, summarise and render than the raw particle data.
The data I have analysed has been of a different nature, so I have not used this particular method before. Hopefully it proves helpful.
PS. I've just seen your comment below, and I'm not sure that this information will help you with that. However, I am posting my update anyway, just in case it is useful information.
I'm looking for articles on tile based games, like the old ultima 6&7, or even puzzle pirates. Specifically:
How they keep track of objects on the map. Objects such as other characters, or trees, or things the character can move.
AI behind the characters. How the game handles character behavior for
characters on the map that are off screen. Especially with very large maps and numerous characters.
I remember checking out Amit's Game Development page back when I wrote some games. He has a great sub-section on tiles that has most of what you want.
You could look through back issues of Game Developer magazine to see if something addresses what you're asking in detail.
For (1) the easiest way of dealing with a tile-based map where each tile can contain multiple objects is to just have a big multidimensional array of structs representing each tile. The struct contains a pointer to the head of a linked list representing all the objects in that tile. This is very memory efficient and lets you quickly find everything in a certain tile while also enumerating them along some other axis (eg, owner, allocation arena, etc).
RogueBasin is devoted to Rogue-like games (e.g. Rogue, NetHack, ). All of those games were based on a simple square grid. The site has an extensive section on developing games like that: http://roguebasin.roguelikedevelopment.org/index.php?title=Articles
You will find both suggestions and code there which could be used to build a game like you describe. After all, the only real difference between Rogue/Larn/NetHack/etc. and Diablo or the Ultima series is using simple text characters to depict the map and gameplay vs. isometric sprites.
In particular you will find information about calculating the area illuminated by a torch or lantern the user is carrying, data structures for storing maps, algorithms for automatic generation of maps, and lots of notes for how different games which have already been written chose to address these problems.
Check out Gamasutra. They have loads of articles for all kinds of game development.
The map would be an array of values. It could be divided into discrete parts. Only parts in range of the player would be loaded and the objects & npc in these parts active.
Since the old hardware had very limited memory and cpu, those games would only be able to load and process parts of the maps.