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

What's hot

Unite2019 HLOD를 활용한 대규모 씬 제작 방법
Unite2019 HLOD를 활용한 대규모 씬 제작 방법Unite2019 HLOD를 활용한 대규모 씬 제작 방법
Unite2019 HLOD를 활용한 대규모 씬 제작 방법장규 서
 
Developing VR Experiences with Unity
Developing VR Experiences with UnityDeveloping VR Experiences with Unity
Developing VR Experiences with UnityMark Billinghurst
 
오픈드론맵 한국어 사용자 지침서
오픈드론맵 한국어 사용자 지침서오픈드론맵 한국어 사용자 지침서
오픈드론맵 한국어 사용자 지침서Byeong-Hyeok Yu
 
Moving into metaverse 메타버스 시대 속으로
Moving into metaverse 메타버스 시대 속으로 Moving into metaverse 메타버스 시대 속으로
Moving into metaverse 메타버스 시대 속으로 Jahee Lee
 
공간규모별 디지털트윈 활용 사례 - 국토연구원 세미나 자료
공간규모별 디지털트윈 활용 사례 - 국토연구원 세미나 자료공간규모별 디지털트윈 활용 사례 - 국토연구원 세미나 자료
공간규모별 디지털트윈 활용 사례 - 국토연구원 세미나 자료SANGHEE SHIN
 
오픈소스GIS 개론 과정 - OpenLayers 기초
오픈소스GIS 개론 과정 - OpenLayers 기초오픈소스GIS 개론 과정 - OpenLayers 기초
오픈소스GIS 개론 과정 - OpenLayers 기초HaNJiN Lee
 
Voxel based game_optimazation_relelase
Voxel based game_optimazation_relelaseVoxel based game_optimazation_relelase
Voxel based game_optimazation_relelaseYEONG-CHEON YOU
 
GeoServer 2.4.x 한국어 사용자 지침서
GeoServer 2.4.x 한국어 사용자 지침서GeoServer 2.4.x 한국어 사용자 지침서
GeoServer 2.4.x 한국어 사용자 지침서SANGHEE SHIN
 
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013Esun Kim
 
State of OpenGXT: 오픈소스 공간분석엔진
State of OpenGXT: 오픈소스 공간분석엔진State of OpenGXT: 오픈소스 공간분석엔진
State of OpenGXT: 오픈소스 공간분석엔진MinPa Lee
 
FOSS4G Firenze 2022 참가기
FOSS4G Firenze 2022 참가기FOSS4G Firenze 2022 참가기
FOSS4G Firenze 2022 참가기SANGHEE SHIN
 
[아꿈사] 게임 기초 수학 물리 1,2장
[아꿈사] 게임 기초 수학 물리 1,2장[아꿈사] 게임 기초 수학 물리 1,2장
[아꿈사] 게임 기초 수학 물리 1,2장sung ki choi
 
WebXR: Introducing Mixed Reality and the Immersive Web - Peter O'Shaughnessy ...
WebXR: Introducing Mixed Reality and the Immersive Web - Peter O'Shaughnessy ...WebXR: Introducing Mixed Reality and the Immersive Web - Peter O'Shaughnessy ...
WebXR: Introducing Mixed Reality and the Immersive Web - Peter O'Shaughnessy ...Codemotion
 
スマートフォン向けサービスにおけるサーバサイド設計入門
スマートフォン向けサービスにおけるサーバサイド設計入門スマートフォン向けサービスにおけるサーバサイド設計入門
スマートフォン向けサービスにおけるサーバサイド設計入門Hisashi HATAKEYAMA
 
오픈소스GIS 개발 일반 강의자료
오픈소스GIS 개발 일반 강의자료오픈소스GIS 개발 일반 강의자료
오픈소스GIS 개발 일반 강의자료BJ Jang
 
Novel Interfaces for AR Systems
Novel Interfaces for AR SystemsNovel Interfaces for AR Systems
Novel Interfaces for AR SystemsMark Billinghurst
 
Cardboard VR: Building Low Cost VR Experiences
Cardboard VR: Building Low Cost VR ExperiencesCardboard VR: Building Low Cost VR Experiences
Cardboard VR: Building Low Cost VR ExperiencesMark Billinghurst
 

What's hot (20)

Unite2019 HLOD를 활용한 대규모 씬 제작 방법
Unite2019 HLOD를 활용한 대규모 씬 제작 방법Unite2019 HLOD를 활용한 대규모 씬 제작 방법
Unite2019 HLOD를 활용한 대규모 씬 제작 방법
 
Developing VR Experiences with Unity
Developing VR Experiences with UnityDeveloping VR Experiences with Unity
Developing VR Experiences with Unity
 
QGIS 활용
QGIS 활용QGIS 활용
QGIS 활용
 
오픈드론맵 한국어 사용자 지침서
오픈드론맵 한국어 사용자 지침서오픈드론맵 한국어 사용자 지침서
오픈드론맵 한국어 사용자 지침서
 
Moving into metaverse 메타버스 시대 속으로
Moving into metaverse 메타버스 시대 속으로 Moving into metaverse 메타버스 시대 속으로
Moving into metaverse 메타버스 시대 속으로
 
공간규모별 디지털트윈 활용 사례 - 국토연구원 세미나 자료
공간규모별 디지털트윈 활용 사례 - 국토연구원 세미나 자료공간규모별 디지털트윈 활용 사례 - 국토연구원 세미나 자료
공간규모별 디지털트윈 활용 사례 - 국토연구원 세미나 자료
 
