2d

Collision detection 2D between rectangles

放肆的年华 提交于 2019-12-02 03:14:46
I am writting a collision detection engine for my game and I have some problems. Indeed, since I have several fixed rectangle and one moving (the player), I need to know which side of the fixed one was collided at first by the player, to replace him correctly. The fixed rectangle are NOT in a grid so they can be placed anywhere on the map and they can have diffents size. They are not rotated. The player class stores it's direction vector. Any idea? KiTe In a nutshell: You'll compare the Y and X components of the bounding rectangles to eachother to check for a collision. If the top(Y) of the

Android Development: Combining small tiles/bitmaps into one bitmap

折月煮酒 提交于 2019-12-02 02:00:48
Im trying to get all my small images like grass, water and asphalt and so on, into one bitmap. I have an Array that goes like this: public int Array[]={3, 1, 3, 3, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ,1 ,1, 1, 1 ,1 ,1 ,7 ,7 ,7, 7, 7 ,7, 7 ,7 ,7, 7 ,7 ,7 ,7 ,7, 7 ,7, 7 ,7 ,7 ,7 ,7 ,7 ,7 ,7, 7, 7, 7, 7 ,7 ,7 ,7 ,7 ,7 ,7, 7, 7 ,7 ,7 ,7 ,7 ,7 ,7 ,7 ,7, 7, 7, 7 ,7 ,7, 7 ,6, 6, 6, 6, 6 ,6 ,6, 6, 6 ,6 ,6, 6, 6 ,6, 6, 6 ,6, 6 ,6 ,6 }; So basicly this is a 10*10 Every number is a placeholder for a image(number).png But how do i merge them together? //Simon Okay so the following

How do I get this 2D Array to rotate to the right 90 degrees?

依然范特西╮ 提交于 2019-12-02 01:41:57
So I have a 2D array, and it is supposed to rotate to the right 90 degrees, but instead it rotates to the left. Really can't figure out why public class CrackCode16 { public static void main (String args[]){ int [] [] oldarray = new int [3][3]; int value = 1; for (int i = 0; i < 3; i++){ for (int j =0; j<3; j++){ oldarray[i][j] = value; value++; } } for (int i = 0; i < 3; i++){ for (int j =0; j<3; j++){ System.out.print(oldarray[i][j] + "\t"); } System.out.println(""); } oldarray = rotate(oldarray, 3); System.out.println(""); for (int i = 0; i < 3; i++){ for (int j =0; j<3; j++){ System.out

Transparency groups in CanvasRenderingContext2D

本秂侑毒 提交于 2019-12-02 00:19:49
Is there a way to combine multiple draw operations to a 2d canvas rendering context in such a way that they their combined result is composed onto the previous content of the canvas, as opposed to each drawing operation being composed by itself? One application: I'd like to draw a translucent line with an arrow head, and I'd like to avoid increased opacity in those areas where the line and the arrow head overlap. Many other rendering models support such features. SVG has a group opacity setting, described in section 14.5. The PDF reference describes “Transparency Groups” in section 7.3. In

Rogue line being drawn to window

牧云@^-^@ 提交于 2019-12-01 23:44:48
问题 I am making a graphing program in C++ using the SFML library. So far I have been able to draw a function to the screen. I have run into two problems along the way. The first is a line which seems to return to the origin of my the plane, starting from the end of my function. You can see it in this image: As you can see this "rogue" line seems to change colour as it nears the origin. My first question is what is this line and how may I eradicate it from my window? The second problem which is

Faster Bresenham line for HTML canvas

♀尐吖头ヾ 提交于 2019-12-01 22:38:52
问题 Slow render I am using Bresenham's line algorithm to render pixel art lines in real time. It renders 1 pixel at a time ctx.rect(x,y,1,1) which is a slow operation. I can not use the pixel buffer, which would greatly reduce the render overhead, as I am using composite operations, alpha, and filters (some of which taint the canvas). The function function pixelArtLine(ctx, x1, y1, x2, y2) { x1 = Math.round(x1); y1 = Math.round(y1); x2 = Math.round(x2); y2 = Math.round(y2); const dx = Math.abs(x2

Rogue line being drawn to window

为君一笑 提交于 2019-12-01 22:19:21
I am making a graphing program in C++ using the SFML library. So far I have been able to draw a function to the screen. I have run into two problems along the way. The first is a line which seems to return to the origin of my the plane, starting from the end of my function. You can see it in this image: As you can see this "rogue" line seems to change colour as it nears the origin. My first question is what is this line and how may I eradicate it from my window? The second problem which is slightly unrelated and more mathematical can be seen in this image: As you can see the asymptotes which

Python: how to print out a 2d list that is formatted into a grid?

天大地大妈咪最大 提交于 2019-12-01 22:00:36
问题 Currently, I have made this code def grid_maker(h,w): grid = [[["-"] for i in range(w)] for i in range(h)] grid[0][0] = ["o"] print grid >>>grid_maker(3,5) => [[['o'], ['-'], ['-'], ['-'], ['-']], [['-'], ['-'], ['-'], ['-'], ['-']], [['-'], ['-'], ['-'], ['-'], ['-']]] I want to make another function that will take in the produced 2d array and print it out such that it is in this format: o---- ----- ----- However, I am unsure where to start. 回答1: If you want to "pretty" print your grid with

Faster Bresenham line for HTML canvas

為{幸葍}努か 提交于 2019-12-01 20:52:49
Slow render I am using Bresenham's line algorithm to render pixel art lines in real time. It renders 1 pixel at a time ctx.rect(x,y,1,1) which is a slow operation. I can not use the pixel buffer, which would greatly reduce the render overhead, as I am using composite operations, alpha, and filters (some of which taint the canvas). The function function pixelArtLine(ctx, x1, y1, x2, y2) { x1 = Math.round(x1); y1 = Math.round(y1); x2 = Math.round(x2); y2 = Math.round(y2); const dx = Math.abs(x2 - x1); const sx = x1 < x2 ? 1 : -1; const dy = -Math.abs(y2 - y1); const sy = y1 < y2 ? 1 : -1; var e2

Java: Rotate Point around another by specified degree value

最后都变了- 提交于 2019-12-01 19:40:16
I am trying to rotate a 2D Point in java around another with a specified degree value, in this case simply around Point (0, 0) at 90 degrees. Method: public void rotateAround(Point center, double angle) { x = center.x + (Math.cos(Math.toRadians(angle)) * (x - center.x) - Math.sin(Math.toRadians(angle)) * (y - center.y)); y = center.y + (Math.sin(Math.toRadians(angle)) * (x - center.x) + Math.cos(Math.toRadians(angle)) * (y - center.y)); } Expected for (3, 0): X = 0, Y = -3 Returned for (3, 0): X = 1.8369701987210297E-16, Y = 1.8369701987210297E-16 Expected for (0, -10): X = -10, Y = 0 Returned