SlideShare a Scribd company logo
openFrameworks
      3D
3D

 ofNode     ofMesh   of3dUtils




ofCamera




ofEasyCam
ofCamera


Camera movement and matrices

• Extends from ofNode
• Basic GLUT camera functions
• Coordinate conversions
ofCamera


Frustum setup
                        angle of field of view in y direction, in degrees
     setFov(float)
                                            (45-60)

   setNearClip(float)             near clipping plane distance

   setFarClip(float)             set far clipping plane distance
ofCamera

Perspective and modelview matrices

        getProjectionMatrix()        Ortho / Perspective


       getModelViewMatrix()          Position/Orientation

   getModelViewProjectionMatrix()   Modelview * Projection
ofCamera


Coordinate conversion
    worldToScreen()      Convert openGL world to screen

    screenToWorld()        Convert screen to GL world

   worldToCamera()          Convert world to camera

   cameraToWorld()          Convert camera to world
ofCamera
               testApp.h




class testApp : public ofBaseApp{

 public:

 
      ...

 
      ofCamera cam;

 
};
ofCamera
                           testApp.cpp




void testApp::setup(){

 ofBackground(33,33,33);

 cam.setNearClip(0.1);

 cam.setFarClip(100);

    // "1 meter" to the right, "5 meters" away from object
    cam.setPosition(ofVec3f(1,0,5));
}




void testApp::draw(){

 cam.begin();

 
      glPointSize(10);

 
      glBegin(GL_POINTS);

 
      
   glVertex3f(0,0,0);

 
      glEnd();

 cam.end();
}
ofNode
ofNode

3D object container

• Standard 3D scene item
• Manage position, scale and orientation
• Lots of fantastic helper functions
• ofCamera extends from this class
ofNode


Movement
       truck()             Move left to right (x-axis)

      boom()              Move up and down (y-axis)

       dolly()        Move forward and backward (z-axis)

    setPosition()             Set position directly
ofNode

Rotation
         tilt()             Rotate around x-axis

         pan()              Rotate around y-axis

        dolly()             Rotate around z-axis

     rotate(a,axis)      Rotate around arbitrary axis
ofNode

Testing movement/orientation
                             Apply ofNode transformation (does a
     transformGL()
                                glPushMatrix/glMultMatrixf())

                         Does a glPopMatrix, call after transformGL and
  restoreTransformGL()
                                           drawing.

    resetTransform()          Resets the orientation and position
ofNode
void setScale(float s)

void setScale(float x, float y, float z)

void setScale(const ofVec3f& p)


void setPosition(float x, float y, float z)

void setPosition(const ofVec3f& p)

void setGlobalPosition(float x, float y, float z)

void setGlobalPosition(const ofVec3f& p)


void setOrientation(const ofQuaternion& q)

void setOrientation(const ofVec3f& eulerAngles)

void setGlobalOrientation(const ofQuaternion& q)
ofNode

Custom 3D nodes

• Create custom class and inherit from ofNode
• Implement virtual customDraw(void) member
  function.

• To draw, just call draw(void) on instance
ofNode
                Extend ofNode




class MyCustom3DNode : public ofNode {
public:

 virtual void customDraw() {

 
   ofSphere(0,0,0,0.7);

 
   ofDrawAxis(2
 );

 }
};
ofEasyCam


Camera interaction made easy

     begin()/end()       Put your draw calls between these

   setTarget(ofNode)        Follow and look at a target
ofEasyCam
        Custom ofNode - example ofEasyCam




class MyCustom3DNode : public ofNode {
public:

 virtual void customDraw() {

 
     ofSphere(0,0,0,0.7);

 
     ofDrawAxis(2);

 }
};

class testApp : public ofBaseApp{


    public:

    
    ofEasyCam easy_cam;

    
    vector<MyCustom3DNode*> custom_nodes;

    
    MyCustom3DNode* mover;
};
ofEasyCam
           Custom ofNode - example ofEasyCam



