Draw isometric map based on heightmap - draw

I am not able to get my head arround my problem triyng for two days now. The highly rated answer on stackoverflow did not help me. I am remaking an game which uses an isometric view. I generated a 2D heightmap matrix that i now want to draw using different tiles. Should the numbers in the array represent the edges or tiles? How to i iterate over my array? I am stuck.
These are the tiles to simulate height, they have different sizes.

Related

Detect coordinates within a shape

Theres 2 parts to my problem and they are related. I have a weird shape on my interface illustrated below, I am trying to randomly spawn MovieClips within its' boundaries but I am having some trouble finding a good way to do it.
Question 1: I can run an If condition to check with bitMapData.hitTest to see if the MovieClip has randomly spawn within this shape, if it doesn't simply retry with a new set of random coordinates. However, is there a better way? Like a way to only take into account coordinates within the shape? There will be plenty of MC spawned at one go so I am hoping to lessen the load, or at least find an efficient way to do this calculation.
Question 2: The MovieClips spawned within this shape will eventually have collision detection mechanics that will repel itself when interacted with. Is there a way to contain them within this shape via some kind of boundary detection?
If it was a square, we could easily have contained them with a quick check on all 4 edges, but not with this shape. Currently I am thinking of using bitMapData.hitTest again to detect for out-of-bounds after being repelled, but how do I know which Point() is the nearest 'edge' of this shape to return the MC to?
For question 1: I'm going to go on an assumption that you have some geometry data about the shape.
One method you can use to check if a point is within a shape is to take that point, then draw a line from that point to infinity (the edge of the screen) in one direction. Then count how many times that line intersects an edge of the shape. If it's odd, the point is within the shape (or on the edge) and if it's even, than that point is outside of the shape.
First link in google: https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
Or can also try a more simple method (at the cost of doing more work): if the above shape is generated with all squares and rectangles and you know the point and size of all of those: can just do a check for the point vs all the squares and rectangles that make up the shape.
For question 2: As Organis mentioned, I'd go with a library like Box2D to do this. You'll most likely spend tons of time (that you may not want to) if you try to implement this alone.
The big issue is how much cpu or gpu the code uses. You're trying to avoid using any collision detection. Collision detection is having code do calculations to determine the edges of an object. It should be the last option.
Most of the time you know there's no need for collision detection. You know where everything is and how big it is. Everything has a centerpoint and comparing simple number coordinates is the lightweight way to check if there's a need to check further.
When things get near each other, you only need to do a collision detection on the immediate area around an object. See how your shape fits in a box that is easy to check for collisions? That box should get a collision check before the actual jagged shape inside it.
Yes that collision detection box has to be drawn or mapped but it's done when the object is defined, not when the game is playing. If you are using sprite sheets, keep an xml of the boxes or circles around the shapes.

Global grid of coloured squares representing temperature data on interactive map

I'm trying to create an interactive map (Google Map / OpenStreetMap etc.) showing a global grid of coloured squares representing temperature data. The length of each side of a square inside the grid is 0.5 degrees in terms of the UTM.
I have temperature data for the centre of each square on the grid. These could be min, max etc. I wish to plot this data on an interactive map so that the result will be a kind of heatmap where low values will be bluish and high values will be reddish.
I would expect the result to be similar to this, but interactive:
I have searched for about eight hours and I can't seem to find a viable solution.
I have looked at Fusion Tables, and followed a tutorial to get this example: Fusion Table Example, so I've looked into making a KML file of the 0.5 degrees grid, but got stuck here.
I have looked at CartoDB and made this but if you zoom in, the points are circular and scale smaller as you zoom in. I wish the points to be square and to stay the same size for all zoom levels.
I was thinking of doing something like this but I imagine having this grid on the entire global map would cause it to be very slow.
I hope to have drop-downs on the page to switch to different parameters like max, min temperature etc, and for the overlay to change.
I already have a grid working here but the user simply clicks on a grid to get the temperature graph for that grid. If the user could click something to turn on the coloured grid to see a kind of heat map when they zoom out, that would be great, but I'm a bit lost as to which direction to take. Any help would be greatly appreciated.

