Custom 3D Rendering - java

So I've been prodding ever so diligently at the internet as of late and have come across some interesting games. The basic example is Minecraft4k. It was made for the Java4k contest a few years back, but what I am really interested in is how the rendering was done. There are a lot of games like this made every year, but I really can't find much on how the creators went about synthesizing 3D worlds, let alone with minimal code.
The basics that would have be implemented would be polygon filling, z-ordering, and some sort of "fog" in order to prevent too much landscape from being drawn (optional, really). I've read up on the Scan line filling algorithm and have a working example but I have no idea how to get any form of z-buffering working. So the question is, does anyone have any experience with this sort of custom 3D rendering work? If so, any tips/pointers/resources you can point me to?
I know this is a bit of a shallow and perhaps inadequate question, but I figured I would try on here. Thanks in advance!

Wikipedia is a good start point (though it is bad for me to post a link) and explains about different techniques.
I developed a 3D software renderer for dots (the simplest 3D renderer ever ;)) and the z-buffering consists of sorting an array of rendered elements according to the Z coordinate, which in turns depend on the projection you are using, either orthographic, isometric, etc. (see another Wikipedia article about projections). In the simplest projection, you simply ignore the Z coordinate when drawing object, but take it into account during rotations (as it has an impact on X and Y).

Related

How do you create and render a 3D Fractal?

So I've been assigned a recursive art project for my AP CS class and have a bunch of spare time, so I've decided to try something a little bit more ambitious.
My plan is to create a 3D fractal, either rendered and shaded in a visualization with GL, or represented via spatially mapping the respective equations' outputs to points on a cube and drawing those. If this explanation seems unclear, please check out the links at the bottom for images. Now, I don't need the fractal to be able to be modified in-program. I just need it to render a single BufferedImage, which I'll be putting directly on a JFrame.
My experience in Java, as far as this project goes, is a bit limited. I've drawn Mandelbrot and Julia set fractals before, but I have little to no experience drawing/rendering objects in 3D in Java. This is all stuff I can look up and figure out myself though, so no worries here.
Thus, the question: How does one map a fractal that should be in the 2nd dimension (e.g. log(no. of subdivided entities)*log(side length of subdivision) = 2) to the 3rd dimension (e.g. log(no. of subdivided entities)*log(side length of subdivision) = 3)? I'm lost trying to mathematically work this out, and I believe there is a more organized approach to go about this circumventing a lot of the math that already exists.
Also, if you are aware of a structured approach to render a 2D fractal, as drawn by a formula, and render it in 3D, provided the respective formula is provided (power is raised), please let me know. I've heard of Ray Tracers, no idea what they are, a brief summary would be cool.
Here are links with pictures of the result I want to obtain:
http://2008.sub.blue/assets/0000/4575/power8_large.jpg
https://www.youtube.com/watch?v=rK8jhCVlCtU
It looks like the image is an example of a Mandelbulb. The is a similar iteration formula to the Mandlebrot set but using 3D points and a novel idea of what raising a 3D point to a power means.

Agar.io-like cell physics

I wanted to make a circle that has a ripple-effect on the edges, kind of like in the game agar.io. I am kind of lost on how to implement it. Obviously I can't just g.fillOval() because that would draw a solid circle with no movement on the edges.
I'm not asking anyone to write any code for me (but if you really want to, I don't mind :D), but if you could point me in the right direction with some methods I should use. I am using Slick-2D library for java, if that helps.
I also tried analyzing the javascript source from the agar.io website to try to understand how they implemented it in javascript, but I was unsuccessful because the code was obfuscated; all the methods and variables were just single letters.
The only way I can imagine doing this currently is to have each circle be composed of a number of points, and let each point have it's own physics, and it can be affected by other points. If anyone who has insight into this problem, I would greatly appreciate some help. Thank you!
I'm not sure you can do this with Slick2D. It is quite high level and gives a lot built-in classes. What you want to do is really specific. As Slick development has stopped you will not get new features. You should probably look at lwjgl which is the base of Slick. It is more low-level but can be more precise with the form you need.
You can look at this project to have some drawing cool stuff. And for another example of manipulating circle you have this one

Basic dynamic 3D collision in LWJGL

sorry about my last question it was a bit all over the place.
I have hit a huge road block with a game I am coding for a friend and i need to learn dynamic collision. A tutorial would be great, a very basic one and i have already seen the NeHe collision detection tutorial and did not seem to pull much from it.
Thanks in advance to all who reply.
What you could do is create a invisible 3d box surrounding your entities and check when two or more of said boxes have intersecting xyz coordinates. I can't supply you with code, but I know it works. You would have to figure out the coding for yourself

