Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:cinder/Cinder

  • Loading branch information...
commit e49647c229a5831681fd51df938a1856e0f0abaa 2 parents 26208ee + 8d66662
@andrewfb andrewfb authored
View
6 docs/doxygen/docsrc/guides/tour/chapter1.dox
@@ -106,7 +106,7 @@ As we mentioned before, including images directly in your app as resources is on
The following code will attempt to create an image from a file selected by means of a standard open dialog box. Once you select a file, assuming the file is a valid image, a texture is created. Otherwise, an exception is thrown and we print an error message (we'll discuss console() more in a bit).
\code
try {
- std::string p = getOpenFilePath( "", ImageIo::getLoadExtensions() );
+ fs::path p = getOpenFilePath( "", ImageIo::getLoadExtensions() );
if( ! p.empty() ) { // an empty string means the user canceled
myImage = gl::Texture( loadImage( p ) );
}
@@ -136,9 +136,9 @@ Drawing shapes is just as easy. If you want to draw a circle of a radius of x, y
gl::drawSolidCircle( Vec2f( 15.0f, 25.0f ), 50.0f );
\endcode
\n
-The circle that is created is actually an OpenGL \c TRIANGLE_FAN. The number of triangles comprising the fan can be controlled by an optional third parameter. If left blank, the circle will be created with as much detail as is needed based on the circle's radius. For example, the following code will create a filled hexagon. Note that the detail parameter represents the number of vertices to draw. Since we are drawing a triangle fan, we need to include the center point which brings the total vertices to 7, not 6.
+The circle that is created is actually an OpenGL \c TRIANGLE_FAN. The number of triangles comprising the fan can be controlled by an optional third parameter. If left blank, the circle will be created with as much detail as is needed based on the circle's radius. For example, the following code will create a filled hexagon.
\code
-gl::drawSolidCircle( Vec2f( 15.0f, 25.0f ), 50.0f, 7 );
+gl::drawSolidCircle( Vec2f( 15.0f, 25.0f ), 50.0f, 6 );
\endcode
\n
There are similar methods for drawing all manner of basic geometry, both 2D and 3D. Check the reference for the full list.\n
View
11 samples/Picking3D/resources/phong_frag.glsl
@@ -7,22 +7,25 @@ varying vec3 N;
void main()
{
- float shinyness = 50.0;
+ const vec4 ambient = vec4(0.1, 0.1, 0.1, 1);
+ const vec4 diffuse = vec4(0.9, 0.9, 0.9, 1);
+ const vec4 specular = vec4(1, 1, 1, 1);
+ const float shinyness = 50.0;
vec3 L = normalize(gl_LightSource[0].position.xyz - v);
vec3 E = normalize(-v);
vec3 R = normalize(-reflect(L,N));
// ambient term
- vec4 Iamb = gl_FrontLightProduct[0].ambient;
+ vec4 Iamb = ambient;
// diffuse term
- vec4 Idiff = texture2D( tex0, gl_TexCoord[0].st) * gl_FrontLightProduct[0].diffuse;
+ vec4 Idiff = texture2D( tex0, gl_TexCoord[0].st) * diffuse;
Idiff *= max(dot(N,L), 0.0);
Idiff = clamp(Idiff, 0.0, 1.0);
// specular term
- vec4 Ispec = vec4(1, 1, 1, 1); // gl_FrontLightProduct[0].specular;
+ vec4 Ispec = specular;
Ispec *= pow(max(dot(R,E),0.0), shinyness);
Ispec = clamp(Ispec, 0.0, 1.0);
View
43 samples/Picking3D/src/Picking3DApp.cpp
@@ -98,6 +98,9 @@ class Picking3DApp : public AppBasic
// the model of a rubber ducky
TriMesh mMesh;
+ // the object space bounding box of the mesh
+ AxisAlignedBox3f mObjectBounds;
+
// transformations (translate, rotate, scale) of the model
Matrix44f mTransform;
@@ -137,7 +140,10 @@ void Picking3DApp::setup()
// (note: the mesh was created from an OBJ file
// using the ObjLoader class. The data was then saved using the
// TriMesh::write() method. Reading binary files is much quicker.)
- mMesh.read( loadResource( RES_DUCKY_MESH ) );
+ mMesh.read( loadResource( RES_DUCKY_MESH ) );
+
+ // get the object space bounding box of the model, for fast intersection testing
+ mObjectBounds = mMesh.calcBoundingBox();
// set up the camera
CameraPersp cam;
@@ -190,7 +196,7 @@ void Picking3DApp::draw()
drawGrid();
// bind the texture
- mTexture.bind();
+ mTexture.enableAndBind();
// bind the shader and tell it to use our texture
mShader.bind();
@@ -212,7 +218,7 @@ void Picking3DApp::draw()
// perform 3D picking now, so we can draw the intersection as a sphere
Vec3f pickedPoint, pickedNormal;
if( performPicking( &pickedPoint, &pickedNormal ) ) {
- gl::color( ColorAf(0.0f, 1.0f, 0.0f, 0.5f) );
+ gl::color( Color(0, 1, 0) );
// draw an arrow to the picked point along its normal
gl::drawVector( pickedPoint + pickedNormal, pickedPoint );
@@ -254,29 +260,36 @@ bool Picking3DApp::performPicking( Vec3f *pickedPoint, Vec3f *pickedNormal )
// where (0, 0) is in the LOWERleft corner, we have to flip the v-coordinate
Ray ray = cam.generateRay(u , 1.0f - v, cam.getAspectRatio() );
- // get the bounding box of the model, for fast intersection testing
- AxisAlignedBox3f objectBounds = mMesh.calcBoundingBox();
-
- // draw this untransformed box in yellow
+ // draw the object space bounding box in yellow
gl::color( Color(1, 1, 0) );
- gl::drawStrokedCube(objectBounds);
+ gl::drawStrokedCube(mObjectBounds);
// the coordinates of the bounding box are in object space, not world space,
// so if the model was translated, rotated or scaled, the bounding box would not
- // reflect that.
- AxisAlignedBox3f worldBounds = mMesh.calcBoundingBox(mTransform);
+ // reflect that.
+ //
+ // One solution would be to pass the transformation to the calcBoundingBox() function:
+ AxisAlignedBox3f worldBoundsExact = mMesh.calcBoundingBox(mTransform); // slow
+
+ // draw this transformed box in orange
+ gl::color( Color(1, 0.5, 0) );
+ gl::drawStrokedCube(worldBoundsExact);
+
+ // But if you already have an object space bounding box, it's much faster to
+ // approximate the world space bounding box like this:
+ AxisAlignedBox3f worldBoundsApprox = mObjectBounds.transformed(mTransform); // fast
// draw this transformed box in cyan
gl::color( Color(0, 1, 1) );
- gl::drawStrokedCube(worldBounds);
-
- // set initial distance to something far, far away
- float result = 1.0e6f;
+ gl::drawStrokedCube(worldBoundsApprox);
// fast detection first - test against the bounding box itself
- if( ! worldBounds.intersects(ray) )
+ if( ! worldBoundsExact.intersects(ray) )
return false;
+ // set initial distance to something far, far away
+ float result = 1.0e6f;
+
// traverse triangle list and find the picked triangle
size_t polycount = mMesh.getNumTriangles();
float distance = 0.0f;
View
6 samples/Picking3D/vc10/Picking3D.vcxproj
@@ -102,11 +102,11 @@
<ClCompile Include="..\src\Picking3DApp.cpp" />
</ItemGroup>
<ItemGroup>
- <None Include="..\data\phong_frag.glsl" />
- <None Include="..\data\phong_vert.glsl" />
+ <ResourceCompile Include="Resources.rc" />
</ItemGroup>
<ItemGroup>
- <ResourceCompile Include="Resources.rc" />
+ <None Include="..\resources\phong_frag.glsl" />
+ <None Include="..\resources\phong_vert.glsl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
View
14 samples/Picking3D/vc10/Picking3D.vcxproj.filters
@@ -23,16 +23,16 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
- <None Include="..\data\phong_frag.glsl">
+ <ResourceCompile Include="Resources.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="..\resources\phong_frag.glsl">
<Filter>Shader Files</Filter>
</None>
- <None Include="..\data\phong_vert.glsl">
+ <None Include="..\resources\phong_vert.glsl">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
- <ItemGroup>
- <ResourceCompile Include="Resources.rc">
- <Filter>Resource Files</Filter>
- </ResourceCompile>
- </ItemGroup>
</Project>
Please sign in to comment.
Something went wrong with that request. Please try again.