OL3 - ol.interaction.modify - showing labels during drag - openlayers-3

While modifying a feature with dragging (e.g. moving a point of a polygon), I would like to show the distances of the modified vertices. I intend to use an overlay with some div elements in the proper position on the map (much like the measure example: http://openlayers.org/en/v3.12.1/examples/measure.html?q=measure).
The things I think that are needed for this, is to attach to the proper events (modifystart, modifyend, change:geometry, ...), and being able to determine which vertices are being modified. For each vertex/segment, I can then put such a label on the map.
I would like to know what the best method is to achieve this (mainly to determine which vertices are being modified)? This seems difficult to achieve.
Some options I was investigating:
The easiest way would be to have access to the dragSegments_ member of the modify interaction. Sadly this seems not to be exposed from the API. For example it would have been nice if some modifydrag event existed, that contained this dragSegments_ collection. Or that this had been already a member of the existing ModifyEvent (not sure whether at the time the modifystart event is raised, this dragSegments_ collection is already filled in).
I know I can listen to the modifystart and modifyend event. This has a mapBrowserPointerEvent member, which I can use to know the coordinate of the mouse cursor. However, in that case I would have to write some logic to find all the segments matching that coordinate, of the features that are being modified. So in fact, I'm rewriting the same code as the modify interaction used to determine the dragSegments_ collection. And then have to hope that I end up with the same collection as the internal dragSegments_ (and keep this up-to-date with future OL3 code changes).
I can also listen to the change:geometry events of the features being modified. In that case I would have to scan the new geometry, and compare each point with the original version (store a copy when modification started), and see which coordinates changed. Not sure how good an approach this is (looks ugly at first sight to scan through all the points and compare them one-on-one).
Is there an elegant solution for this?

Related

How can I remove sprites when they are outside viewport, but then add them again if I return to their location to save memory

I'm creating an open-world RPG like Neverwinter nights. But I'm worried about memory and am afraid if I just populate a huge world with physics-based sprite nodes, I won't have any memory for anything else.
To combat this, I want to remove the sprites when they go far outside of the viewport and then re-add those sprites when I get close to their location.
How could I accomplish this?
To any and all who take time to help me with this, thank you!
You can store all data on a database like CoreData with exact parameters you need like states and positions whatever do you need.
Then you can create a method to get all objects on a specific position with radius and use this method when the player moves or when you need to check things like a quest on another site, take those objects and compare with current objects, place again on the correct site the new ones and remove the old ones (they are not on radius probably or disappears for another reason)
This is a complex approach but it could work.

how to allow an object to move through gaps in an skphysicsnode

I want to try to have a sprite kit node move through this image and when it contacts one of the blocks it executes a function and is blocked from moving forward, but it can pass through the gaps. The way my code is set up now however, the entire image is recognized as one node so nothing can pass through even the gaps. I was wondering if anyone had some suggestions on how to work around this without having to add each individual block as its own node. Thanks.
Sorry to disappoint you but what you want to do is not possible. I know of 2 ways to detect collisions.
1) through physics like you are already doing
2) through use of intersects(_:)
Both of them require you to have separate objects. Else how is the system supposed to know the difference between the space in-between the objects and the objects them selves. Your saying you want one massive object. Maybe you could write some great script that detects intersection of different colours, but that would be a really strange solution to a simple problem
Like Steve asked. Why do you not want to add them individually? It's really easy to do. Just create an instance of the object then add it multiple times with different positions. If you are not sure how to do this then, this is the question you need to be asking.

How to get a particular point of an detected object with ARKit

My question is about object detection and get a particular point from it.
For example, if I want to implement this, how would you tackle this?
You put a white paper in front of your camera and let it detect
it. As soon as that paper is detected, some action (like any action such as a node is produced somewhere in the screen) is triggered.
One solution that came through my head is to do some hit test, thinking it would give me a node position of a first detected by hit test. But it seems like it is not working as desired. I want to see a new node being created up above that paper, based on the position of the detected real object.
Is marker based detection is better for achieving this program, or is there any better solution to this?

how to generate Tetris piece from a given grid