AS3 Counting TUIO points within specific coordinates

I am writing a flash app for an LED floor using a Kinect to track tuio points. The interactive is split into three zones. When a particular zone has more tuio points than any other zone, it will send a message to another application which triggers a photostream (not important right now)...
I am wondering what the best way to count these points would be. Would three different containers do it? If so, how is it that each container could effectively "contain" the points. I was thinking of drawing three different Rectangles and creating some kind of function that counts the points within the coords of each rect. I just can't really wrap my head around how to keep certain points married to a specific region or DisplayObject.
Any thoughts? Thank you...
Placing points inside another container is like putting marbles inside balloon; the points will move, but the boundaries of the balloon will stretch to accomodate the marbles. Unless this is the behavoir you're looking for, don't parent the points to your rectangles.
Assuming a specific layout of rectangles, your goal is to count the number of points overlapping each rectangle. While you could certainly go the route of Geometry/Trigonometry calculations to ascertain an overlap (if your geometry were more complex, such as triangles, or n-sided objects), you could probably just get away with a framestack using getObjectsUnderPoint() & Point object..
var point:Point = new Point(tuioX, tuioY);
var stack:Array = getObjectsUnderPoint(point);
Check the array for each of the 3 regions, and you'll have your answer. :)

Calculate 3D coordinates from 2D Image plane accounting for perspective without direct access to view/projection matrix

First time asking a question on the stack exchange, hopefully this is the right place.
I can't seem to develop a close enough approximation algorithm for my situation as I'm not exactly the best in terms of 3D math.
I have a 3d environment in which I can access the position and rotation of any object, including my camera, as well as run trace lines from any two points to get distances between a point and a point of collision. I also have my camera's field of view. I do not have any form of access to the world/view/projection matrices however.
I also have a collection of 2d images that are basically a set of screenshots of the 3d environment from the camera, each collection is from the same point and angle and the average set is taken at about an average of a 60 degree angle down from the horizon.
I have been able to get to the point of using "registration point entities" that can be placed in the 3d world that represent the corners of the 2d image, and then when a point is picked on the 2d image it is read as a coordinate with range 0-1, which is then interpolated between the 3d positions of the registration points. This seems to work well, but only if the image is a perfect top down angle. When the camera is tilted and another dimension of perspective is introduced, the results become more grossly inaccurate as there no compensation for this perspective.
I don't need to be able to calculate the height of a point, say a window on a sky scraper, but at least the coordinate at the base of the image plane, or which if I extend a line out from my image from a specified image space point I need at least the point that the line will intersect with the ground if there was nothing in the way.
All of the material I found about this says to just deproject the point using the world/view/projection matrices, which I find straightforward in itself except I don't have access to these matrices, just data I can collect at screenshot time and other algorithms use complex maths I simply don't grasp yet.
One end goal of this would be able to place markers in the 3d environment where a user clicks in the image, while not being able to run a simple deprojection from the user's view.
Any help would be appreciated, thanks.
Edit: Herp derp, while my implementation for doing so is a bit odd due to the limitations of my situation, the solution essentially boiled down to ananthonline's answer about simply recalculating the view/projection matrices.
Between position, rotation and FOV of the camera, could you not calculate the View/Projection matrices of the camera (songho.ca/opengl/gl_projectionmatrix.html) - thus allowing you to unproject known 3D points?

Create a Graph from points in a Grid that contains holes

I've got a continuous plane (2-D) containing polygonal obstacles. I am uniformly sampling the plane at discrete positions to create a uniform grid of points. The grid does not have points where obstacles lie (i.e. holes where ever an obstacle is) as shown in the image below.
(Please view the image at http://i48.tinypic.com/2efnblg.png for a clear idea of what I'm attempting to accomplish. I couldn't embed it.)
Can anyone point me to some good implementations with optimal worst-case time-complexity?
Solved the problem using recursion.