Skip to content

Commit

Permalink
more sample improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
richardeakin authored and andrewfb committed Apr 11, 2015
1 parent 40cd959 commit 6e34bbe
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions samples/_opengl/VboMesh/src/VboMeshApp.cpp
@@ -1,17 +1,16 @@
//
// This sample demonstrates the VboMesh class by creating a simple Plane mesh with a texture mapped onto it.
// The mesh has static indices and texture coordinates, but its vertex positions are dynamic.
// This sample demonstrates basic usage of the VboMesh class by creating a simple Plane mesh
// with a texture mapped onto it. The mesh has static indices and texture coordinates, but
// its vertex positions are dynamic.
//

#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/gl/VboMesh.h"
#include "cinder/gl/Shader.h"
#include "cinder/gl/Texture.h"
#include "cinder/GeomIO.h"
#include "cinder/MayaCamUI.h"
#include "cinder/ImageIo.h"
#include "cinder/MayaCamUI.h"

#include "Resources.h"

Expand All @@ -20,9 +19,6 @@ using namespace ci::app;

using std::vector;

const int VERTICES_X = 200;
const int VERTICES_Z = 50;

class VboSampleApp : public App {
public:
void setup() override;
Expand All @@ -41,7 +37,7 @@ class VboSampleApp : public App {

void VboSampleApp::setup()
{
auto plane = geom::Plane().size( vec2( 20, 20 ) ).subdivisions( ivec2( VERTICES_X, VERTICES_Z ) );
auto plane = geom::Plane().size( vec2( 20, 20 ) ).subdivisions( ivec2( 200, 50 ) );

vector<gl::VboMesh::Layout> bufferLayout = {
gl::VboMesh::Layout().usage( GL_DYNAMIC_DRAW ).attrib( geom::Attrib::POSITION, 3 ),
Expand Down Expand Up @@ -83,17 +79,15 @@ void VboSampleApp::mouseDrag( MouseEvent event )

void VboSampleApp::update()
{
const float zFreq = 0.9325f;
const float xFreq = 1.3467f;
float offset = getElapsedSeconds() * 5.0f;
float offset = getElapsedSeconds() * 4.0f;

// Dynmaically generate our new positions based on a sin(x) + cos(z) wave
// We set 'orphanExisting' to false so that we can also read from the position buffer, though keep
// in mind that this isn't the most efficient way to do cpu-side updates. Consider using VboMesh::bufferAttrib() as well.
auto mappedPosAttrib = mVboMesh->mapAttrib3f( geom::Attrib::POSITION, false );
for( int i = 0; i < mVboMesh->getNumVertices(); i++ ) {
vec3 &pos = *mappedPosAttrib;
(*mappedPosAttrib).y = ( sinf( pos.x * xFreq + offset ) + cosf( pos.z * zFreq + offset ) ) / 4.0f;;
mappedPosAttrib->y = sinf( pos.x * 1.1467f + offset ) * 0.323f + cosf( pos.z * 0.7325f + offset ) * 0.431f;
++mappedPosAttrib;
}
mappedPosAttrib.unmap();
Expand Down

0 comments on commit 6e34bbe

Please sign in to comment.