java - Method to create a cube in OpenGL -
how should x, y, z, sizex, sizey, sizez values put vertices make cube?
public static void cube(float x, float y, float z, float sx, float sy, float sz){ glpushmatrix(); { gltranslatef(x, y, z); //just 1 side of cube given due unnecessary code. glbegin(gl_quads); glvertex3f(-1, -1, 1); glvertex3f(1, -1, 1); glvertex3f(1, 1, 1); glvertex3f(-1, 1, 1); glend(); } glpopmatrix(); }
thanks.
wherever in code have e.g. glvertex3f(-1, -1, 1);
mulitply them corresponding value of sx, sy, sz divided 2 e.g. glvertex3f(-sx/2, -sy/2, sz/2);
for position can issue gltranslatef(x, y, z)
before drawing cube. if insist on hardcoding vertices should write above statement glvertex3f(x - sx/2, y - sy/2, z + sz/2);
Comments
Post a Comment