Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (623) 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 770 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: 354
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.

 ClaasJG (21 views) 2015-04-27 13:36:51 BurntPizza (33 views) 2015-04-23 03:42:11 theagentd (35 views) 2015-04-22 16:23:07 Riven (50 views) 2015-04-16 10:48:47 Duke0200 (59 views) 2015-04-16 01:59:01 Fairy Tailz (42 views) 2015-04-14 20:13:12 Riven (45 views) 2015-04-12 21:36:37 bus hotdog (61 views) 2015-04-10 02:39:32 CopyableCougar4 (66 views) 2015-04-10 00:51:04 BurntPizza (71 views) 2015-04-06 22:06:58
 theagentd 23x BurntPizza 17x wessles 15x kingroka123 11x alwex 11x 65K 11x kevglass 8x Rayvolution 7x Riven 7x chrislo27 7x Hanksha 7x Olo 7x Ecumene 7x ra4king 7x KevinWorkman 6x Spasi 6x
 How 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:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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