void testApp::setup(){

 ofBackground(33,33,33);


   // set distance of camera "5" meters away

   easy_cam.setDistance(5);


   // create a bunch of custom 3D nodes

   float r = 4;

   for(int i = 0; i < 10; ++i) {

   
     MyCustom3DNode* node = new MyCustom3DNode();

   
     node->setPosition(

   
     
    cos((float)i/10*TWO_PI) * r

   
     
    ,sin((float)i/10*TWO_PI) * r

   
     
    ,-5

   
     );

   
     custom_nodes.push_back(node);

   
     mover = node;

   }


   // set target for camera

   easy_cam.setTarget(*mover);
}
ofEasyCam
                   Custom ofNode - example ofEasyCam




void testApp::draw(){

 easy_cam.begin();

 
      // draw custom nodes.

 
      for(int i = 0; i < custom_nodes.size(); ++i) {

 
      
    custom_nodes[i]->draw();

 
      }

 

 
      // move over x-axis.

 
      float truck_amount = sin(ofGetElapsedTimef()*0.5) * 0.001;

 
      mover->truck(truck_amount);

 easy_cam.end();
}
ofMesh

Container for all vertex related data

•   Use this when working with 3D meshes. It creates a model that is used
    by openGL to draw 3D shapes.

•   Future proof (ready for modern openGL)

•   Clean API for most used data:
    add[Vertex,Color,TexCoord]()

•   Nice interface for writing 3D exports (OBJ, PLY)

•   Use this with Vertex Buffer Objects (VBO)
ofMesh
Adding vertices
          addVertex(ofVec3f)             Add one vertex

      addVertices(vector<ofVec3f>&)    Reference to ofVec3f
      addVertices(ofVec3f*, int num)    Pointer to vertices
          setVertex(int index)          Remove by index


Remove vertices
        removeVertex(int index)         Remove by index

            clearVertices()            Remove all vertices


Get vertex
             getVertex(int)              Get one vertex
ofMesh
Adding normals
         addNormal(ofVec3f&)             Add a normal

      addNormals(vector<ofVec3f>)    Add vector of normals
       addNormals(ofVec3f*, int)     Add array of normals
        setNormal(int, ofVec3f&)    Set one normal by index




Removing normals
         removeNormal(int)             Remove by index

           clearNormals()             Remove all normals



Retrieving normals
           getNormal(int)            Get normal by index
ofMesh
Adding indices
         addIndex(ofIndexType)              Add a index

     addIndices(const<ofIndextype>&)   Add a bunch of indices
       addIndices(ofIndexType*,int)    Add bunch of indices
        setIndex(int, ofIndexType)      Set a specific index




Removing indices
          removeIndex(int i)             Remove by index

            clearIndices()               Remove all indices



Retrieving indices
             getIndex(int)             Get index by index ;-)
ofMesh
Adding colors
         addColor(const ofFloatColor& c)                Add a index

      addColors(const<ofFloatColor>& cols)         Add a bunch of indices
    addColors(const ofFloatColor* cols, int amt)   Add bunch of indices
     setColor(int index, const ofFloatColor& c)     Set a specific index




Removing colors
            removeColor(int index)                   Remove by index

                 clearColors()                       Remove all indices



Retrieving colors
        ofFloatColor getColor(int i)               Get index by index ;-)
ofMesh
Useful for GL_ARRAY_BUFFER / VBO
            getNumVertices()               Total number of vertices

             getNumColors()                 Total number of colors

          getNumTexCoords()             Total number of texture coords

            getNumIndices()                Total number of indices



        float* getVerticesPointer()       Get a pointer to the vertices

        float* getColorsPointer()          Get a pointer to the colors

       float* getNormalsPointer()        Get pointer to stored normals

   ofIndexType* getTexCoordsPointer()      Get pointer to texcoords
ofMesh

Same API for the rest
• Same API for Colors, TexCoord

•   Helper function addTriangle(int,int,int)
Create two planes                   testApp.cpp
                                    void testApp::setup(){

                                    
   // bottom
                                    
   cube.addVertex(ofVec3f(-1,0,1));
                                    
   cube.addVertex(ofVec3f(1,0,1));
                                    
   cube.addVertex(ofVec3f(1,0,-1));
                                    
   cube.addVertex(ofVec3f(-1,0,-1));
                                    
                                    
   // top
                                    
   cube.addVertex(ofVec3f(-1,1,1));
                                    
   cube.addVertex(ofVec3f(1,1,1));
                                    
   cube.addVertex(ofVec3f(1,1,-1));
                                    
   cube.addVertex(ofVec3f(-1,1,-1));

                                    
                                    
   // triangles bottom
                                    
   cube.addIndex(0);
                                    
   cube.addIndex(1);
                                    
   cube.addIndex(2);
                                    
   cube.addIndex(2);
                                    
   cube.addIndex(3);
testApp.h                           
   cube.addIndex(0);
                                    
class testApp : public ofBaseApp{
                                    
   // triangles top
                                    
   cube.addIndex(4);

 public:
                                    
   cube.addIndex(5);

 
    ofMesh cube;
                                    
   cube.addIndex(6);
};
                                    
   cube.addIndex(6);
                                    
   cube.addIndex(7);
                                    
   cube.addIndex(4);
                                    
                                    }