오픈소스GIS 개론 과정 - OpenLayers 기초
오픈소스GIS 개론 과정 - OpenLayers 기초오픈소스GIS 개론 과정 - OpenLayers 기초
오픈소스GIS 개론 과정 - OpenLayers 기초
 
카툰 렌더링
카툰 렌더링카툰 렌더링
카툰 렌더링
 
Voxel based game_optimazation_relelase
Voxel based game_optimazation_relelaseVoxel based game_optimazation_relelase
Voxel based game_optimazation_relelase
 
GeoServer 2.4.x 한국어 사용자 지침서
GeoServer 2.4.x 한국어 사용자 지침서GeoServer 2.4.x 한국어 사용자 지침서
GeoServer 2.4.x 한국어 사용자 지침서
 
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
 
State of OpenGXT: 오픈소스 공간분석엔진
State of OpenGXT: 오픈소스 공간분석엔진State of OpenGXT: 오픈소스 공간분석엔진
State of OpenGXT: 오픈소스 공간분석엔진
 
FOSS4G Firenze 2022 참가기
FOSS4G Firenze 2022 참가기FOSS4G Firenze 2022 참가기
FOSS4G Firenze 2022 참가기
 
[아꿈사] 게임 기초 수학 물리 1,2장
[아꿈사] 게임 기초 수학 물리 1,2장[아꿈사] 게임 기초 수학 물리 1,2장
[아꿈사] 게임 기초 수학 물리 1,2장
 
WebXR: Introducing Mixed Reality and the Immersive Web - Peter O'Shaughnessy ...
WebXR: Introducing Mixed Reality and the Immersive Web - Peter O'Shaughnessy ...WebXR: Introducing Mixed Reality and the Immersive Web - Peter O'Shaughnessy ...
WebXR: Introducing Mixed Reality and the Immersive Web - Peter O'Shaughnessy ...
 
スマートフォン向けサービスにおけるサーバサイド設計入門
スマートフォン向けサービスにおけるサーバサイド設計入門スマートフォン向けサービスにおけるサーバサイド設計入門
スマートフォン向けサービスにおけるサーバサイド設計入門
 
오픈소스GIS 개발 일반 강의자료
오픈소스GIS 개발 일반 강의자료오픈소스GIS 개발 일반 강의자료
오픈소스GIS 개발 일반 강의자료
 
Novel Interfaces for AR Systems
Novel Interfaces for AR SystemsNovel Interfaces for AR Systems
Novel Interfaces for AR Systems
 
Lec15 sfm
Lec15 sfmLec15 sfm
Lec15 sfm
 
Cardboard VR: Building Low Cost VR Experiences
Cardboard VR: Building Low Cost VR ExperiencesCardboard VR: Building Low Cost VR Experiences
Cardboard VR: Building Low Cost VR Experiences
 

Viewers also liked

openFrameworks 007 - video
openFrameworks 007 - videoopenFrameworks 007 - video
openFrameworks 007 - videoroxlu
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utilsroxlu
 
openFrameworks 007 - GL
openFrameworks 007 - GL openFrameworks 007 - GL
openFrameworks 007 - GL roxlu
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - eventsroxlu
 
openFrameworks 007 - sound
openFrameworks 007 - soundopenFrameworks 007 - sound
openFrameworks 007 - soundroxlu
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphicsroxlu
 
Shadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL HardwareShadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL HardwareMark Kilgard
 
Kalman filter - Applications in Image processing
Kalman filter - Applications in Image processingKalman filter - Applications in Image processing
Kalman filter - Applications in Image processingRavi Teja
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitcbenDesigning
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013aleks-f
 
Computer vision techniques for interactive art
Computer vision techniques for interactive artComputer vision techniques for interactive art
Computer vision techniques for interactive artJorge Cardoso
 

Viewers also liked (11)

openFrameworks 007 - video
openFrameworks 007 - videoopenFrameworks 007 - video
openFrameworks 007 - video
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
openFrameworks 007 - GL
openFrameworks 007 - GL openFrameworks 007 - GL
openFrameworks 007 - GL
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
 
openFrameworks 007 - sound
openFrameworks 007 - soundopenFrameworks 007 - sound
openFrameworks 007 - sound
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
Shadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL HardwareShadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL Hardware
 
Kalman filter - Applications in Image processing
Kalman filter - Applications in Image processingKalman filter - Applications in Image processing
Kalman filter - Applications in Image processing
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
Computer vision techniques for interactive art
Computer vision techniques for interactive artComputer vision techniques for interactive art
Computer vision techniques for interactive art
 

Similar to openFrameworks 007 - 3D

Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfcontact41
 
I need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdfI need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdfConint29
 
Complete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfComplete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfmarketing413921
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slidestamillarasan
 
Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01Getachew Ganfur
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++vidyamittal
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingMark Kilgard
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITEgor Bogatov
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-CNissan Tsafrir
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupMark Kilgard
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleannessbergel
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Korhan Bircan
 
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfgopalk44
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montageKris Kowal
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bPhilip Schwarz
 

Similar to openFrameworks 007 - 3D (20)

Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
 
I need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdfI need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdf
 
Complete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfComplete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdf
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
 
Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
OpenGL L06-Performance
OpenGL L06-PerformanceOpenGL L06-Performance
OpenGL L06-Performance
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-C
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
 
Exploiting vectorization with ISPC
Exploiting vectorization with ISPCExploiting vectorization with ISPC
Exploiting vectorization with ISPC
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleanness
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
 
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
 

Recently uploaded

Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesThousandEyes
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 

Recently uploaded (20)

Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 

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

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n