3d - How to draw cuboids by defining offsets correctly in OpenGL? -
i facing following problem:
- i want draw multiple cuboids representing items packed in container , 1 cuboid representing container. have algorithm packs container items , outputs boxes dimensions (and x,y,z offsets)
i have following input data example:
- container dimensions (width 10, length 10, height 10)
- box1: [width=2, length=2, height=2] position=[x=5, y=4, z=0]]
- box2: [width=4, length=4, height=4] position=[x=5, y=0, z=0]]
- box3: [width=5, length=5, height=5] position=[x=0, y=0, z=0]]
the solution should this:
- use opengl beginmode quads draw cuboids.
- start @ x=0, y=0, z=0 , draw container cuboid width, height , length.
- start @ x=boxpositionx, y=boxpositiony, z=boxpositionz draw each of boxes cuboids.
my problems are:
- how can tell opengl if use drawcuboid function example width=10,height=10 , length=10 should start x=0,y=0,z=0 , draw x=width,y=height,z=length , not go -x,-y , -z coordinates?
- how can apply x-shift,y-shift , z-shift correctly?
to draw cuboids use following code (attention: use opentk opengl c# wrapper please dont try compile opengl libraries):
... // use "wireframe mode" gl.polygonmode(materialface.frontandback, polygonmode.fill); // precalc length = (float)length / (float)650f; height = (float)height / (float)650f; width = (float)width / (float)650f; //side 1 gl.vertex3(width, height, -length); gl.vertex3(-width, height, -length); gl.vertex3(-width, height, length); gl.vertex3(width, height, length); gl.end(); // side 2 gl.vertex3(width, -height, length); gl.vertex3(-width, -height, length); gl.vertex3(-width, -height, -length); gl.vertex3(width, -height, -length); // side 3 gl.vertex3(width, height, length); gl.vertex3(-width, height, length); gl.vertex3(-width, -height, length); gl.vertex3(width, -height, length); // side 4 gl.vertex3(width, -height, -length); gl.vertex3(-width, -height, -length); gl.vertex3(-width, height, -length); gl.vertex3(width, height, -length); // side 5 gl.vertex3(-width, height, length); gl.vertex3(-width, height, -length); gl.vertex3(-width, -height, -length); gl.vertex3(-width, -height, length); // side 6 gl.vertex3(width, height, -length); gl.vertex3(width, height, length); gl.vertex3(width, -height, length); gl.vertex3(width, -height, -length); ... any appreciated!
Comments
Post a Comment