Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (603) Games in Android Showcase (171) games submitted by our members Games in WIP (651) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 making a 3d program  (Read 892 times) 0 Members and 1 Guest are viewing this topic.
Rakiayn

Senior Newbie

 « Posted 2013-09-23 23: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)

HeroesGraveDev

JGO Kernel

Medals: 360
Projects: 11
Exp: 3 years

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

 « Reply #1 - Posted 2013-09-24 05: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.

StrideColossus
 « Reply #2 - Posted 2013-09-24 08: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.
Rakiayn

Senior Newbie

 « Reply #3 - Posted 2013-09-24 11: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();                               } `
Rakiayn

Senior Newbie

 « Reply #4 - Posted 2013-09-25 10: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.

 SHC (11 views) 2015-08-01 03:58:20 Jesse (17 views) 2015-07-29 04:35:27 Riven (38 views) 2015-07-27 16:38:00 Riven (19 views) 2015-07-27 15:35:20 Riven (22 views) 2015-07-27 12:26:13 Riven (12 views) 2015-07-27 12:23:39 BurntPizza (32 views) 2015-07-25 00:14:37 BurntPizza (43 views) 2015-07-24 22:06:39 BurntPizza (25 views) 2015-07-24 06:06:53 NoxInc (31 views) 2015-07-22 22:16:53
 theagentd 51x wessles 45x basil_ 35x orangepascal 27x KaiHH 26x ags1 21x Riven 19x mooman219 17x bornander 14x KudoDEV 13x princec 11x CelestialCreator 11x klaus 11x Jesse 11x Zaneris 9x pquiring 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 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