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

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.

Related

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.

Java/Graphics: Plotting 3d coordinates?

I'm coding a programm, that will produce 3d coordinates for a rocket and I would like to do a rudimentally graphic output for this.
it just has to be scaleable and rotationable, so that you can change the view manually.
the postions should be connected by lines and
it ould be nice to have spheres for earth and moon ( and perhaps addtional celestial objects).
I think, there should be some ready stuff for this kind of plott already available, but I couldn't find one.
So that's why I'm here to ask you, if you know such a thing.
and if there isn't I would kike to ask you how a bignner like me should start this?
I ust coded for console apllications, because there was no need for a real graphics output.
thank you in advance for any tip! :)
Andreas
I don't think there are sand-box ready things you can use to draw customizable 3d objects in Java, if you can live without strange things you can you just a graph library able to draw 3d graphs like for example jMathTools (link).. otherwise you should go into J3D with opengl and similar things.
I don't think they exist just because doing simple things is trivial if you work with OpenGL or similar APIs..
Doing what you need with OpenGL is not complex at all, just a GL_LINE_STRIP to draw the trajectory and some primitives if you need earth, moon and so on.. rotating and scaling come implicitly moving the camera of your viewport..
Take a look at: Java3D or JOGL
I can't believe nobody has mentioned this yet, but the NASA WorldWind project seems like exactly what you need: http://worldwind.arc.nasa.gov/java/ You can extend it with JOGL if needed, or you can use some of the vast modeling objects already available to mark trajectory and location in 3D coordinates, complete with zooming/rotating and the like. Having accurate Earth layers is nice as well =)
Use JOGL! It is easy to install, and if you know Java it should be easy. There are a few things in JOGL that require you to be decent in trigonometry. This tutorial might help you get started: http://www.youtube.com/watch?v=rT02jFYrXv0

Do I need to use OpenGL in my 2D Java sim game?

I have recently been developing a sim game in java, as many of my questions show, and it's come a long way! Graphically, it is somewhat lacking, and at current I'm using shapes for items, people, rooms etc.
I was looking at other similar projects, and noticed that one was using OpenGL. I have been reading CokeAndCode "space invaders 103 - refactoring and OpenGL", and I still don't know if it is something I need in my game or not.
Here is a video that I used for a previous question, but it still shows basically what I have so far (http://www.screenjelly.com/watch/Bd7d7pObyFo), although I have done a lot of refactoring and re coding over the last few weeks, but graphically, nothing has changed. As I understand it, I'm currently using java2D to do this.
I really don't know how I should continue graphically with this game. This is my first project I have done outside of learning for my own enjoyment, and so I'm still rather new to this.
Thanks in advance!
This could turn into a long subjective conversation quickly but I want to state the fact that you don't need openGL. Your application doesn't need to be the best looking one out there. Nethack still attracts people and between you and me : the graphics sucks.
Do you want to learn about 2D and 3D graphics and textures and so on ? Then try stuff... best way to learn. Then you can add this to your resume.
There are a lot of tutorial to do your first steps in OpenGL or some other graphic library. You can even try Qt Jambi. But once you start, you're in for a ride ;)
According to this, it's still largely possible to implement a working graphical game in Java2D with decent performance, as long as you make sure not to do a certain number of bad things.
It might help you to check and see how your approach is, compared to this.
I have no idea how far along Java has come with OpenGL support, so were I in your place I would probably just see how much refactoring of the Java2D code I could do, and figure out what to do from there.
Hope this helps, at least a bit.
One good side of using opengl (even for 2D graphics) is that you will get (if properly done) hardware graphics acceleration for your scenes.
Also, you can use orthogonal projection and keep one of the axis (Z) as zero to do your 2D graphics. It will be easy if you want to add a 3D effect (like lightning or something) if you use OpenGL.
However it all depends on how much you want to improve the graphics, since adding OpenGL might make things a little more complicated than plain Java2D.
How to continue graphically: use textures, more interesting animations (implement a simple physics engine and/or collision detection, that always looks nice).
When you go 3d (for example using opengl) you can add lighting effects to the equation, that usually does a lot to the aesthetics of the whole. For example if the moving circle was a sphere with a nice texture (marble or something), then you could make it really role over the board, and you could specify diffuse and specular reflection values to vary the lighting like for example here.
Camera movement can also beef up the graphics.

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.

Porting easily from 2D to 3D on a Java game

Due to lack of capital and time we are having to do our game in 2D even though me (the developer) would prefer if it was done in 3D. I would hate for users to join the game, only to think the graphics look bad and leave. Though I suppose we just have to try and do our best.
That being said, I would like to develop the game in such a way that, should the time come, we can port to 3D as easily as possible. I know of games that had to rewrite the entire thing from scratch. I'd hate to do that, so I'd like some tips / guidelines to use when programming the game so that, when we move to 3D, it will be as simple as changing the code of 1-5 graphics rendering classes (or close) and the 3D graphics would run.
P.S It is a multiplayer roleplaying game (Not an MMORPG, much smaller in scope for now)
The simplest way to achieve this is to write the game in 3D, and render the views using a 3d to 2d projection, e.g. in plan or elevation. If the games internal mechanics are 2D and you try to move to a true 3d frame, you would probably better off with a rewrite. It also depends to an extent on what you mean by 3D, and whether you have an effective mapping option. For example, Microsofts Age of Empires is rendered in 3D, but would work perfectly well as a 2D plan. A first person shooter such as Half Life or Quake on the other hand would not.
Due to lack of capital and time we are
having to do our game in 2D even
though me (the developer) would prefer
if it was done in 3D. I would hate for
users to join the game, only to think
the graphics look bad and leave.
Though I suppose we just have to try
and do our best.
I don't think everything has to be 3D to look good. Well done 2D can look many times better than some standard 3D graphics. To have great 3D graphics you have to invest some serious effort. If your budget doesn't allow for this, I would rather try to put a lot effort into gameplay development.
Just think of (somewhat dated) Diablo II which is not 3D but still has some nice and good looking graphics.
It is certainly possible to build an architecture which could make it easier to change the graphical representation, but I think it will almost never be as simple as you described. Of course, if you just want 3D for the sake of 3D it could be done (instead of bitmaps you now render 3D models) but this is somewhat pointless. If you want to use 3D the player should be able to make use of it (e.g. by moving the camera, having more degrees of freedom, ...) but this would have to be considered in the whole design of the game and thus seriously affects gameplay.
You can use the GL ortho view. This will allow you to draw on screen using only 2D coordinates, if you want 3D later on, switch from Ortho to Perspective view and you have 3D, however i don't think it will help you reuse the code, since the 2D ortho view is usually done with textures, and you cannot transform a texture to a 3D mesh.
Maybe a better approach is to do everything in 3D, and setup your camera to look from above, if you do that later you can switch to 3D just by relocating the camera and making better models and textures. This options sounds nicer but gives you more work with the trade-off 2D to 3D portability without code changes.
An MVC pattern should help.
And I guess you're aware already, but have you looked at Java3D? Perhaps having a plug replaceable 3D rendering view based on that (but which is not necessarily polished and production ready) will keep you honest so that you don't wind up tied to 2D in some horrible way. It could be as simple as rendering your 2D stuff with some Z positioning added.

Categories