3D Flood Fill using Java - java

I am using the JMonkey Engine to create a 3D bounding box and then I'm trying to use smaller boxes to flood fill the bounding box. Unfortunately I can't find a 3D flood fill algorithm.
Does anyone know of a 3d flood fill algorithm or have any pseudo code or examples of this being done in any language?

I don't think you will find something like that. Floodfill is somewhat bound to pixel based graphics, and that doesn't go along well with OpenGl / 3d.
If you have some kind of pixel concept for 3d, I think adapting a 2d algorithm shouldn't be rocket science. I just doubt anyone found it useful so far.
Perhaps something like octrees is worth further reading?

Related

Custom 3D graphics engine... where to plot Z coordinate

I'm brainstorming a way to create a basic custom 3D engine by myself and it's all very new to me, as I've only practiced 2D graphics.
Assuming that we have calculations for a Z coordinate using the recommended formulas given here, how might I go about plotting the Z coordinate? I understand that by default, Java graphics draw on a 2D field, which means that the only coordinates I can draw to is either the X or Y coordinate... and that's where I'm stuck.
3D development is not taught in my college... so I really appreciate good feedback. The tutors here never practiced creating 3D engines, so I'm very frustrated because learning this concept is crucial.
In order to map 3D coordinates to a 2D plane (the screen) you'll need to understand the concept of the Frustum and how to utilize a Projection Matrix.
This article does an excellent job of explaining what it does and how to implement one. Writing your own engine for this seems to be a massive undertaking and assumes you understand the vector and matrix mathematics. If not, I would suggest doing some reading on linear algebra; it's fundamental to this kind of programming.
If you'd like to work with some already established technologies, look into OpenGL for Java.
I know how to make a 3d program in English but not in code.
If you would like to make one, please let me know. So I can see how active you are.
Oh my apologies. I didn't answer*. Let me elaborate on your predicament.
Z axis doesn't exist. It's an illusion. You need to produce a procedural code to establish this illusion.

Animate a cube turning via mathematics (Java)

For a school project i have made a program that can solve a rubiks cube (you know, that cube with all the colors). But now my teachers asked if i could do some research and try out 3d animation for one of the sides. But they want to see the mathematical way to do it. I have found a way to move the corners with the use of polar coordinates. But i do not know how i could render a cube in 3d and be able to animate it.
So my question is: how can i render things like a cube in 3d (or are there any good libraries for it) and how could i use these polar coordinates to animate it?
And is there a good tutorial out there for java 3d rendering?
i must say that i have absolutely no experience with 3d rendering, so it might be a bit difficult. But i really would like to try it out.
thanks in advance
Depending on whether you want to take an existing implementation or if you want to build code for 3D animations from scratch, you might try this tutorial. Graphics programming in this area can be quite involved; a full answer of the question is beyond the scope of this site. However, there are a few main areas.
Usage of vector math for transformation of objects (translation, rotation). This can be done directly or via projective geometry using 4-by-4 matrices. The latter is easier for concatenation of transformations.
Backface culling to remove faces of the object which cannot be seen by the camera.
Using a projection and a camera model to transform 3D coordinates to 2D coordinates.
Using a rasterizer to render the 3D vector information to the screen. Here Bresenham's algorithm might be a good start.
I would suggest you look at one of the 3D libraries. One that I've used a lot and found to be excellent is JMonkeyEngine (JME) which is designed for games but would work well for your needs. It also has an excellent tutorial that takes you from basic to very complex. In fact the first step in the tutorial is a revolving coloured cube!
JME takes a huge amount of the work out of 3D modelling. You build a scene in code with materials, lights etc. and JME does all the work to render it. You can even build your models in a tool such as Blender so you don't even need to do the modelling in code. But I will warn you that using modelling tools is definitely not for the faint hearted.

Detecting lines in a hand drawn canvas stroke

I have a drawing canvas and I would like break it apart into lines by finding the corners.
I'm collecting the stroke points using something similiar to this Google example:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html
I've been using http://jabtunes.com/notation/shortstraws.html to handle this in JavaScript. Does anyone know of an easy way to do this using Java on an Android device?
You can try something like a Hough Transform. It's a common way of finding shapes in Computer Vision applications. You might also want to combine it with an edge-detection algorithm, which is pretty simple to implement (maybe 20 or 30 lines of code).