Appropriate Transformation for 3D-looking 2D drawing (Java)

I'm looking for the appropriate transformation to make a 2D image look like a 3D drawing. If I draw a "road" with parallel lines on a sheet of paper, and then tilt the top of the page away from you, so that the road appears to be disappearing into the distance is what I am looking for.
I'm using Java and would like an appropriate API/library. I don't believe "AffineTransformation" accomplishes this.
You don't want an AffineTransformation, as that will always preserve parallel lines, which isn't what you want here.
Luckily the Java Advanced Imaging API (javax.media.jai) has exactly what you want, in the shape of the PerspectiveTransform class (click that link for docs).
Your problem is not trivial, but certainly solvable. You can take any four-sided image and apply a 3D perspective transformation. Just don't expect it to be a one-liner.
I'm at home now (checking SO before going to sleep, of course :D), but I'm almost 100% certain this is the site I used to find the appropriate code in C#:
http://ryoushin.com/cmerighi/en-us/61,2007-10-29/Image_Distortion_Enhancements.aspx
Porting it to java should be fairly straightforward. Let me know if the link doesn't solve your answer and I'll edit my answer tomorrow with more info.
I can't give you a simple answer, but I can tell you that what you're looking to draw is called two-point perspective. With this information, maybe you will be able to find a library that takes a 3D object and produces a perspective view.
Here's a simple Java applet that I've seen previously that demonstrates 2-point perspective:
Link
Hope this helps!

How to create 3D Tag Cloud in Java

I need a suggestion/idea how to create a 3D Tag Cloud in Java (Swing)
(exactly like shown here: http://www.adesblog.com/2008/08/27/wp-cumulus-plugin/)
, could you help, please?
I'd go either with Swing and Java2D or OpenGL (JOGL).
I used OpenGL few times and drawing text is easy using JOGL's extenstions (TextRenderer).
If you choose Swing, than the hard part will be implementation of a 3D transformation. You'd have to write some sort of particle system. The particles would have to reside on a 3D sphere. You personally would be responsible of doing any 3D transformation, but using orthogonal projection that would be trivial. So it's a nice exercise - what You need is here: Wiki's spherical coord sys and here 3d to 2d projection.
After You made all of the transformation only drawing is left. And Java2D and Swing have very convenient API for this. It would boil down to pick font size and draw text at given coordinates. Custom JPanel with overriden paintComponent method would be enough to start and finish.
As for the second choice the hardest part is OpenGL API itself. It's procedural so if You're familiar mostly with Java You would have hard time using non-OO stuff. It can get used to and, to be honest, can be quite rewarding since You can do a lot with it. If you picked OpenGL than you would get all the 3D transformations for free, but still have to transform from spherical coordinate system to cartesian by yourself (first wiki article still helpful). After that it's just a matter of using some text drawing class, such as TextRenderer that comes with JOGL distribution.
So OpenGL helps You with view projection calculations and is hardware accelerated. The Java2D would require more math to use, but in my opinion, this approach seems a bit easier. Oh, and by the way - the Java2D tries to use any graphic acceleration there is (OpenGL or DirectDraw) internally. So You are shielded from certain low-level problems.
For both options You need also to bind mouse coordinates s to rotational speed of sphere. Whether it's Java2D or OpenGL the code will look very similar. Just map mouse coordinates related to the center of panel to some speed vector. At the drawing time You could use the vector to rotate the sphere accordingly.
And one more thing: if You would want to try OpenGL I'd recommend: Processing language created on MIT especially for rich graphic applets. Their 3D API, not so coincidentally, is almost the same as OpenGL, but without much of the cruft. So if You want the quickest prototype that's the best bet. Consult this discussion thread for actual example. Note: Processing is written in Java.
That's not really 3D. There are no perspective transformations or mapping the text on some 3D shape (such as, say, a sphere). What you have is a bunch of strings where each string has an associated depth (or Z order). Strings "closer" to you are painted with a stronger shade of gray and larger font size.
The motion of each string as you move the mouse is indeed a 3D shape which looks like a slanted circle around a fixed center - with the slant depending on where the mouse cursor is. That's simple math - if you figure it for one string, you figure it out for all. And then the last piece would be to scatter the strings so that they don't overlap too much, and give each one the initial weight based on their frequency.
That's what most of the code is doing. So you need to either do the math, or translate the ActionScript to Java2D blindly. And no, there is no need for JOGL.
Why don't you just download the source code, and have a look? Even if you can't write PHP, it should still be possible to read it and figure out how the algorithm works.

Categories

Resources