At first I think my question should have been asked before, but I didn't find what I want.
One element of this iOS app I'm developing is break a 8x8 grid into Tetris pieces (every piece is made of 4 blocks). Two particular question I have are:
what is the best way to represent a Tetris piece in objective-C?
what algorithm to present the grid into random Tetris pieces (and later on how to check if two pieces fits together).
Edition on 01/28
#livingtech, I think I implemented pretty much what you say, except the point of "having a hole". My code works with no hole at simple stage when Tetris block is two blocks only (yes, two squares, connected either horizontally or vertically), but at 3-square Tetris block, I would get holes. I just tested and out of 1000 running, I would get one without a hole. So definitely I need some mechanism to check if next square will be a singleton.
I been trying to do the same thing for my game. Though I am a total beginner, and I'm using XNA and C#.
But the way I'm trying to go about it is: 4x6 grid array
--y123456
X1-000000
X2-000000
X3-000000
X4-000000
Here,
0 signifies no block
1 defines a block
Algorithm
Start by taking the very first 0 in the array ( top left corner )
and randomly pick a 0 or a 1.
Randomly choose the coordinates based on x1/x2-y1/y2, decide 1 or 0.
If it is 1, then decide coordinated based on where that 1 was put.
If it was 1 on x2 y1, then decide if a 1 should go on next touching
coordinate.
If you just have to code in what coordinates touch and which don't,
and the logic will roll through.
I have mine set up bit different. But this is the basic foundation of my random Tetris engine.
I also found that making it like that really helps to have a whiteboard and make a drawing of the grid and label with your coordinates.
since ur board is 8*8, i think u can use a int64 to represent the board. each bit of the int64 represents whether the specific grid is filled or not.
Implementing Tetris is a hobby of mine. First implemented it in Windows/C. Then in Perl/Tk! Last implementation I did in Obj-C/Cocoa (Mac). In all cases, the game logic is the same. Only the UI stuff changes. I treat every little box separately and have a two-dimensional array which contains the presence (and color) of every "set" box on the board. Standard board size I use is 10 boxes wide by 20 boxes high.
Separately I keep track of the "dropping" piece: it's location and what kind of piece it is. Based on a timer, try to make the piece drop. If any of the boxes where the "dropping" piece would drop is already set, then stop dropping the piece and add the piece boxes to the "set" part of the board. Create a new piece, and start over.
It may not be the best way to implement it, but it makes sense in my head. From a pure OO perspective, each shape of a dropping piece could be a subclass of a generic shape class. Override functions that check whether the shape can drop, the offsets of the individual boxes in the shape, etc.
I don't think anybody has taken a stab at your question #2 yet here, so I'm going to outline what I would do.
Setup:
You'll need to represent your grid as an array of some kind. At the very least, you'll want some kind of boolean values, to denote whether each coordinate in the grid is "occupied".
You'll need to keep track of the pieces on your grid. This could be another array, this time holding references to the four coordinates for each piece.
You'll need a variable or variables to keep track of a coordinate in your grid where you'll start filling in pieces, (I would probably populate these with a corner to start).
Set up a "pool" of all possible Tetris pieces and rotations. (You'll want to keep track of which ones you've already checked on every iteration outlined below.)
Iterate:
Get a random piece from your pool that will fit into your starting coordinate. (If you want to get fancy, you could be smart about which ones you choose, or you could just go totally random. As pieces don't fit, mark them checked, so you don't keep checking randomly forever. If you get to a point where you've checked all the pieces, you have a solution that doesn't work, either back up an iteration, or start over.)
Make sure the Tetris piece you selected didn't leave a "hole", or empty space with less than 4 squares. (I don't know your requirements for solving this problem, so I can't say whether you should focus on speed or ease of coding, but you may be able to skip this step if you want, and "brute force" the solution.)
"Place" the piece, by writing it to your piece array and marking the coordinates filled.
Check for "finished" condition, in which all your spaces are filled.
Pick a new coordinate in your grid and repeat #1. (I would pick an empty one next to the previous coordinate.)
If this actual yet, I wrote test tetris app on Objective-C few months ago https://github.com/SonnyBlack/Test-Demo-Tetris . I think my algorithm not very well, but it working. =)

simple shape recognition

I wanna achieve something that looks like the wizard's ability in the game Trine.
I want to create a game where the player uses the mouse to create certain objects, so i will need to compare the shape the player drew to a predefined shape of my own and check if its close.
I have no idea how to achieve this and where to look for, I assume it has something to do with shape recognition like in image processing and computer vision but it should be much simpler and work in real time.
does anyone have a clue how this can be done or where can i look for something like that?
Is this what you're going for? http://www.youtube.com/watch?v=7Zh79q_xvZw
I would start by researching gesture recognition. I think that's the phrase you need to get good info. http://en.wikipedia.org/wiki/Gesture_recognition
Also, sketch recognition: http://en.wikipedia.org/wiki/Sketch_recognition
Have a look at this question. What you are looking for in particular is on-line handwriting recognition, meaning that you follow every move of the user from beginning to end.
Now, you might want to simplify it a whole lot, so one way is defining 9 areas, like a 3x3 grid. Then convert the user's movement into a list of how the user moved through these grids (use thresholds to make sure it was in that area for a while). Now you will have an array like this: 1-1, 1-2, 2-2, 2-3 (meaning the user went from upper-left corner, the upper-middle, etc.)
This information is now fairly easy to match to a set of gestures. If it performs poorly, you can either make it more difficult and introduce a Hidden Markov Model, that will allow some mistakes in the gesture (but still matching the most likely one you have in your gesture set), or you could simply display the grid to the user, so that the user will learn the gestures like number codes.

Resources