making a 3d program

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)

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.

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.

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)



    @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(); 
                   
       

    } 

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.