Generating tile noise maps "on the fly"

I’m interested in generating 3D height maps for a 2D game I am working on. I am using this to create land masses like in Minecraft or Dwarf Fortress.
I've created 2D heightmaps before, but I used a very rudimentary algorithm that just interpolated between points of a fully random noise array to create a fixed size map. This doesn't tile however since if I try to add a new map next to it, it doesn't account for the height of the existing map.
I have read about Perlin and Simplex noise, but I’m now confused on how to apply Perlin or Simplex noise to a 2D array of height values.
Any help with this would be greatly appreciated. I have no idea what to do anymore. The term 'octaves' not on sheet music scares me.
Exactly, you have to look for Perlin/Simplex noise. Think of it as a function f(x,y,...) (as many variable as you wish) that will output random-looking noise. The difference with pure noise is that it acts on gradients, so it will look more natural since it "draws" gradients instead of plain noise with high local variability. Simplex noise is pretty much the same as Perlin's but it divides space in simplexes instead of operating in n-dimensional grids like Perlin does. This alleviates computational cost and has some more benefits.
It might seem scary, but it's simple actually. You're scared about octaves, but they're pretty much the same as octaves in music: just higher (or lower) frequency noise mixed with the original output. Talking about sheet music, it's like playing C4 and C5 at the same time. It's still C but it has some flavor added (little spikes in the waveform.) Don't be afraid and keep researching, it's not that hard.
Regarding tiling:
If you mean linear tiling (like Minecraft does) you just have to use the same seed for the noise algorithm. As soon as you approach your new boundaries, just generate the new chunk of data and it will tile perfectly (just like it does if you infinitely fill with noise.)
If you mean torus tiling (repeating tiles, think Pacman for instance) I found the best solution is to generate your noise tile and then interpolating near the borders as if it were tiled. The noise will deform to match sides and it will be completely tileable.
I think that your question might be phrased incorrectly. A heightmap is 2D, inherently, and you use it to generate 3D terrain (mesh).
http://en.wikipedia.org/wiki/Heightmap
If that is the case... then you can use the Perlin noise function to create a 2D image and use it for a heightmap. If you are unsure of what is created, you can use GIMP or Photoshop or a similar tool to create Perlin noise on a 2D Canvas for an example.
Minecraft makes use of the Perlin noise function to create a 3D cube of noise. So where a heightmap is 2D Perlin noise, Minecraft is 3D Perlin noise. You can also generate 1D Perlin noise.
What is nice about the Perlin noise function is that you can control the "resolution" and "offsets" of the texture through the mathematics and hence create seamless environments. I believe that Minecraft makes use of Perlin noise as a base and then moves on to some cellular automata for finishing touches.
I am unfamiliar with simplex noise.
EDIT: here is a link to test some math functions (in processing)
http://processing.org/learning/basics/noise2d.html

how can i do to a 2D image and spin it around it's X, Y, or Z axis as if it were a 3D image.in java?

I want to achieve the effect of a 2D image I have but a little inclined, for example a plane, I want the image can be rotated about its axis Y. .. anyone can help me with some idea of how to do ..**
Basically you need a little linear geometry/algebra, and/or a package to do them for you.
From the geometry point of view, you think of the image as if it's on a plane in space; you're looking at it as if it were back-projected on your monitor. If the picture is exactly parallel to that screen, and the same size, each point is mapped to a pixel on the screen. Otherwise you have to go through a computation that makes that mapping, which involves a trig function for the angles in the x,y,z directions between that plane and the plane of the screen. The linear algebra comes in because the easy way to handle this computation is as a series of multiplications of 4×4 matrices.
Now, you could program all that yourself, and for what you're thinking of it wouldn't be all that difficult. See any good computer graphics text, like Shirley, or Foley and van Damm.
As far as a package, there's good 3D graphics in Java. Even better, there are good tutorials:
The Java3D tutorial at Sun.
the stuff at j3d.org
a whole list of them at java3d.org
In what context ? Using a 3D API like OpenGL trough JOGL seems to me like the simplest way to achieve this. Otherwise, if the angle is variable, you'll need some form of software renderer.

Categories