Create a cube                       testApp.cpp

                                     void testApp::setup(){
                                     
 // bottom vertices
                                     
 cube.addVertex(ofVec3f(-1,0,1));
                                     
 cube.addVertex(ofVec3f(1,0,1));
                                     
 cube.addVertex(ofVec3f(1,0,-1));
                                     
 cube.addVertex(ofVec3f(-1,0,-1));
                                     
                                     
 // top vertices
                                     
 cube.addVertex(ofVec3f(-1,1,1));
                                     
 cube.addVertex(ofVec3f(1,1,1));
                                     
 cube.addVertex(ofVec3f(1,1,-1));
                                     
 cube.addVertex(ofVec3f(-1,1,-1));

                                     
   // indices
                                     
   cube.addTriangle(0,1,2);   // bottom
                                     
   cube.addTriangle(2,3,0);
                                     
   cube.addTriangle(4,5,6);   // top
                                     
   cube.addTriangle(6,7,4);
                                     
   cube.addTriangle(0,4,5);   // front
                                     
   cube.addTriangle(0,1,5);
testApp.h                            
   cube.addTriangle(1,2,6);   // right
                                     
   cube.addTriangle(6,5,1);
class testApp : public ofBaseApp{    
   cube.addTriangle(2,6,3);   // back
                                     
   cube.addTriangle(3,7,6);

 public:                            
   cube.addTriangle(0,3,7);   // left

 
    ofMesh cube;                  
   cube.addTriangle(7,4,0);
};                                   }
roxlu
www.roxlu.com

More Related Content

KEY
openFrameworks 007 - GL
KEY
openFrameworks 007 - graphics
KEY
openFrameworks 007 - video
KEY
openFrameworks 007 - utils
PDF
Dynamic C++ ACCU 2013
PPT
Евгений Крутько, Многопоточные вычисления, современный подход.
PDF
Антон Бикинеев, Writing good std::future&lt; C++ >
PDF
Standford 2015 week3: Objective-C Compatibility, Property List, Views
openFrameworks 007 - GL
openFrameworks 007 - graphics
openFrameworks 007 - video
openFrameworks 007 - utils
Dynamic C++ ACCU 2013
Евгений Крутько, Многопоточные вычисления, современный подход.
Антон Бикинеев, Writing good std::future&lt; C++ >
Standford 2015 week3: Objective-C Compatibility, Property List, Views

What's hot (20)

PDF
Алексей Кутумов, Coroutines everywhere
PDF
Standford 2015 week9
PDF
Kirk Shoop, Reactive programming in C++
PDF
C++の話(本当にあった怖い話)
PDF
Коварный code type ITGM #9
TXT
Advance C++notes
PDF
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
PDF
OpenGL L02-Transformations
PDF
Tiramisu をちょっと、味見してみました。
PDF
The Ring programming language version 1.8 book - Part 65 of 202
PPTX
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
PPT
Advance features of C++
PDF
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
PDF
A basic introduction to open cv for image processing
PDF
Anomalies in X-Ray Engine
PDF
The Evolution of Async-Programming (SD 2.0, JavaScript)
DOCX
Travel management
PPTX
Pro typescript.ch03.Object Orientation in TypeScript
PDF
Welcome to Modern C++
PPT
6.1.1一步一步学repast代码解释
Алексей Кутумов, Coroutines everywhere
Standford 2015 week9
Kirk Shoop, Reactive programming in C++
C++の話(本当にあった怖い話)
Коварный code type ITGM #9
Advance C++notes
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
OpenGL L02-Transformations
Tiramisu をちょっと、味見してみました。
The Ring programming language version 1.8 book - Part 65 of 202
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Advance features of C++
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
A basic introduction to open cv for image processing
Anomalies in X-Ray Engine
The Evolution of Async-Programming (SD 2.0, JavaScript)
Travel management
Pro typescript.ch03.Object Orientation in TypeScript
Welcome to Modern C++
6.1.1一步一步学repast代码解释
Ad

