StoneAgeCoder
StoneAgeCoder

Reputation: 1003

Java Algorithms for Geometric Primitives

I have been researching some about algorithms for geometric primitives where the two most vital for me are lines with stroke and circles. Oracle does not seem to provide the exact information for generating these shapes for painting. The reason why I want this is because I need to store the affected pixels from painting into a texturePaint[] for game collision detection. I mainly wanted expert input on if its worth even doing because just using bufferedImages is effecting how big I can make my game maps because of RAM issues. Will it slow down my painting process by a significant amount from iteration through the array or does java iterate through each pixel for painting to draw its shapes?

Upvotes: 2

Views: 329

Answers (1)

CodeMed
CodeMed

Reputation: 9189

In terms of speed, writeableraster allows you to make pretty fast alterations to an image. You can also use tools like fork/join to speed things up faster if needed.

In terms of collision detection, I am afraid you are going to have to rely on your own hand-rolled mathematics functions. Here is an example.

EDIT:

When I was doing that kind of coding, I found that using the setPixels method in writeableraster was a LOT faster than relying on the paintComponent approach, such as drawing shapes. If you want to feel more certain, you could write some functions to test each approach by repeating the operation 10000 times and see which approach finishes faster.

Also, in addition to multithreading, you can use java's double buffering and BufferStrategy tools to prepare the subsequent rasters before they are needed. In this way, each successive raster is simply "turned on" when its turn comes because it has already been pre-rendered in the buffer.

I hope these additional links help.

Upvotes: 2

Related Questions