Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) 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 1861 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: 382
Projects: 11
Exp: 4 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

 ivj94 (585 views) 2018-03-24 14:47:39 ivj94 (49 views) 2018-03-24 14:46:31 ivj94 (383 views) 2018-03-24 14:43:53 Solater (63 views) 2018-03-17 05:04:08 nelsongames (110 views) 2018-03-05 17:56:34 Gornova (159 views) 2018-03-02 22:15:33 buddyBro (704 views) 2018-02-28 16:59:18 buddyBro (92 views) 2018-02-28 16:45:17 xxMrPHDxx (494 views) 2017-12-31 17:17:51 xxMrPHDxx (734 views) 2017-12-31 17:15:51
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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