Viewers also liked (6)

KEY
openFrameworks 007 - events
KEY
openFrameworks 007 - sound
PPT
Shadow Mapping with Today's OpenGL Hardware
PDF
Kalman filter - Applications in Image processing
PDF
Open frameworks 101_fitc
PPTX
Computer vision techniques for interactive art
openFrameworks 007 - events
openFrameworks 007 - sound
Shadow Mapping with Today's OpenGL Hardware
Kalman filter - Applications in Image processing
Open frameworks 101_fitc
Computer vision techniques for interactive art
Ad

Similar to openFrameworks 007 - 3D (20)

PDF
Im looking for coding help I dont really need this to be explained.pdf
PDF
Geometric objects and transformations
PDF
WebGL - 3D in your Browser
PDF
I need help with this assignment Ive gotten abit stuck with the cod.pdf
PDF
The Ring programming language version 1.7 book - Part 169 of 196
PDF
The Ring programming language version 1.8 book - Part 165 of 202
PDF
The Ring programming language version 1.9 book - Part 177 of 210
PDF
The Ring programming language version 1.7 book - Part 155 of 196
PDF
The Ring programming language version 1.5.2 book - Part 121 of 181
PDF
The Ring programming language version 1.5.2 book - Part 135 of 181
PDF
The Ring programming language version 1.7 book - Part 188 of 196
DOCX
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
PDF
The Ring programming language version 1.8 book - Part 179 of 202
PDF
The Ring programming language version 1.9 book - Part 196 of 210
PDF
The Ring programming language version 1.10 book - Part 170 of 212
PDF
The Ring programming language version 1.5.3 book - Part 143 of 184
PDF
The Ring programming language version 1.5.2 book - Part 154 of 181
PDF
The Ring programming language version 1.5.4 book - Part 110 of 185
PDF
The Ring programming language version 1.5.3 book - Part 162 of 194
PDF
The Ring programming language version 1.6 book - Part 151 of 189
Im looking for coding help I dont really need this to be explained.pdf
Geometric objects and transformations
WebGL - 3D in your Browser
I need help with this assignment Ive gotten abit stuck with the cod.pdf
The Ring programming language version 1.7 book - Part 169 of 196
The Ring programming language version 1.8 book - Part 165 of 202
The Ring programming language version 1.9 book - Part 177 of 210
The Ring programming language version 1.7 book - Part 155 of 196
The Ring programming language version 1.5.2 book - Part 121 of 181
The Ring programming language version 1.5.2 book - Part 135 of 181
The Ring programming language version 1.7 book - Part 188 of 196
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
The Ring programming language version 1.8 book - Part 179 of 202
The Ring programming language version 1.9 book - Part 196 of 210
The Ring programming language version 1.10 book - Part 170 of 212
The Ring programming language version 1.5.3 book - Part 143 of 184
The Ring programming language version 1.5.2 book - Part 154 of 181
The Ring programming language version 1.5.4 book - Part 110 of 185
The Ring programming language version 1.5.3 book - Part 162 of 194
The Ring programming language version 1.6 book - Part 151 of 189

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
A Presentation on Artificial Intelligence
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Approach and Philosophy of On baking technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
MIND Revenue Release Quarter 2 2025 Press Release
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Accuracy of neural networks in brain wave diagnosis of schizophrenia
A Presentation on Artificial Intelligence
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation theory and applications.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Approach and Philosophy of On baking technology
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”

