• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
chrisprij

Question about 3D render in Java

7 posts in this topic

I've been watching a 3D tutorial on youtube about doing 3D graphics in Java without any exterior libraries -- just standard Java. I've been curious about how 3D graphics work down at the lower levels; I've used Unity and openGL to make applications, and now I'm aiming to go a step deeper into my understanding of 3D graphics (I also am very intrigued into the mathematics behind it all). And here is where my question arises.

 

Below is a function in the Render3D class for the tutorial. Using what's written below, it takes two for loops to go through each pixel in the pixels array, and end up drawing a green and blue checkered pattern shown here:

 

[sharedmedia=core:attachments:13636]

 

public void floor() {

	for (int y = 0; y < height; y++) {

		double ceiling = (y - height / 2.0) / height;
		double z = 8 / ceiling;

		for (int x = 0; x < width; x++) {

			double depth = (x - width / 2.0) / height;
			depth *= z;
			int xx = (int) (depth) & 15;
			int yy = (int) (z) & 15;
			pixels[x + y * width] = (xx << 4)||(yy << 4)<< 8;
		}
	}
}

 

basically, I'm wondering if anyone has a good explanation for how this works or what the name of the algorithm is. I understand how this physically chooses what color to put in each pixel (by following through the code and printing out values), but how does this relate to rendering a 3D environment later on?

 

Thanks in advance! Let me know if more information is needed as well.

--Chris

0

Share this post


Link to post
Share on other sites

I understand how this physically chooses what color to put in each pixel (by following through the code and printing out values), but how does this relate to rendering a 3D environment later on?

That's rather vague and I'm not sure what you mean. Setting the pixels specifically to a color with an algorithm then drawing it still requires some kind of API, what you listed wouldn't draw anything by itself.

 

Not to mention 3d rendering in games is done with rasterization, which is you feeding vertices and other information to an API like openGL and letting it do all the math heavy work to convert it to screen pixels. There are many many, maaaaaaaany books on the subject of 3d graphics. Did you have a more specific question about the thing you've been watching?

1

Share this post


Link to post
Share on other sites

Satharis,

'Rendering' was the wrong word; I meant how does this set the pixels to later render and display a 3D environment. However I now understand vaguely how this algorithm works.

The pixels array is a reference to a Java Swing's screen of pixels, allowing me to set the pixels for the screen (through the buffers, that is). This render method gets called twice, once for the back buffer and once for for the third buffer, and every tick the buffers get pushed up one, and the back buffer gets pushed onto the screen. Anyways, I spent a few hours yesterday playing around with this algorithm and changing variables, and I found out how it works; it uses the y-pixel value to determine the depth on the screen. Then it uses AND's and shifts to determine the color. He later uses this same algorithm, with some minor changes, to print textures onto the 3D environment, using the following change to the last line of this algorithm:

 

pixels[x*y+width] = Textures.floor.pixels[(xx & 7) + (yy & 7) << 3];

 

 

which uses an 64 length array (8 x 8 texture) to color the pixels to the colors the texture uses, transforming the world into this:

 

Episode15.jpg

 

I've used openGL a few times before, and that's what I usually use, but I wanted to understand what openGL might do under the hood through practice, or see other ways of rendering. My question was this: what does this algorithm have to do with any regular algorithm for setting the pixels (done by openGL) given a 3D environment? I know this is still vague but I'm not sure how else to ask this. How does this method, or does this method, relate to anything openGL does (Any better? haha)? Later in the episodes he starts creating blocks and walls and they keep their x-y-z coordinates, but I'm not there yet. Maybe there's some words of wisdom by then? 

I also have a couple 3D graphics books from my university's library now that talk about the underlying information about how openGL works, and that should open up some knowledge about how this might work. I'm starting to think this was a premature question; I'll throw myself into this for a couple weeks to see if I get anything from it.

 

Thanks for your answer though!

--Chris

Edited by chrisprij
0

Share this post


Link to post
Share on other sites

Shadowisadog:

 

Now that you bring that up, would you be able to point out where in the algorithm above it performs a 3D projection? I'm guessing it has something to do with the whole x' = x/z * zoom, y' = y/z * zoom idea....

0

Share this post


Link to post
Share on other sites

Could you post the links to the videos you're watching.  I'd like to see what's going on here.

0

Share this post


Link to post
Share on other sites

The video's are here.

 

 

However he has a really weird time explaining things . . . he'll cover stuff like what an array is and so on (really basic java fundamentals), but he doesn't explain how his code works too well, hence my question!

 

-Chris

0

Share this post


Link to post
Share on other sites

Ah Ha! I found where he (the guy I was watching on youtube) got the algorithm, Notch used it in a Lundum Dare Competition a while back! It starts here if anyone is interested in seeing what's up. biggrin.png

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0