2d

How to divide an area composed of small squares into bigger rectangles?

谁说胖子不能爱 提交于 2019-11-30 13:26:24
Where would i go to look for algorithms that take a 2d grid of values that are either 0 or 1 as input and then identifies all possible non-overlapping rectangles in it? In a more practical explanation: I am drawing a grid that is represented by a number of squares, and i wish to find a way to combine as many adjacent squares into rectangles as possible, in order to cut down on the time spent on cycling through each square and drawing it. Maximum efficiency is not needed, speed is more important. Addendum: Apparently what i am looking for seems to be a technique called Tesselation. Now i only

Win32 clipboard and alpha channel images

冷暖自知 提交于 2019-11-30 13:07:15
My application should be able to copy 32-bit images (RGB + alpha channel) to the clipboard and paste these images from the clipboard. For this I plan to use CF_DIBV5 because the BITMAPV5HEADER structure has a field bV5AlphaMask . The problem is that there doesn't seem to be a consensus as to how exactly the image data should be stored in the clipboard. While doing some tests I found out that there are several differences betweeen the applications making it next to impossible to come up with a general solution. Here are my observations: When I copy an alpha channel image from Word 2010 or

Simple 2d polygon triangulation

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 12:14:38
问题 Trying to triangulate a set of simple 2d polygons , I've come up with this algorithm: 1) For each vertex in the polygon, compute the angle between the two linked edges 2) Sort vertices by decreasing angle relative to the interior of the polygon 3) If there is less than 3 vertices in the set, we're done 4) Take the last vertex in the set and output the triangle formed by it and its two neighbours 5) Remove the vertex from the set 6) Update the angle of the two neighbours 7) Jump to 2 I've

Efficient 2D Tile based lighting system

不羁的心 提交于 2019-11-30 11:57:22
问题 What is the most efficient way to do lighting for a tile based engine in Java? Would it be putting a black background behind the tiles and changing the tiles' alpha? Or putting a black foreground and changing alpha of that? Or anything else? This is an example of the kind of lighting I want: 回答1: There are many ways to achieve this. Take some time before making your final decision. I will briefly sum up some techiques you could choose to use and provide some code in the end. Hard Lighting If

Difference between glOrthof and glViewPort

吃可爱长大的小学妹 提交于 2019-11-30 11:37:05
On OpenGL-ES i'm confused on what the difference is between setting glOrthof() glViewPort() GLU.gluOrtho2D() with it's respective parameters. Since I believe it's all setting the part you can see to the specified coordinates (width, height). Which should I use? The glViewport determins the portion of the window to which OpenGL is drawing to. This may be the entire window, or a subsection (think console game's "split screen" mode- a different viewport for every player). glOrthof applies an orthographic projection to the current matrix, which is usually set to the projection matrix before this

Area of self-intersecting polygon

拥有回忆 提交于 2019-11-30 11:36:30
Calculating the area of a simple irregular polygon is trivial . However, consider the self-intersecting polygon ABCDEF shown at left below: If we use the linked-to formula above traversing the points in polygon order, we get an area of 0. (The 'clockwise' area cancels out the 'counter-clockwise' area.) However, if we sort the points radially around a center and calculate the area, we get the incorrect area of the polygon ABEDCF at right above. How can I best find the visible area of a self-intersecting polygon? (If the answer requires creating phantom points for each intersection, please

Algorithm for finding nearest object on 2D grid

好久不见. 提交于 2019-11-30 10:39:59
问题 Say you have a 2D grid with each spot on the grid having x number of objects (with x >=0). I am having trouble thinking of a clean algorithm so that when a user specifies a coordinate, the algorithm finds the closest coordinate (including the one specified) with an object on it. For simplicity's sake, we'll assume that if 2 coordinates are the same distance away the first one will be returned (or if your algorithm doesn't work this way then the last one, doesn't matter). Edit: A coordinate

Most performant way to graph thousands of data points with WPF?

こ雲淡風輕ζ 提交于 2019-11-30 10:22:49
问题 I have written a chart that displays financial data. Performance was good while I was drawing less than 10.000 points displayed as a connected line using PathGeometry together with PathFigure and LineSegment s. But now I need to display up to 100.000 points at the same time (without scrolling) and it's already very slow with 50.000 points. I was thinking of StreamGeometry , but I am not sure since it's basically the same as a PathGeometry stroring the information as byte stream. Does any one

Find all the points of a cubic bezier curve in javascript

爱⌒轻易说出口 提交于 2019-11-30 10:06:06
I have a cubic bezier with 2 control points. Starting point and control points are known. Need to get all the points of the curve, given the control, starting and ending points. What I wanna to achieve is ..given a value i from 1 to length of curve.. get the X and Y and alpha (angle) of each point in that position. I cannot find a good reference or working code for that. I'm using javascript. Rahul Banerjee If I understand correctly, you are trying to determine the position and slope (tangent to the curve) of the Bezier, at every point. Let's assume that your start point is (ax, ay), the end

OpenGL texture atlas bleeding

拜拜、爱过 提交于 2019-11-30 09:52:46
I'm trying to draw a basic 2d ground mesh made up of smaller tiles from a texture atlas (note the 1 pixel transparent border): I render the tiles as texture quads using the following code: glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(2, GL_SHORT, 0, &m_coords[0]); glTexCoordPointer(2, GL_FLOAT, 0, &m_uvs[0]); glDrawArrays(GL_TRIANGLES, 0, m