Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  making a 3d program  (Read 527 times)
0 Members and 1 Guest are viewing this topic.
Offline Rakiayn

Senior Newbie





« Posted 2013-09-24 01:12:25 »

hello all

I need some advice on a project I am working on. (my second projects, so im quite noobish)
it is a small simulation game that consist out of a 3d world with cubes that affect each other by gravity and velocity.
the cubes rotate around each other like planets and stars.
everything works fine so far.

I set up (found on the internet and modified) a vertex buffer object and got things working fine. except the cubes never rotate around their axis.

I would like the cubes to be able to rotate in any random direction but im not sure how I should do this.
my first thought was to calculate each corner point of each cube according to its rotation (yaw, pith,roll)
but that seems kind of cpu intensive and not to mention kind of complicated to code ( rotation matrices ).
then I though maybe there is an other way to do this?

I would like to know your thought how I should make this.
the vertex array is not static btw. objects are removed and added add certain times.
als I would like some cubes to rotate around the center of a different cube ( when to cubes are attached to each other to form one object)




Offline HeroesGraveDev

JGO Kernel


Medals: 239
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-09-24 07:55:24 »

Take it one step at a time.

Get a cube working.
Get multiple cubes working.
Get the cubes rotating.
Get the cubes colliding.
Work out how to 'merge' cubes.

Offline StrideColossus
« Reply #2 - Posted 2013-09-24 10:45:01 »

Yes it would be quite complicated (and somewhat pointless) to continually re-calculate the vertices of each cube on the CPU - use a vertex shader.

If you're relatively au-fait with matrices then it's much simpler to pass the vertices and the rotation matrix for each cube to your shader and apply the rotation there, that's what vertex shaders are for.  Obviously this requires you to get to grips with shaders, but it's not much harder than implementing VBOs which you have already got to grips with.

This is a good tutorial for using shaders to do roughly what you're attempting:  http://www.arcsynthesis.org/gltut/Positioning/Tut03%20A%20Better%20Way.html  Will also be worth searching on this site for other guides and tutorials.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Rakiayn

Senior Newbie





« Reply #3 - Posted 2013-09-24 13:36:22 »

thanx , I will check out the vertex shader.

Edit: is it possible to rotate each cube individually by the glRotatef(a,b,c,d) method?
I tried this but ended up rotation every cube around the origin.

Edit2:   for now I want to do rotations in a simpler way , so I used the glrotatef method. only my code is not working.
Can someone tell me what I am doing wrong here?
attached is the code of the render function of the cubes (called in game loop)

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  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
    @Override
    public void render()
    {

        rotation_alpha = 45f;
       
       
        //set rotation and coordinates to origan
       GL11.glTranslatef(0,0,0);  
        GL11.glRotatef(0,0f,0f,0f);  
 
       
       
        GL11.glPushMatrix();
         
        //move matrix origan to coordinates of cube
       GL11.glTranslatef(x,y,z);
        //rotate cube
       GL11.glRotatef(rotation_alpha,1f,0f,0f);            
                     
        cx1 = x - xsize;
        cy1 = y - xsize;
        cz1 = z - xsize;  
       
        cx2 = x + xsize;
        cy2 = y - xsize;
        cz2 = z - xsize;          
       
        cx3 = x + xsize;
        cy3 = y + xsize;
        cz3 = z - xsize;          
       
        cx4 = x - xsize;
        cy4 = y + xsize;
        cz4 = z - xsize;        
       
        cx5 = x - xsize;
        cy5 = y - xsize;
        cz5 = z + xsize;  
       
        cx6 = x + xsize;
        cy6 = y - xsize;
        cz6 = z + xsize;          
       
        cx7 = x + xsize;
        cy7 = y + xsize;
        cz7 = z + xsize;          
       
        cx8 = x - xsize;
        cy8 = y + xsize;
        cz8 = z + xsize;        
       
       

        //front quad
       Draw.drawRect(cx1,cy1,cz1,cx2,cy2,cz2,cx6,cy6,cz6,cx5,cy5,cz5,red,green,blue,transparancy);
 
        //left quad
       Draw.drawRect(cx4,cy4,cz4,cx1,cy1,cz1,cx5,cy5,cz5,cx8,cy8,cz8,red,green,blue,transparancy);  
       
        //right quad
       Draw.drawRect(cx2,cy2,cz2,cx3,cy3,cz3,cx7,cy7,cz7,cx6,cy6,cz6,red,green,blue,transparancy);
       
        //back quad
       Draw.drawRect(cx4,cy4,cz4,cx3,cy3,cz3,cx7,cy7,cz7,cx8,cy8,cz8,red,green,blue,transparancy);
       
        //bottom quad
       Draw.drawRect(cx1,cy1,cz1,cx2,cy2,cz2,cx3,cy3,cz3,cx4,cy4,cz4,red,green,blue,transparancy);  
       
        //top quad
       Draw.drawRect(cx5,cy5,cz5,cx6,cy6,cz6,cx7,cy7,cz7,cx8,cy8,cz8,red,green,blue,transparancy);    
       
        //reset matrix rotation and position back to before matrix push        
       GL11.glPopMatrix();
                   
       

    }
Offline Rakiayn

Senior Newbie





« Reply #4 - Posted 2013-09-25 12:17:44 »

Ok, I know why it is not working. it is because I am doing all the conversion before they are actually drawn. Im using a vbo so everything gets drawn at the end all at once. I should have known this. looks like i have to study the matrices and the shaders.
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.

CogWheelz (15 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (17 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

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

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

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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
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!