SpriteKit - Getting The Weight Of A SKSpriteNode - swift

I have an app with large boxes falling on top of the small red box. I would like to know when the small red block reaches a certain weight (X blocks are resting on top of it). I couldn't find a weight property for the red block. Any suggestions?
EDIT: Just to clarify. The boxes falling from the top will be random sizes, and falling from random positions. So there isn't really a way to keeping track of what landed on top of the red block. I need some way to measure the downward force being applied to the red block

You can calculate the weight for each node the following way and then add them together.
redBox.PhysicsBody?.mass

Related

How to perform matching of markers from two images which are taken from different perspective?

I have a markered robot with circular markers and two images from different perspective as shown: (Circular white rings are the markers)
I want to match the markers in the two images, by matching I mean the bottommost marker of 1st image should be treated as correspondence point of bottom most marker of 2nd image and so on.
The finger-like robot given in the image can bend in any direction given in space (can also bend in a U-like manner).
If it helps, the camera geometry is fixed and known beforehand.
I am lost, as simple correspondence algorithm would not work, since the perspectives are very different. How should I go about matching the two images?
You can start like this:
You know the position of the mounting point on the base panel for each perspective.
You know the positions of the white rings for each perspective as discussed here.
You can derive the direction of the arm at each ring by its tilt.
So you can easily determine the sequence of the positions starting with the mounting point stepping from ring to ring even if the arm is bent. With this you can match the rings from both images. If you have any situation where this fails, please add an according example to your question!
Unfortunately, you don't have matching points but matching curves. You might try to fit ellipses on the rings and take the ellipse centers for points to be matched.
This is an approximation, as the center of a circle does not exactly project as the center of the ellipse, but I don't think that this will be the major source of error: as you only see half circles, the fitting will not be that accurate.
If all nine circles remain visible and are ordered vertically, the matching of the centers is trivial. If they are not ordered but don't form a loop, you can probably start from the lowest and follow the chain of nearest neighbors.

Fastest way to determine line of sight on a grid

