/// <summary>/// Determines if there is overlap of the non-transparent pixels between two/// sprites./// </summary>/// <param name="transformA">World transform of the first sprite.</param>/// <param name="widthA">Width of the first sprite's texture.</param>/// <param name="heightA">Height of the first sprite's texture.</param>/// <param name="dataA">Pixel color data of the first sprite.</param>/// <param name="transformB">World transform of the second sprite.</param>/// <param name="widthB">Width of the second sprite's texture.</param>/// <param name="heightB">Height of the second sprite's texture.</param>/// <param name="dataB">Pixel color data of the second sprite.</param>/// <returns>True if non-transparent pixels overlap; false otherwise</returns>publicstaticboolIntersectPixels(MatrixtransformA, intwidthA, intheightA, Color[] dataA,MatrixtransformB, intwidthB, intheightB, Color[] dataB) {// Calculate a matrix which transforms from A's local space into// world space and then into B's local spaceMatrixtransformAToB = transformA * Matrix.Invert(transformB);

// When a point moves in A's local space, it moves in B's local space with a// fixed direction and distance proportional to the movement in A.// This algorithm steps through A one pixel at a time along A's X and Y axes// Calculate the analogous steps in B:Vector2stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB);Vector2stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB);

// Calculate the top left corner of A in B's local space// This variable will be reused to keep track of the start of each rowVector2yPosInB = Vector2.Transform(Vector2.Zero, transformAToB);

// For each row of pixels in Afor (intyA = 0; yA < heightA; yA++) {// Start at the beginning of the rowVector2posInB = yPosInB;

// If both pixels are not completely transparent,if (colorA.A != 0 && colorB.A != 0) {// then an intersection has been foundreturntrue; } }

// Move to the next pixel in the rowposInB += stepX; }

// Move to the next rowyPosInB += stepY; }

// No intersection foundreturnfalse; }

I am familiar with java so I can translate most of the code myself. width, height and color data I have access to so we dont have to worry about them.It is the Matrix and Transform classes that confuse me. What is their equivalence in Slick2D? Also, in my game, the rotation of the images is stored as an float.

Since Slick uses LWJGL, you can actually make use of Vector2f/Matrix4f/etc.

Do I really need to learn linear algebra? That would require a background of math to, which I dont have.I checked the Slick2D api and I found a few interesting things but I am stuck at the first line in the method body:Matrix transformAToB = transformA * Matrix.Invert(transformB);How do I translate this?

The real problem is that since Slick uses OpenGL for rendering, you won't have access to the color data without performing a copy from GPU to CPU (which can be slow).

Or you could keep a 'Pixmap' (<- LibGDX) storing all the data on the CPU from the beginning on. I think that's totally okay on today's hardware. Today we have enough RAM space to store two copies of texture data, once on the CPU Memory once on the GPU memory.

The only problem is that I don't have a clue of how to do that with Slick2D. I'd go with writing a simple Pixmap class storing an int[] array with color information from the loaded BufferedImage, which Slick can obviously read and convert to a ogl texture.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org