box()

Shape / 3D Primitives

Description

A box is an extruded rectangle. Use in P3D mode. A box with equal dimensions is a cube.

Syntax

void box(float size) void box(float w, float h, float d)

Parameters

NameTypeDescription
sizefloatdimension of the box in all directions
wfloatwidth
hfloatheight
dfloatdepth

Returns

void

Related

Under the Hood

From Processing.h:

void box(float size); void box(float w, float h, float d); inline void PGraphics::box(float size) { if(PApplet::g_papplet) PApplet::g_papplet->box(size); } inline void PGraphics::box(float w, float h, float d) { if(PApplet::g_papplet) PApplet::g_papplet->box(w,h,d); }

Under the Hood

From Processing.cpp:

void PApplet::box(float s){box(s,s,s);} void PApplet::box(float s){box(s,s,s); void PApplet::box(float bw,float bh,float bd){ { GLint curFbo=0; glGetIntegerv(GL_FRAMEBUFFER_BINDING,&curFbo); GLboolean depthOn = glIsEnabled(GL_DEPTH_TEST); GLint depthFunc=0; glGetIntegerv(GL_DEPTH_FUNC, &depthFunc); GLboolean depthMask; glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask); GLint vp[4]; glGetIntegerv(GL_VIEWPORT, vp); PDEBUG("PApplet::box(%.1f,%.1f,%.1f) ENTRY: doFill=%d fillR=%.3f fillG=%.3f fillB=%.3f curFbo=%d\n", bw,bh,bd, doFill, fillR, fillG, fillB, curFbo); PDEBUG(" depthTest=%d depthFunc=0x%x depthWriteMask=%d viewport=(%d,%d,%d,%d)\n", depthOn, depthFunc, depthMask, vp[0], vp[1], vp[2], vp[3]); } float hw=bw/2,hh=bh/2,hd=bd/2; struct Face{ float nx,ny,nz; float v[4][3]; }; Face faces[]={ { 0, 0, 1,{{-hw,-hh,hd},{hw,-hh,hd},{hw,hh,hd},{-hw,hh,hd}}}, { 0, 0,-1,{{hw,-hh,-hd},{-hw,-hh,-hd},{-hw,hh,-hd},{hw,hh,-hd}}}, {-1, 0, 0,{{-hw,-hh,-hd},{-hw,-hh,hd},{-hw,hh,hd},{-hw,hh,-hd}}}, { 1, 0, 0,{{hw,-hh,hd},{hw,-hh,-hd},{hw,hh,-hd},{hw,hh,hd}}}, { 0,-1, 0,{{-hw,-hh,-hd},{hw,-hh,-hd},{hw,-hh,hd},{-hw,-hh,hd}}}, { 0, 1, 0,{{-hw,hh,hd},{hw,hh,hd},{hw,hh,-hd},{-hw,hh,-hd}}}, }; if(doFill){ applyFill(); glBegin(GL_QUADS); for(auto& f:faces){ glNormal3f(f.nx,f.ny,f.nz); for(auto& v:f.v) glVertex3f(v[0],v[1],v[2]); } glEnd(); { GLenum err = glGetError(); PDEBUG("PApplet::box() AFTER glEnd(): glError=0x%x firstFaceVertex=(%.1f,%.1f,%.1f)\n", err, faces[0].v[0][0], faces[0].v[0][1], faces[0].v[0][2]); } } if(doStroke){ applyStroke();glLineWidth(strokeW); float vx[]={-hw,-hw,hw,hw,-hw,-hw,hw,hw}; float vy[]={-hh,hh,hh,-hh,-hh,hh,hh,-hh}; float vz[]={hd,hd,hd,hd,-hd,-hd,-hd,-hd}; int e[][2]={{0,1},{1,2},{2,3},{3,0},{4,5},{5,6},{6,7},{7,4},{0,4},{1,5},{2,6},{3,7}}; glBegin(GL_LINES); for(auto& ee:e){glVertex3f(vx[ee[0]],vy[ee[0]],vz[ee[0]]);glVertex3f(vx[ee[1]],vy[ee[1]],vz[ee[1]]);} glEnd(); restoreLighting(); } }