Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Help] Block Class Design  (Read 2253 times)
0 Members and 1 Guest are viewing this topic.
Offline deadteck

Senior Newbie





« Posted 2012-04-26 03:09:18 »

Hey everyone, im really needing a lot of help in creating a 3D block class, Ive been looking around for some time and I havent found anything that could really help me. This is my first 3D game and I dont really know what to add into the class, and is it possible to have it render from the actual block class, or does it have to be rendered in the render class? Any help would be really appreciated. Im also looking for a basic structure of a random world generator. Thanks a lot Cheesy

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline ReBirth
« Reply #1 - Posted 2012-04-26 13:34:42 »

Quote
does it have to be rendered in the render class?
Depends on your lib. Usually on libgdx I pass SpriteBatch to each class of this kind.

Offline deadteck

Senior Newbie





« Reply #2 - Posted 2012-04-26 15:22:03 »

Depends on your lib. Usually on libgdx I pass SpriteBatch to each class of this kind.
Im using lwjgl, and do you happen to know how to structure the class?

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-04-27 10:55:57 »

By structure you mean relation between class? well it's up to your game mechanism. Or you mean this single block class? just fill it with necessary fields and methods. With lwjgl, you can call static GL to draw from within your block class directly.

Offline deadteck

Senior Newbie





« Reply #4 - Posted 2012-04-27 18:09:46 »

By structure you mean relation between class? well it's up to your game mechanism. Or you mean this single block class? just fill it with necessary fields and methods. With lwjgl, you can call static GL to draw from within your block class directly.
Okay, and what type of fields and methods do you think I should incorporate, and do you happen to know how to make a cube with the same texture on all 6 sides?

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline ReBirth
« Reply #5 - Posted 2012-04-28 03:08:00 »

For coordinates, find a point/vector3d which will be used to all 6 sides. Your class hold it and also texture REFERENCE. Class's drawing method has to draw that texture 6 times with different position.

Offline deadteck

Senior Newbie





« Reply #6 - Posted 2012-04-28 14:30:21 »

For coordinates, find a point/vector3d which will be used to all 6 sides. Your class hold it and also texture REFERENCE. Class's drawing method has to draw that texture 6 times with different position.
Ahh okay, and how would you have it on an actual block place, and not in the miidlle of it

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline DavidW
« Reply #7 - Posted 2012-04-28 15:41:55 »

Have a 3D point which stores the block's location and translate to that location before you begin drawing.  Next, bind your texture and draw the six faces of the cube as quads (or two triangles if you prefer).  How you actually go about doing this really depends on how you implement drawing, but the basic idea is the same.  A cube has eight verticies:
1  
2  
3  
4  
5  
6  
7  
8  
(0.5, 0.5, 0.5)
(0.5, -0.5, 0.5)
(-0.5, -0.5, 0.5)
(-0.5, 0.5, 0.5)
(0.5, 0.5, -0.5)
(0.5, -0.5, -0.5)
(-0.5, -0.5, -0.5)
(-0.5, 0.5, -0.5)

You use these verticies to draw the quads.  Each face of the cube has one coordinate that is constant, so for instance, the four points
1  
2  
3  
4  
(0.5, 0.5, 0.5)
(0.5, -0.5, 0.5)
(-0.5, -0.5, 0.5)
(-0.5, 0.5, 0.5)

make up the front of the cube because they all have the same z coordinate.  You get the other five faces the same way.  If you don't want to use +/-0.5 for all the coordinates you don't have to, you could use 1 and 0, 1 and -1, or whatever you want.  I chose 0.5 because this will give you a cube of unit side length (each edge is one unit long) and centered at the origin (the point (0,0,0)).  Because you translated before drawing, the cube on the screen will be centered at (x, y, z) which is exactly what you want Smiley Just remember to translate back to the origin before drawing the next cube.

Hope this helps.

Hello!
Offline deadteck

Senior Newbie





« Reply #8 - Posted 2012-04-28 15:48:27 »

Ohh okay, so it would automatically draw the cube on the "space"

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (37 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (27 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!