2d

XNA - Getting mouse coordinates with a 2d Camera system with rotation/zoom/translation

社会主义新天地 提交于 2019-12-05 01:51:14
问题 I have a 2d Camera with this translation matrix: Transform = Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) * Matrix.CreateRotationZ(Rotation) * Matrix.CreateScale(new Vector3(Scale, Scale, 0)) * Matrix.CreateTranslation(new Vector3((GraphicsDevice.Viewport.Width * 0.5f), (GraphicsDevice.Viewport.Height * 0.5f), 0)); Which works for Rotation/Zoom where the origin is the center of the camera. Now I am trying to get the mouse coordinates in the world. I tried just using an

Fast, Pixel Precision 2D Drawing API for Graphics App?

不羁的心 提交于 2019-12-05 01:25:25
问题 I woud like to create a cross-platform drawing program. The one requirement for writing my app is that I have pixel level precision over the canvas. For instance, I want to write my own line drawing algorithm rather than rely on someone elses. I do not want any form of anti-aliasing (again, pixel level control is required.) I would like the users interactions on the screen to be quick and responsive (pending my ability to write fast algorithms.) Ideally, I would like to write this in Python,

2D Tile Lighting

寵の児 提交于 2019-12-05 00:35:34
问题 I'm adding lighting to my XNA 2D tile based game. I found this article useful, but the way its done it does not support collision. What I'd like is a method to do the following Have always lit point Collision (If the light ray hits a block, then dim the next block by whatever amount until its dark to simulate shadows) I've been searching around for quite a while but no luck (I did find Catalin's tutorial, but it seemed a bit advanced for me, and didn't apply to tiles well due to redrawing the

Algorithm for translating list of wallsections into coherent polygon

女生的网名这么多〃 提交于 2019-12-04 22:43:22
I have a list of points that in pairs describe a polygon, like this: <0,0><0,1><0,1><1,0><1,0><1,1><1,1><0,0> which is a square. Note that each pair of points describes a line so our square is made up out of the lines <<0,0><0,1>><<0,1><1,0>><<1,0><1,1>><<1,1><0,0>> I do however have to draw these polygons which works fine when the points in question are all properly in order and there are no holes. Unfortunatly this sometimes goes wrong when the input is like <0,0><0,1><1,1><0,0><0,1><1,0><1,0><1,1> and the resulting polygon is weird or when there are several holes in the <0,0><0,2><0,2><2,0>

convert circle into heart 2d android [closed]

穿精又带淫゛_ 提交于 2019-12-04 22:10:27
hi sorry but my maths and physics is too weak so i tried so many times but every time i failed i need your help to complete my app plz convert this circle to heart import android.graphics.Bitmap; public class Circle { float origRadius,deltaRadius,radius,origX,deltaX,x,origY,deltaY,y; int color,alpha,steps,currentStep; Bitmap bitmap; public Circle(float xCenter, float yCenter, float radius, int color, int steps) { this.x = xCenter; this.origX = xCenter; this.deltaX = (float) (40.0 * Math.random() - 20.0); this.y = yCenter; this.origY = yCenter; this.deltaY = (float) (40.0 * Math.random() - 20.0

Plotting equation to cartesian plane

点点圈 提交于 2019-12-04 20:29:37
I am trying to plot a two variable equation to a Cartesian plane. Here is my problem, on the code below if I comment out one for loop and let another run, the plot of the graph (the negative or positive sides of x) is correct, but if I run both for loops they seem to alter each other and the graph comes out wrong. I've tried every combination of for loops, looping frontward, backward, nothing seems to solve it. I commented out the where these loops are at the end of the class "public class DrawingComponent extends JComponent" where it says "// This two loops work fine if each one is run

Unity3d Is there something like Mesh Collider for 2D objects?

只谈情不闲聊 提交于 2019-12-04 20:00:02
Im making simple 2D game, I designed the "way" the player going through in the game. If the player touches the wall the game is over, so I must detect collisions. At first I created the walls from sprites, but then I realized there is no 2D collider that suit himself to the shape of the sprit(it was to difficult to create the collider manually from a lot of smaller polygon and circle colliders), so I made all the walls that builds the "way" 3D objects(.dae files with z=0.001), and added them the mash collider which suits himself to the 3D object. I changed my player to be 3D as well so the

How to multiple a 2D point with a 4D Matrix

岁酱吖の 提交于 2019-12-04 19:58:07
How can I convert a 2D point (or 3D with Z=0) to 2D point(where Z is ignored) with a 4D matrix ? I am using Microsofts Silverlight to project a 2D control as pseudo 3D using a Matrix3D definition of Matrix3D I know the initial 2D coordinate of a point in the untransformed control and I want the 2D position of the point after the transform. The silverlight API is sparse regarding 3D methods. Please suggest basic math to perform the calculation. This is a follow on from a silverlight specific question Edit further details its not working. I am using x = x0 * matrix[0][0] + y0 * matrix[1][0] + z0

Wrong rectangle size in canvas

↘锁芯ラ 提交于 2019-12-04 19:09:18
问题 I'm implementing a color picker. There is problem with the rendering. When I call c.fillRect(0, 0, 100, 80); the size of that rectangle is 103x42 px instead of 100x80. What is wrong here? Also, rectangles are antialiased. Do I need offset the position by (0.5, 0.5) to avoid AA? I didn't use any kind of the coordinate system transformations. colorSlider = function($e, color) { this._$canvas = $('<canvas></canvas>'); this._c = this._$canvas[0].getContext('2d'); this._color = color || { r: 0, g:

Accurately detect color regions in an image using K-means clustering

与世无争的帅哥 提交于 2019-12-04 18:35:30
I'm using K-means clustering in color-based image segmentation. I have a 2D image which has 3 colors, black, white, and green. Here is the image, I want K-means to produce 3 clusters, one represents the green color region, the second one represents the white region, and the last one represents the black region. Here is the code I used, %Clustering color regions in an image. %Step 1: read the image using imread, and show it using imshow. img = (imread('img.jpg')); figure, imshow(img), title('X axis rock cut'); %figure is for creating a figure window. text(size(img,2),size(img,1)+15,...