openFrameworks 007 - 3D

  • 2. 3D ofNode ofMesh of3dUtils ofCamera ofEasyCam
  • 3. ofCamera Camera movement and matrices • Extends from ofNode • Basic GLUT camera functions • Coordinate conversions
  • 4. ofCamera Frustum setup angle of field of view in y direction, in degrees setFov(float) (45-60) setNearClip(float) near clipping plane distance setFarClip(float) set far clipping plane distance
  • 5. ofCamera Perspective and modelview matrices getProjectionMatrix() Ortho / Perspective getModelViewMatrix() Position/Orientation getModelViewProjectionMatrix() Modelview * Projection
  • 6. ofCamera Coordinate conversion worldToScreen() Convert openGL world to screen screenToWorld() Convert screen to GL world worldToCamera() Convert world to camera cameraToWorld() Convert camera to world
  • 7. ofCamera testApp.h class testApp : public ofBaseApp{ public: ... ofCamera cam; };
  • 8. ofCamera testApp.cpp void testApp::setup(){ ofBackground(33,33,33); cam.setNearClip(0.1); cam.setFarClip(100); // "1 meter" to the right, "5 meters" away from object cam.setPosition(ofVec3f(1,0,5)); } void testApp::draw(){ cam.begin(); glPointSize(10); glBegin(GL_POINTS); glVertex3f(0,0,0); glEnd(); cam.end(); }
  • 10. ofNode 3D object container • Standard 3D scene item • Manage position, scale and orientation • Lots of fantastic helper functions • ofCamera extends from this class
  • 11. ofNode Movement truck() Move left to right (x-axis) boom() Move up and down (y-axis) dolly() Move forward and backward (z-axis) setPosition() Set position directly
  • 12. ofNode Rotation tilt() Rotate around x-axis pan() Rotate around y-axis dolly() Rotate around z-axis rotate(a,axis) Rotate around arbitrary axis
  • 13. ofNode Testing movement/orientation Apply ofNode transformation (does a transformGL() glPushMatrix/glMultMatrixf()) Does a glPopMatrix, call after transformGL and restoreTransformGL() drawing. resetTransform() Resets the orientation and position
  • 14. ofNode void setScale(float s) void setScale(float x, float y, float z) void setScale(const ofVec3f& p) void setPosition(float x, float y, float z) void setPosition(const ofVec3f& p) void setGlobalPosition(float x, float y, float z) void setGlobalPosition(const ofVec3f& p) void setOrientation(const ofQuaternion& q) void setOrientation(const ofVec3f& eulerAngles) void setGlobalOrientation(const ofQuaternion& q)
  • 15. ofNode Custom 3D nodes • Create custom class and inherit from ofNode • Implement virtual customDraw(void) member function. • To draw, just call draw(void) on instance
  • 16. ofNode Extend ofNode class MyCustom3DNode : public ofNode { public: virtual void customDraw() { ofSphere(0,0,0,0.7); ofDrawAxis(2 ); } };
  • 17. ofEasyCam Camera interaction made easy begin()/end() Put your draw calls between these setTarget(ofNode) Follow and look at a target
  • 18. ofEasyCam Custom ofNode - example ofEasyCam class MyCustom3DNode : public ofNode { public: virtual void customDraw() { ofSphere(0,0,0,0.7); ofDrawAxis(2); } }; class testApp : public ofBaseApp{ public: ofEasyCam easy_cam; vector<MyCustom3DNode*> custom_nodes; MyCustom3DNode* mover; };
  • 19. ofEasyCam Custom ofNode - example ofEasyCam void testApp::setup(){ ofBackground(33,33,33); // set distance of camera "5" meters away easy_cam.setDistance(5); // create a bunch of custom 3D nodes float r = 4; for(int i = 0; i < 10; ++i) { MyCustom3DNode* node = new MyCustom3DNode(); node->setPosition( cos((float)i/10*TWO_PI) * r ,sin((float)i/10*TWO_PI) * r ,-5 ); custom_nodes.push_back(node); mover = node; } // set target for camera easy_cam.setTarget(*mover); }
  • 20. ofEasyCam Custom ofNode - example ofEasyCam void testApp::draw(){ easy_cam.begin(); // draw custom nodes. for(int i = 0; i < custom_nodes.size(); ++i) { custom_nodes[i]->draw(); } // move over x-axis. float truck_amount = sin(ofGetElapsedTimef()*0.5) * 0.001; mover->truck(truck_amount); easy_cam.end(); }
  • 21. ofMesh Container for all vertex related data • Use this when working with 3D meshes. It creates a model that is used by openGL to draw 3D shapes. • Future proof (ready for modern openGL) • Clean API for most used data: add[Vertex,Color,TexCoord]() • Nice interface for writing 3D exports (OBJ, PLY) • Use this with Vertex Buffer Objects (VBO)
  • 22. ofMesh Adding vertices addVertex(ofVec3f) Add one vertex addVertices(vector<ofVec3f>&) Reference to ofVec3f addVertices(ofVec3f*, int num) Pointer to vertices setVertex(int index) Remove by index Remove vertices removeVertex(int index) Remove by index clearVertices() Remove all vertices Get vertex getVertex(int) Get one vertex
  • 23. ofMesh Adding normals addNormal(ofVec3f&) Add a normal addNormals(vector<ofVec3f>) Add vector of normals addNormals(ofVec3f*, int) Add array of normals setNormal(int, ofVec3f&) Set one normal by index Removing normals removeNormal(int) Remove by index clearNormals() Remove all normals Retrieving normals getNormal(int) Get normal by index
  • 24. ofMesh Adding indices addIndex(ofIndexType) Add a index addIndices(const<ofIndextype>&) Add a bunch of indices addIndices(ofIndexType*,int) Add bunch of indices setIndex(int, ofIndexType) Set a specific index Removing indices removeIndex(int i) Remove by index clearIndices() Remove all indices Retrieving indices getIndex(int) Get index by index ;-)
  • 25. ofMesh Adding colors addColor(const ofFloatColor& c) Add a index addColors(const<ofFloatColor>& cols) Add a bunch of indices addColors(const ofFloatColor* cols, int amt) Add bunch of indices setColor(int index, const ofFloatColor& c) Set a specific index Removing colors removeColor(int index) Remove by index clearColors() Remove all indices Retrieving colors ofFloatColor getColor(int i) Get index by index ;-)
  • 26. ofMesh Useful for GL_ARRAY_BUFFER / VBO getNumVertices() Total number of vertices getNumColors() Total number of colors getNumTexCoords() Total number of texture coords getNumIndices() Total number of indices float* getVerticesPointer() Get a pointer to the vertices float* getColorsPointer() Get a pointer to the colors float* getNormalsPointer() Get pointer to stored normals ofIndexType* getTexCoordsPointer() Get pointer to texcoords
  • 27. ofMesh Same API for the rest • Same API for Colors, TexCoord • Helper function addTriangle(int,int,int)
  • 28. Create two planes testApp.cpp void testApp::setup(){ // bottom cube.addVertex(ofVec3f(-1,0,1)); cube.addVertex(ofVec3f(1,0,1)); cube.addVertex(ofVec3f(1,0,-1)); cube.addVertex(ofVec3f(-1,0,-1)); // top cube.addVertex(ofVec3f(-1,1,1)); cube.addVertex(ofVec3f(1,1,1)); cube.addVertex(ofVec3f(1,1,-1)); cube.addVertex(ofVec3f(-1,1,-1)); // triangles bottom cube.addIndex(0); cube.addIndex(1); cube.addIndex(2); cube.addIndex(2); cube.addIndex(3); testApp.h cube.addIndex(0); class testApp : public ofBaseApp{ // triangles top cube.addIndex(4); public: cube.addIndex(5); ofMesh cube; cube.addIndex(6); }; cube.addIndex(6); cube.addIndex(7); cube.addIndex(4); }
  • 29. Create a cube testApp.cpp void testApp::setup(){ // bottom vertices cube.addVertex(ofVec3f(-1,0,1)); cube.addVertex(ofVec3f(1,0,1)); cube.addVertex(ofVec3f(1,0,-1)); cube.addVertex(ofVec3f(-1,0,-1)); // top vertices cube.addVertex(ofVec3f(-1,1,1)); cube.addVertex(ofVec3f(1,1,1)); cube.addVertex(ofVec3f(1,1,-1)); cube.addVertex(ofVec3f(-1,1,-1)); // indices cube.addTriangle(0,1,2); // bottom cube.addTriangle(2,3,0); cube.addTriangle(4,5,6); // top cube.addTriangle(6,7,4); cube.addTriangle(0,4,5); // front cube.addTriangle(0,1,5); testApp.h cube.addTriangle(1,2,6); // right cube.addTriangle(6,5,1); class testApp : public ofBaseApp{ cube.addTriangle(2,6,3); // back cube.addTriangle(3,7,6); public: cube.addTriangle(0,3,7); // left ofMesh cube; cube.addTriangle(7,4,0); }; }

Editor's Notes