Skip to content

Commit

Permalink
Merge pull request #84 from jvcleave/master
Browse files Browse the repository at this point in the history
ofPath fixes
  • Loading branch information
kylemcdonald committed Apr 20, 2012
2 parents bbe0743 + 29b980f commit 11c107b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
9 changes: 7 additions & 2 deletions _documentation/3d/ofMesh.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ Vertices are passed to your graphics card and your graphics card fill in the spa

3. Say that you're done making points.

You may be thinking: I'll just make eight vertices and voila: a cube. Not so quick. Theres a hitch and that hitch is that the OpenGL renderer has different ways of connecting the vertices that you pass to it and none are as efficient as to only need eight vertices to create a cube. You've probably seen a version of the following image somewhere before.
Generally you have to create your points to fit the drawing mode that you've selected because of whats called winding. A vertex gets connected to another vertex in the order that the mode does its winding and this means that you might need multiple vertices in a given location to create the shape you want. The cube, for example, requires eighteen vertices, not the eight that you would expect. If you note the order of vertices in the GL chart above you'll see that all of them use their vertices slightly differently (in particular you should make note of the GL_TRIANGLE_STRIP example). Drawing a shape requires that you keep track of which drawing mode is being used and which order your vertices are declared in. If you're thinking: it would be nice if there were an abstraction layer for this you're thinking right. Enter the mesh, which is really just an abstraction of the vertex and drawing mode that we started with but which has the added bonus of managing the draw order for you. That may seem insignificant at first, but it provides some real benefits when working with complex geometry.
You may be thinking: I'll just make eight vertices and voila: a cube. Not so quick. There's a hitch and that hitch is that the OpenGL renderer has different ways of connecting the vertices that you pass to it and none are as efficient as to only need eight vertices to create a cube.

You've probably seen a version of the following image somewhere before.
![PRIMATIVES](primitives_new-640x269.gif)
Generally you have to create your points to fit the drawing mode that you've selected because of whats called winding. A vertex gets connected to another vertex in the order that the mode does its winding and this means that you might need multiple vertices in a given location to create the shape you want. The cube, for example, requires eighteen vertices, not the eight that you would expect. If you note the order of vertices in the GL chart above you'll see that all of them use their vertices slightly differently (in particular you should make note of the GL_TRIANGLE_STRIP example). Drawing a shape requires that you keep track of which drawing mode is being used and which order your vertices are declared in.

If you're thinking: it would be nice if there were an abstraction layer for this you're thinking right. Enter the mesh, which is really just an abstraction of the vertex and drawing mode that we started with but which has the added bonus of managing the draw order for you. That may seem insignificant at first, but it provides some real benefits when working with complex geometry.



Expand Down
Binary file added _documentation/3d/primitives_new-640x269.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions _documentation/graphics/ofPath.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ for( float theta = 0; theta < TWO_PI; theta += 0.1)
px = mouseX;
py = mouseY;
$$/code
~~~~



Expand Down Expand Up @@ -407,7 +407,7 @@ line.addVertex(ofPoint(200, 400));
line.bezierTo(100, 100, 800, 100, 700, 400);
~~~~
Creates this:
![polyline bezier](/bezier.png)
![polyline bezier](bezier.png)
The control points are shown in yellow.


Expand Down Expand Up @@ -512,7 +512,7 @@ _description: _


Creates a quadratic bezier line in 3D space from the current drawing point with the beginning indicated by the coordinates cx1, cy1, cz1, the control point at cx2, cy2, cz2, and that ends at the coordinates x, y, z.
![polyline curves](/curves.png)
![polyline curves](curves.png)



Expand Down Expand Up @@ -606,7 +606,7 @@ Creates an arc at centre, which has the radiusX, radiusY, and begins at angleBeg

~~~~{.cpp}
path.arc( 100, 100, 50, 50, 0, 360);
$$/code
~~~~

Note that angleBegin needs to be larger than angleEnd, i.e. 0, 180 is ok, while 180,0 is not.

Expand Down Expand Up @@ -639,9 +639,9 @@ Creates an arc at x,y, which has the radiusX, radiusY, and begins at angleBegin
~~~~{.cpp}
path.moveTo(300, 300);
path.arc( 300, 300, 200, 200, 0, 271); // note 271, not 270 for precision
$$/code
~~~~

![ofPath arc](/ofPath_arc.png)
![ofPath arc](ofPath_arc.png)

Note that angleBegin needs to be larger than angleEnd, i.e. 0, 180 is ok, while 180,0 is not.

Expand Down Expand Up @@ -705,7 +705,7 @@ OF_POLY_WINDING_POSITIVE
OF_POLY_WINDING_NEGATIVE
OF_POLY_WINDING_ABS_GEQ_TWO

![ofPath winding modes](/windingModes.gif)
![ofPath winding modes](winding_modes.gif)

So adding the following points:

Expand Down Expand Up @@ -767,7 +767,7 @@ void testApp::keyPressed(int key){
path2.setPolyWindingMode((ofPolyWindingMode) mode);
}
$$/code
~~~~

we can see non zero and positive handle the winding differently:

Expand Down
6 changes: 3 additions & 3 deletions _documentation/graphics/ofPolyline.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ line.addVertex(ofPoint(200, 400));
line.bezierTo(100, 100, 800, 100, 700, 400);
~~~~
Creates this:
![polyline bezier](/bezier.png)
![polyline bezier](bezier.png)
The control points are shown in yellow.


Expand Down Expand Up @@ -658,7 +658,7 @@ _advanced: False_
_description: _

Creates a quadratic bezier line in 3D space from the current drawing point with the beginning indicated by the coordinates cx1, cy1, cz1, the control point at cx2, cy2, cz2, and that ends at the coordinates x, y, z.
![polyline curves](/curves.png)
![polyline curves](curves.png)



Expand Down Expand Up @@ -780,7 +780,7 @@ line.draw();
ofTranslate(400, 0);
line.getResampledBySpacing(100).draw();
~~~~
![polyline resample](/resample.png)
![polyline resample](resample.png)



Expand Down
Binary file modified _documentation/graphics/path_winding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 11c107b

Please sign in to comment.