rt300@0: // rt300@0: // 3DboxGL.cpp rt300@0: // tweakathlon rt300@0: // rt300@0: // Created by Robert Tubb on 17/04/2014. rt300@0: // rt300@0: // rt300@0: rt300@0: #include "3DboxGL.h" rt300@0: rt300@0: rt300@0: Leap3DBoxGL::Leap3DBoxGL(float ax, rt300@0: float ay, rt300@0: float awidth, rt300@0: float aheight, rt300@0: float azx, rt300@0: float azy, rt300@0: const UIProps& props) : rt300@0: Leap3DBox(ax,ay,awidth, aheight, azx, azy, props) rt300@0: { rt300@0: indicatorColor = ofColor(123, 123, 220); rt300@0: // how much to rotate the box rt300@31: angleX = -25; // elevation rt300@32: angleY = 0; // yaw rt300@0: rt300@0: depth = width; // its a cube rt300@0: rt300@0: // where is the camera rt300@26: camTrans = 250; rt300@0: rt300@0: // cube is centred on 0,0,0 rt300@0: float I = width/2; rt300@0: float O = -width/2; rt300@0: rt300@0: // left face x=O rt300@0: // back face z=O rt300@0: // top face y=O rt300@0: rt300@0: // positions of vertices rt300@0: ofPoint ltf = ofPoint( O,O,I ); rt300@0: ofPoint lbf = ofPoint( O,I,I ); rt300@0: ofPoint rtf = ofPoint( I,O,I ); rt300@0: ofPoint rbf = ofPoint( I,I,I ); rt300@0: rt300@0: ofPoint ltr = ofPoint( O,O,O ); rt300@0: ofPoint lbr = ofPoint( O,I,O ); rt300@0: ofPoint rtr = ofPoint( I,O,O ); rt300@0: ofPoint rbr = ofPoint( I,I,O ); rt300@0: rt300@0: // now build faces rt300@0: // rear rt300@32: makeTexFace(&boxMesh, rtr, ltr, lbr, rbr); rt300@0: rt300@0: rt300@0: // boxMesh.addVertex(ltr); rt300@0: // boxMesh.addVertex(rtr); rt300@0: // boxMesh.addVertex(rbr); rt300@0: // rt300@0: // boxMesh.addVertex(ltr); rt300@0: // boxMesh.addVertex(rbr); rt300@0: // boxMesh.addVertex(lbr); rt300@0: rt300@32: // left rt300@32: makeTexFace(&boxMesh, ltr, ltf, lbf,lbr); rt300@32: rt300@32: // boxMesh.addVertex(ltf); rt300@32: // boxMesh.addVertex(ltr); rt300@32: // boxMesh.addVertex(lbr); rt300@32: // rt300@32: // boxMesh.addVertex(ltf); rt300@32: // boxMesh.addVertex(lbr); rt300@32: // boxMesh.addVertex(lbf); rt300@32: rt300@32: // bottom rt300@32: makeTexFace(&boxMesh, lbr, lbf, rbf,rbr); rt300@32: rt300@32: // boxMesh.addVertex(lbf); rt300@32: // boxMesh.addVertex(lbr); rt300@32: // boxMesh.addVertex(rbr); rt300@32: // rt300@32: // boxMesh.addVertex(lbf); rt300@32: // boxMesh.addVertex(rbr); rt300@32: // boxMesh.addVertex(rbf); rt300@32: rt300@32: rt300@0: boxMesh.setupIndicesAuto(); rt300@25: setNormals(boxMesh); rt300@0: } rt300@0: rt300@0: rt300@0: //-------------------------------------------------------------- rt300@0: rt300@0: void setNormals( ofMesh &mesh ) rt300@0: rt300@0: { rt300@0: //The number of the vertices rt300@0: int nV = mesh.getNumVertices(); rt300@0: rt300@0: //The number of the triangles rt300@0: int nT = mesh.getNumIndices() / 3; rt300@0: rt300@0: vector norm( nV ); rt300@0: rt300@0: //Array for the normals rt300@0: //Scan all the triangles. For each triangle add its rt300@0: //normal to norm's vectors of triangle's vertices rt300@0: rt300@0: for (int t=0; t