I am improving a video game of mine where I currently have the problem that NPCs can shoot through walls. In order to fix this issue, I have decided to completely re-do my work regarding ground combat.
I use a tight grid for finding paths from any point A to B. I store my grid as an image-like structure and use Jump Point Search for the pathfinding itself. My goal is to find a location that is as far away from the enemy as possible (limited by the firearms's range) that also has a direct line of sight to the enemy.
In my latest approach, I determined all nodes in my grid that are within weapon range and that are connected to the enemy's location (colored in green in the image below). The final missing part is filtering these points so that only the points with a valid line of sight remain.
I can also detect the border lines (colored in blue) very fast. I could check for every node, if a line from this node to the enemy would intersect any border line. If that is not the case, I have clear line of sight. However, I assume this to be neither fast nor the optimal solution.
Do you have any ideas or suggestions? I am glad for any hint!
I visualized the grid in the following image to give you an idea of what I am talking about. If a character would stand in the lower right green area, he could not shoot the enemy in the upper left area because of missing line of sight.

How to create a SKPhysicsBody in a shape of a parabola?

I need to create a SKSpriteNode or a SKShapeNode such that it would look like the image below. I can figure out how to use a texture to get the shape of the line but I can't seem to find a way to make the physics body. It needs to be made out of two horizontal lines which can change their y position and the middle parabola-like shape joins the other two lines with a specified maximum point (the maximum would hopefully be a variable).
(Note:- the blue and green lines are just to highlight that the image is compromised of three objects)
Is this possible? Thanks!

Weird Lines 3D Unity

I'm working on a project, using unity 5.4.
In this projects blocks are stacked next to eachother.
However there appear some annoying weird lines. Also on android these
line occur more often than on PC.
For illustration purposes I added an image and video.
Please zoom in on the picture to see, the line I'm speaking of, clearly.
Could anyone please provide a solution to get red of this nuissance.
Thanks in advance.
Literature:
Block alignment code snippet:
for (int x = 0; x < xSize; x++)
for (int z = 0; z < zSize; z++)
{
Vector3 pos = new Vector3(x, -layerDepth, z);
InstantiateBlock(pos);
}
Video link: https://youtu.be/5wN1Wn51d_Y
You have object seams!
This occurs when there is a physical or perceived gap between objects.
There are multiple causes for this.
1. Floating Point Imprecision
This could be because you are setting the position of the cubes to int's but they have floating point dimensions. The symptom for this is usually no white seams when the camera is close to the objects, and then they gradually appear as you get further away due to floating point imprecision. More.
Most of these blocks appear to line up exactly, from most camera positions. But from the occasional unfortunate position, the exact value for A's position plus its vertex at (0.5,0.5,-0.5) might be slightly different to object B's position plus its vertex at (-0.5,0.5,-0.5) . The result is that Unity shows a tiny gap, within which you can see the shadowed side of cube A.
If you consider the following on paper 3 == 1/3 * 3 this is mathematically correct, however using floats, 1/3 == 0.333333... and subsequently 3 * 0.333333... == 0.999999... BINGO! random gap between objects!
So how to solve? Use floats to calculate the positions of your objects. new vector3(1,1,1); should be new vector3(1f,1f,1f); - for example. For further reading on this try this SOP.
2. Texture Wrap-mode
If you are using textures on your objects, try changing the Wrap-Mode of your texture from wrap to clamp, or try upping the texture padding.
3. Shadow Acne - (Lighting and Shadow artifacts)
This is the arbitrary patterns of pixels in shadow when they should really be lit or NOT lit.
To prevent shadow acne, a Bias value can be added to the distance in the shadow map to ensure that pixels on the borderline definitely pass the comparison as they should, or to ensure that while rendering into the shadow map. source.
In Unity... go to your light source and then increase the Shadow Type > shadow Bias I would suggest doubling the default value of 0.05 and then continue so until fixed. You don't want to crank this value to max because...
Do not set the Bias value too high, because areas around a shadow near the GameObject casting it are sometimes falsely illuminated. This results in a disconnected shadow, making the GameObject look as if it is flying above the ground.
Are you using different blocks that you put against eachother? Your problem sounds like the blocks are not completely against eachother which causes you to see the side of the next block (this explains the camera Y changing: you might see the side better from higher up). That side will have different lighting and appear as a different/lighter colour. To check if this is the problem, try overlapping them slightly manually in the editor and see if the problem still occurs.
Making the blocks kinematic solves that. The issue is the rigid bodies bumping up against one another.

Circle with different colors

I am new to Iphone. I want to draw a circle with different colors in it. And all the colors should cover equal area. Like if I want to have 10 different colors in it. Then each color should cover 1/10th area of the circle. I am not trying to draw a pie chart here. Also not trying to use 10 different colors. Just want 10 equal parts of circle and each part can be filled with colors.
I am trying to build a fortune wheel. Such that a smaller wheel is above the larger wheel. And then I want to drag them separately.
Also is it possible to do this with help of Core Animation?
Ambiguous question. If you draw a piechart with 10 equal areas then each will cover 1/10th of the area, thus fulfilling your request, no?
There are 360° in a circle, so divide that by 10 and each wedge should have a 36°. Now you just have to draw 10 wedges, and this page should help you:
http://www.raywenderlich.com/2106/core-graphics-101-arcs-and-paths
Since you say you don't want pie slices, do you want concentric rings instead?
And are you sure you want equal AREA? That will make the rings different thicknesses. The innermost ring will be fairly thick, and each ring as you go outward will be thinner. Much thinner, on the outer rings.
Our eyes are used to a bulls-eye formation, where each ring is the same thickness.
In any case, you should look at CAShapeLayer objects. You can create a shape layer for each ring that defines a closed path with 2 circles. There is something called the "winding rule" that lets you determine what happens when paths overlap. I think you'd want even-odd path winding (kCAFillRuleEvenOdd).
To make the rings equal area, you could do this:
First calculate the area of the whole circle. Divide by the number of rings. That's the desired area for each ring Let's call that area "a". Start from the center. The radius of that ring (a circle) will be sqrt(pi/a).
For each following ring you'll need to calculate the thickness of the ring based on the area of the outer circle minus the area of the inner circle that makes up the ring. You'll need to write an equation that solves for the outer radius given the desired area and the radius or the previous circle.