Browse files

create cone via ofVboMesh

  • Loading branch information...
1 parent 4c1857d commit 9d390fbfc67fd4b3833c99cb804b5baba7ddbe34 @fx-lange committed May 11, 2012
Showing with 92 additions and 25 deletions.
  1. +43 −4 example/.cproject
  2. +1 −1 example/.project
  3. +30 −20 src/ofxVoronoiGL.cpp
  4. +18 −0 src/ofxVoronoiGL.h
View
47 example/.cproject
@@ -4,7 +4,7 @@
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.404154">
- <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.404154" moduleId="org.eclipse.cdt.core.settings" name="Default">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.404154" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
@@ -16,11 +16,11 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <configuration buildProperties="" description="" id="0.404154" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+ <configuration buildProperties="" description="" id="0.404154" name="Debug" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.404154." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1654981793" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1654981793.1875460484" name=""/>
- <builder id="org.eclipse.cdt.build.core.settings.default.builder.16424622" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
+ <builder id="org.eclipse.cdt.build.core.settings.default.builder.16424622" incrementalBuildTarget="Debug" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.1060555393" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.1572989054" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1046001704" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
@@ -40,6 +40,43 @@
<externalSettings containerId="openFrameworks;" factoryId="org.eclipse.cdt.core.cfg.export.settings.sipplier"/>
</storageModule>
</cconfiguration>
+ <cconfiguration id="0.404154.862606806">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.404154.862606806" moduleId="org.eclipse.cdt.core.settings" name="Release">
+ <externalSettings/>
+ <extensions>
+ <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ </extensions>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <configuration buildProperties="" description="" id="0.404154.862606806" name="Release" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+ <folderInfo id="0.404154.862606806." name="/" resourcePath="">
+ <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1458638722" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
+ <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1458638722.1593924146" name=""/>
+ <builder id="org.eclipse.cdt.build.core.settings.default.builder.982349585" incrementalBuildTarget="Release" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.libs.816666891" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1270550839" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1667989196" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.234480112" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1217107934" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1378394835" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1249632710" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ </toolChain>
+ </folderInfo>
+ </configuration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings">
+ <externalSettings containerId="addons;" factoryId="org.eclipse.cdt.core.cfg.export.settings.sipplier"/>
+ <externalSettings containerId="openFrameworks;" factoryId="org.eclipse.cdt.core.cfg.export.settings.sipplier"/>
+ </storageModule>
+ </cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="emptyExample.null.1823919498" name="emptyExample"/>
@@ -50,5 +87,7 @@
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
- <storageModule moduleId="refreshScope"/>
+ <storageModule moduleId="refreshScope" versionNumber="1">
+ <resource resourceType="PROJECT" workspacePath="/SmallVoronoiExample"/>
+ </storageModule>
</cproject>
View
2 example/.project
@@ -54,7 +54,7 @@
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
- <value>all</value>
+ <value>Debug</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
View
50 src/ofxVoronoiGL.cpp
@@ -11,8 +11,9 @@ void ofxVoronoiGL::setup(int _width, int _height, float _error){
fboSettings.internalformat = GL_RGB;
fboSettings.numSamples = 0;
fboSettings.useDepth = true;
- fboSettings.numColorbuffers = 2; //an extra texture for the depthbuffer
- fbo.allocate(fboSettings); //-> use MSAA
+ fboSettings.depthAsTexture = true;
+// fboSettings.numColorbuffers = 2; //an extra texture for the depthbuffer
+ fbo.allocate(fboSettings);
R = sqrt(width*width + height*height);
//TODO musst be calculate by 2cos⁽⁻¹⁾(R-E / R)
@@ -22,10 +23,15 @@ void ofxVoronoiGL::setup(int _width, int _height, float _error){
cam.enableOrtho();
cam.move(0,0,10);
+ cam.setFarClip(400);//TODO should be set depended to width and height
+
+ vboMesh.setMode(OF_PRIMITIVE_TRIANGLES);
}
void ofxVoronoiGL::setPoint(int x,int y){
- points.push_back(VoronoiCell(x,y,SPTAColor()));
+ SPTAColor sc = SPTAColor();
+ points.push_back(VoronoiCell(x,y,sc));
+ createConeMesh( x, y, sc);
}
void ofxVoronoiGL::setPoint(ofPoint & p){
@@ -69,21 +75,22 @@ void ofxVoronoiGL::drawOnScreen(int x,int y){
void ofxVoronoiGL::createVoronoi(){
glEnable(GL_DEPTH_TEST);
- glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
-
- //draw points
- std::vector<VoronoiCell>::iterator pointIt;
- for(pointIt = points.begin(); pointIt!=points.end();pointIt++){
- VoronoiCell& p = *pointIt;
- drawCone(p,p.color);
- }
-
- //draw polygons
- std::vector<std::vector<VoronoiCell> >::iterator polyIt;
- for(polyIt = polygons.begin();polyIt!=polygons.end();polyIt++){
- std::vector<VoronoiCell>& poly = *polyIt;
- drawPolygon(poly);
- }
+ glPolygonMode(GL_FRONT_AND_BACK,GL_FILL );
+
+// //draw points
+// std::vector<VoronoiCell>::iterator pointIt;
+// for(pointIt = points.begin(); pointIt!=points.end();pointIt++){
+// VoronoiCell& p = *pointIt;
+// drawCone(p,p.color);
+// }
+//
+// //draw polygons
+// std::vector<std::vector<VoronoiCell> >::iterator polyIt;
+// for(polyIt = polygons.begin();polyIt!=polygons.end();polyIt++){
+// std::vector<VoronoiCell>& poly = *polyIt;
+// drawPolygon(poly);
+// }
+ vboMesh.draw();
glDisable(GL_DEPTH_TEST); //REVISIT instead of enable and disable -> popStyle
}
@@ -165,7 +172,7 @@ void ofxVoronoiGL::drawPolygon(std::vector<VoronoiCell> & poly){
if(skeleton){
if(v1.angle(v2)<0){
- colorCone.set(0,0,0);
+ colorCone.set(0,0,0); //TODO use alpha channel?!
color = p2.color;
}
}else if(perFeatureV){
@@ -197,11 +204,14 @@ void ofxVoronoiGL::drawTent(VoronoiCell p1, VoronoiCell p2, ofColor &color){
}else{
ofSetColor(color.r,color.g,color.b);
}
- glBegin(GL_QUADS);
+ glBegin(GL_TRIANGLES);
glVertex3f(p1.x,p1.y,0);
glVertex3f(p2.x,p2.y,0);
glVertex3f(p2.x + pn1.x ,p2.y + pn1.y ,-R);
+
+ glVertex3f(p2.x + pn1.x ,p2.y + pn1.y ,-R);
glVertex3f(p1.x + pn1.x ,p1.y + pn1.y ,-R);
+ glVertex3f(p1.x,p1.y,0);
glEnd();
View
18 src/ofxVoronoiGL.h
@@ -73,6 +73,8 @@ class ofxVoronoiGL{
ofFbo fbo;
ofPixels pixels;
+ ofVboMesh vboMesh;
+
ofCamera cam;
std::vector<VoronoiCell> points;
@@ -84,6 +86,22 @@ class ofxVoronoiGL{
int steps;
void createVoronoi();
+ void createConeMesh(int peakX, int peakY, ofColor &color){
+ steps = (int)(360.f / alpha)+1;
+ alphaUse = 360.f / (float)steps;
+ for(int i=0;i<steps;i++){
+ vboMesh.addVertex(ofVec3f(peakX,peakY,0));
+ float x = R * sin(alphaUse*i*PI/180);
+ float y = R * cos(alphaUse*i*PI/180);
+ vboMesh.addVertex(ofVec3f(peakX+x,peakY+y,-R));
+ x = R * sin(alphaUse*(i+1)*PI/180);
+ y = R * cos(alphaUse*(i+1)*PI/180);
+ vboMesh.addVertex(ofVec3f(peakX+x,peakY+y,-R));
+ for(int j=0;j<3;++j){
+ vboMesh.addColor(color);
+ }
+ }
+ }
void drawCone(int x, int y, ofColor& color);
void drawCone(VoronoiCell p, ofColor& color){

0 comments on commit 9d390fb

Please sign in to comment.