Herramientas de usuario

Herramientas del sitio


wiki2:cpp:libraries:openframeworks:creating_graphics

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:cpp:libraries:openframeworks:creating_graphics [2015/10/08 17:41]
alfred [ofMesh]
wiki2:cpp:libraries:openframeworks:creating_graphics [2020/05/09 09:25] (actual)
Línea 118: Línea 118:
  
 ''​path.setMode(ofPath::​POLYLINES)''​ which will make that path override the creation of primitives and work directly with ofPolylines which can be slightly faster in certain cases, mostly if you are creating a really high number of paths and modifying them frequently. ''​path.setMode(ofPath::​POLYLINES)''​ which will make that path override the creation of primitives and work directly with ofPolylines which can be slightly faster in certain cases, mostly if you are creating a really high number of paths and modifying them frequently.
 +
 +=== Notes ===
 +
 +  * If you do not close the path then the last point won't join the first one.
  
 ===== 3D ===== ===== 3D =====
Línea 128: Línea 132:
 ofRect(20,​20,​20,​20);​ ofRect(20,​20,​20,​20);​
 </​code>​ </​code>​
-... enclosed that between ​ofPush/​PopMatrix. But they are also deprecated. Each call to them, or the gl equivalents for that matter, are doing a multiplication of 4x4 matrices. But we can avoid it somehow. Instead of doing all of the multiplications of the matrices every frame, we can use an ofMatrix4x4 for each shape we use, do all of that shape'​s transformations once (or every time the shape moves), and apply them later when we want to draw that frame:+... enclosed that between ​''​ofPushMatrix''​ or ''​ofPopMatrix''​. But they are also deprecated. Each call to them, or the gl equivalents for that matter, are doing a multiplication of 4x4 matrices. But we can avoid it somehow. Instead of doing all of the multiplications of the matrices every frame, we can use an ofMatrix4x4 for each shape we use, do all of that shape'​s transformations once (or every time the shape moves), and apply them later when we want to draw that frame:
 <code cpp> <code cpp>
 ofPath path ofPath path
Línea 298: Línea 302:
     mesh.draw();​     mesh.draw();​
     mesh2.draw();​ // fast!!     mesh2.draw();​ // fast!!
 +}
 +</​code>​
 +
 +You can change the way the mesh is drawn using the next constants for the ''​setMode''​ method: OF_PRIMITIVE_TRIANGLES,​ OF_PRIMITIVE_TRIANGLE_STRIP,​ OF_PRIMITIVE_TRIANGLE_FAN,​ OF_PRIMITIVE_LINES,​ OF_PRIMITIVE_LINE_STRIP,​ OF_PRIMITIVE_LINE_LOOP,​ OF_PRIMITIVE_POINTS.
 +
 +You can draw the wireframe, the points using the ''​drawWireframe()''​ and ''​drawVertices()''​ methods.
 +
 +==== of3dPrimitive ====
 +of3dPrimitive is a helper class that encapsulates an ofVboMesh and inherits from ofNode. You can call any method you would call on an ofNode, because of how inheritance works, it is actually an ofNode so we can change it's position, rotate it, make it look to some other node, add it to a node hierarchy... And when you call draw on it, it'll draw the mesh it contains applying the transformation defined by it's node.
 +
 +There'​s several predefined 3D primitives, like...
 +  * ofPlanePrimitive
 +  * ofSpherePrimitive
 +  * ofIcoSpherePrimitive
 +  * ofCylinderPrimitive
 +
 +Also you can create your own:
 +<code cpp>
 +of3dPrimitive primitive;
 +
 +// ofApp.cpp
 +
 +void ofApp::​setup(){
 +    primitive.getMesh().addVertex(ofVec3f(20,​20));​
 +    primitive.getMesh().addVertex(ofVec3f(40,​20));​
 +    primitive.getMesh().addVertex(ofVec3f(40,​40));​
 +    primitive.getMesh().addVertex(ofVec3f(20,​40));​
 +    primitive.getMesh().setMode(OF_PRIMITIVE_TRIANGLE_FAN);​
 +}
 +
 +void ofApp::​update(){
 +    primitive.move(ofVec3f(10,​0,​0));​
 +}
 +
 +void ofApp::​draw(){
 +    primitive.draw();​
 } }
 </​code>​ </​code>​
wiki2/cpp/libraries/openframeworks/creating_graphics.1444326094.txt.gz · Última modificación: 2020/05/09 09:25 (editor externo)