help manually roting vertices

hi there guys, firstly id like to say hello to all as this is my first post here :smiley:

so i have just recently gotten into 3d development in java and so far i have picked up pretty fast, the hardest part was probably setting up my environment, but as i have programed in ruby for a while i picked up java pretty fast as it is object orientated, any way enough of that to the issue!

so i am currently trying to rotate vertices manually, i know i can use the glRotate method to achieve rotation, but this is so i can use logical functions later to detect collision etc, in this case i am constructing a box,i have managed to sort of apply the rotation manually, but it seems to go a little crazy, it rotates, but doesnt rotate to the right angle, so here is my code that manages the box and drawing of it:


package com.game.base.uncatogorized.Graphics;

import static org.lwjgl.opengl.GL11.*;

public class Cube {

	public float xScale, yScale, zScale;
	
	public Cube(float xScale, float yScale, float zScale) {
		
		this.xScale = xScale;
		this.yScale = yScale;
		this.zScale = zScale;
		
	}
	
	public void draw(float x, float y, float z, float rotation) {
		float x1, y1, z1, rx, rz;
		
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glPushMatrix(); 
		{
			glTranslatef(0, 0, 0);
			glColor3f(1,0,0);  
			glBegin(GL_QUADS);
			{
				
				//FRONT FACE
				//BOTTOM LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//BOTTOM RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				
				//RIGHT FACE
				//BOTTOM LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//BOTTOM RIGHT
				x1 = x - ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP RIGHT
				x1 = x - ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				
				//BACK FACE
				//BOTTOM LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//BOTTOM RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				
				//LEFT FACE
				//BOTTOM LEFT
				x1 = x + ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//BOTTOM RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP LEFT
				x1 = x + ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				
				//TOP FACE
				//BOTTOM LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//BOTTOM RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y + ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				
				//BOTTOM FACE
				//BOTTOM LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//BOTTOM RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z - ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP RIGHT
				x1 = x + ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
				//TOP LEFT
				x1 = x - ((1 * xScale) / 2);
				y1 = y - ((1 * yScale) / 2);
				z1 = z + ((1 * zScale) / 2);
				rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
				rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
				glVertex3f(rx, y1, rz);
			}
			glEnd();
			
		}
		glPopMatrix();
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glColor3f(1,1,1);     
	}
	
}

i am currently only trying to rotate on the x and z, as you can see i am drawing the boxes in line mode, as that space will just represent impassable space, the reason i need it to rotate is so it rotates correctly with the object that it is bound around, ie. a character, then this box will act as the characters collider

also on the matter is this a good way to go about generating a collision area? i know about the physics library jbullet but that is a bit of an overhaul for what i require, anyway let me know if anyone knows how i can solve this :slight_smile:

You need to learn matrices:
http://tomdalling.com/blog/modern-opengl/03-matrices-depth-buffering-animation/

I’d also not recommend immediate mode for 3D geometry, as you’ll quickly run into some performance problems. At a very least, use simple vertex arrays, or for better performance, use an interleaved VBO to hold static data.