Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  3D noob  (Read 2231 times)
0 Members and 1 Guest are viewing this topic.
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Posted 2009-09-11 01:57:53 »

So far I've done a bit of 2D stuff with LWJGL. I like 2D because development is fast. However, I'd like to start incorporating some 3D effects in my 2D games. I think this is a good first step and eventually I might end up doing a fully 3D game.

I don't really know where to start. For my first goal, I'd like to make a spinning spiked ball (like the ball from a mace). Should I start by making a box spin and then replace the box with a spiked ball? How would I make the spiked ball? I have Maya, is that a good tool to use for this? After I create my spiked ball (which should be a relatively easy model to make) how do I get it into LWJGL?

I should also note that I plan to do development for both the desktop and Android, so I'd like to keep the OpenGL bits as simple as possible. Eg, I don't want to use something like jMonkeyEngine, since that is not available for Android (which, for the most part, only has OpenGL ES 1.0).

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #1 - Posted 2009-09-11 09:08:10 »

Quote
Should I start by making a box spin and then replace the box with a spiked ball?
I think it is a good idea to get use of the 3D functions. There is GLU function to create cube and sphere.

Quote
How would I make the spiked ball? I have Maya, is that a good tool to use for this?
Yes, Maya, Blender, Milkshape, ... anything is good  Grin

Quote
After I create my spiked ball (which should be a relatively easy model to make) how do I get it into LWJGL?
When done, export your spiked ball to ".obj" file format. It is a text file format that it is easy to do an importer.

Quote
I don't want to use something like jMonkeyEngine, since that is not available for Android (which, for the most part, only has OpenGL ES 1.0).
I drop using JMonkey too. I do my own engine but it take a LOT of time (and it will be difficult to make all functionality). What I really want is a OpenGL ES binding in LWJGL, I will make an OpenGL/OpenGL ES engine easier  Wink
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #2 - Posted 2009-09-12 00:18:24 »

I created a simple spiked ball with Maya. I lifted some simple code to parse the OBJ text format and managed to get my model rendered with LWJGL. Sweet!

My render code looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
FloatBuffer position = BufferUtils.createFloatBuffer(4);
position.put(new float[] {0.0f, 0.0f, 800.0f, 0.0f}).flip();
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, position);
GL11.glEnable(GL11.GL_LIGHT0);

FloatBuffer red = BufferUtils.createFloatBuffer(4);
red.put(new float[] {0.8f, 0.1f, 0.0f, 1.0f}).flip();
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red);

GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_LIGHTING);

GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glFrustum(-1, 1, -1, 1, 30f, 500.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glTranslatef(0.0f, 0.0f, -290.0f);

FloatBuffer projection = BufferUtils.createFloatBuffer(128);
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);

FloatBuffer modelview = BufferUtils.createFloatBuffer(128);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);

IntBuffer viewport = BufferUtils.createIntBuffer(128);
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);

FloatBuffer winPos = BufferUtils.createFloatBuffer(3);
GLU.gluProject(800, 600, 1f, modelview, projection, viewport, winPos);
float xs = 800 / winPos.get(0);
float ys = 600 / winPos.get(1);
float zs = 1 / winPos.get(2);
GL11.glScalef(xs, ys, zs);

GL11.glRotatef(rotation, 0, 1, 1);

obj.draw();


I'm trying to use gluProject so (for example) I can model an object with a width of 60 and when I render it to the screen it will be 60 pixels wide. The above works, however I found the values for glFrustum mostly through trial and error. I found if I change zNear to 5f instead of 30f that my object is rendered 3 to 4 pixels too small. Can anyone help me understand why this occurs and also how I should know what values to plug in to glFrustum?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #3 - Posted 2009-09-14 09:43:23 »

FloatBuffer projection = BufferUtils.createFloatBuffer(128);
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);

FloatBuffer modelview = BufferUtils.createFloatBuffer(128);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);

IntBuffer viewport = BufferUtils.createIntBuffer(128);
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);

128 ?  Huh

Beside that you seem to use a amfully complicated solution  Smiley
1  
2  
3  
4  
5  
6  
7  
   
    GL11.glViewport(viewport_x, viewport_y, viewport_w, viewport_h);
    GL11.glMatrixMode(GL11.GL_PROJECTION) ;
    GL11.glLoadIdentity();
    GLU.gluPerspective(fovy,(float)viewport_w/(float)viewport_h, zNear ,zFar);      
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();


For gluPerspective, you can use fovy = 45°, viewport_x = 0, viewport_y=0, viewport_w = 800, viewport_h = 600, zNear = 1, zFar=1000.

I didn't try but give a try to :
- scale the object by 100
- translate by -100*zNear


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.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (19 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!