What's reasonable way to represent a grid in terms of an object?
It's part of a two dimensional graphic programming exercise where at the center of the grid is "me".
The object needs to be scalable up to 20,20.
So if I have a 3,3 grid I need to know that I am in grid 1,1 (center) and that 0,0 is lower right. And if I have an grid of 5,5 I need to know that 2,2 is the center and 0,0 is the center.
If you need a reduction of the complexity and another order of the grid you can use space-filling-curve like a z-curve, a hilbert-curve, a peano-curve.
Related
Rectangle frame is an area that needs to be split in 4 parts (not equal at all). I need sizing according to population in each area. Inside the rectangle I need to divide between two categories which can be part of any quadrants (split of rectangles). Circle could be oval or whole rectangle could be circular. But I need it easy and quick! This has been easy design on paper.
Thanks.
enter image description here
Hi stackoverflow community,
This is a continuation of a question I asked 6 months regarding calculating the area and position of dynamically formed rectangles. The solution provided for that worked a treat but now I want to take this a step further.
Some background - I'm working on a puzzle game using Cocos2D/Box2D were the player draws lines on the screen. Depending on were the player draws, I want to then work out the area and position of polygons that appear as a result of the drawn lines.
In the following image, the black border represents a playing area, this will always be the same shape. The grey lines are player drawn and will always be straight. The green square is an obstacle. The obstacle objects will be convex shapes. The formed polygons (3 in this case) are the blue areas and are the shapes I'm trying to get the coordinates and area for.
I think I'll be fine with working out the area of a polygon using determinants but before that, I need to work out the coordinates of the blue polygons and I'm not sure how to do this.
I've got the lines (x,y) coordinates for both ends, the coordinates for the obstacle and the corner coordinates for the black border. Using those, is it possible to work out the coordinates of the blue polygons or am I approaching this the wrong way?
UPDATE - response to duffymo
Thanks for your answer. To explain further, each object mentioned is defined and encapsulated in a class i.e. I've got a Line/Obstacle/PlayingArea object. My polygon object is encapsulated in a 'Rectangle' object. Each one of these objects has it's own properties associated with it such as its coordinates/area/ID/state etc...
In order to keep track of all the objects, I've got an over-seeing singleton object which holds all of the Line objects / Obstacle objects etc in their own respective array. This way, I can loop through say all Lines and know were each one has been drawn by the player.
The game is a bit like classic JezzBall so I need to be able to create these polygon shapes when a user draws a line because the polygon shape will be used as my way of detecting if that particular area contains a ball. If not the area needs to be filled.
Since you already have the nodes and edges for your polygons, I'd recommend that you calculate the centroids, perimeters, and areas using contour integration You can express the centroids and areas as contour integrals using Green's theorem.
You can use Gaussian quadrature to do piecewise integration along each edge.
It'll be fast and accurate; it'll work on polygons of arbitrary complexity.
UPDATE: Objective-C is an object-oriented language. I don't know it myself, but I believe it's based on ideas from C and C++. Since that's the case, I'd recommend that you start writing more in terms of objects. Arrays of coordinates? They need to encapsulated together. I'd suggest a Point abstraction that encapsulates a point (id, x, y) together. Make a Grid that has a List of Points.
It sounds like users supply the relationship between Points to form Polygons. That's not clear from your description, so it's not a surprise that you're having trouble implementing it.
I am attempting to organize one to six images in a grid with a fairly random layout. I am passing the method an array of images that I want to iterate over and return a view containing the grid of images similar to my example below. What would be the best approach to accomplish this?
Edit: I am trying to figure out how to layout each view on the fly. Also, the first grid in count == 5 in the image is incorrect.
Let's say, you have 3 images. You will have 4 possible layouts. Calculate for each layout, in which combination of subviews and images you lose less pixels from the images, when scaling and cropping them to the dimensions of the subimages. If several layouts have the same result, pick one randomly.
I have a huge map image (8192x6144px) which I'd like to display at scales ranging from 1x to 0.1x. At 1x this is about 24 mb using PVR 4-bpp compression--a little too much. So I'd like to load them at varying resolutions, depending on the map scale.
Does mipmapping accomplish what I need, which is to load/unload levels of mipmaps based on the map scale? From what I've read it sounds like all mipmap levels need to be loaded, and cannot be generated/released at runtime.
Well, technically, it can (you can select which one of the mipmap level you want to update / fetch from), but this leaves you with the initial problem : when you're at max zoom, you have to have the entire image in memory.
I can think of two options.
This first is a dynamic atlas texture, also known as megatexturing or virtual texturing. You'll find plenty of links on the subjects, but this is a little bit overkill for what you want.
The second is a standard LOD (level of detail). At zoom 0.1x, you draw only 1 quad, with a low-def texture. When you zoom in, you recursively split the quad depending on the distance to the camera (near = recurse more). For each medium or little quad, you create a new texture at the right resolution, and bind it.
So you'll have a series of 512x512 images, at different resolutions, organized in a hierarchy.
I am in the process of making my 2D engine for a Beat'em Up game (Castle Crashers is what I call Beat'em Up or Brawler kind of game ).
I will support 2D sprites and 2D particle emitters. This is all done in the engine now. But I have come to an issue that I would like to ask for advice:
It's about "space" management, what I thought was to do something as this image shows:
alt text http://img337.imageshack.us/img337/9162/spacingprototype1.png
My idea is to make a grid ( Spatial Hash or Grid ), of the ground where my Particle Emitters / 2D sprites will live. In my picture, I have enumerated this slots from 1 to N, (don't have to be 35, it's just for showing purposes ). My idea is to draw the "GameElements" (Sprites/Emitters) in order from 0 to N , ( going from bucket 0 to bucket N ) , so then I will get them to display correctly overlapped on screen (back to forward).
I know this could be done by just comparing the lower Y axis of each Element and performing a "quicksort" too, but having the Grid could allow me to perform Collision Detection in a better way , and if I do something like A* to implement some kind of AI, it could help me too.
If you want to have some sort of optimization for the number of objects you need to test against each other, you might want to think about using a Quadtree
http://en.wikipedia.org/wiki/Quadtree
The idea is to divide the screen up in 4 nodes, placing all items in the node they belong, then divide the nodes you just created up in another 4 if there are sprites/items/whatever in there that need to be tested. Keep doing this until a certain size or amount of items in a node has been reached.
You can then ask the top-node if it contains the item you want to test. This node will then ask the child-nodes if it contains the item, which in their turn will ask their children. This way a large part of the screen can be skipped already (if it's located in child 00, you can skip child 01, 10 and 11). Then you get a list of items you perform more specific collision detection on when it's desired to do so.
If you were to make it visual, it would look a bit like this:
alt text http://geodata.ethz.ch/geovite/tutorials/L2GeodataStructuresAndDataModels/en/images/quadtree.gif
Fire them out to the Z buffer and let that worry about it.
If you find that in the future it is too slow (via profiling obviously) then look at optimizing it.
Take the simplest solution and move on.
Your method fails if you have two sprites occupying the same box in the grid. Suppose you have two enemies both standing in the same box. One stands slightly in front of the other. Which do you draw first? You would need two algorithms - one which divides the sprites into the grid, and the second which looks at the z co-ordinates of all the sprites in a given grid box and draws them based on that value.
A far simpler method is to have a single collection of all sprites. It should store all sprites sorted by their z co-ordinates (from the back of the screen at the head of the list to the front of the screen at the back). Loop through the collection and draw each sprite as it appears. When a sprite moves into or out of the screen (ie. its z co-ordinate changes) you can perform a very simple sort to move that single sprite within the collection. Keep swapping it with the next sprite in the list until the next sprite's z co-ordinate is greater than/less than (as appropriate) the changed sprite's co-ordinate.