Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OF 0.10 update for main.cpp and ofxStrip.h files #27

Open
alptugan opened this issue Nov 15, 2019 · 0 comments
Open

OF 0.10 update for main.cpp and ofxStrip.h files #27

alptugan opened this issue Nov 15, 2019 · 0 comments

Comments

@alptugan
Copy link

alptugan commented Nov 15, 2019

** replace main.cpp codes with the following content;

#include "ofMain.h"
#include "testApp.h"
int main( ){

    
    ofGLFWWindowSettings s;
    s.setSize(1024, 768);
    //s.setGLVersion(2, 1);
    
    ofCreateWindow(s);
    
    
	ofRunApp( new testApp());

}

** replace ofxStrip.h codes with the following content;

//Written by Theo Watson - http://theowatson.com
//Work in progress class for doing opengl strips / ribbons 

#pragma once
#include "ofMesh.h"

class ofxStrip{

	public:
	
		ofxStrip(){
			bTexCoords = true;
			bNormals = true;
			tex_u = 1.0;
			tex_v = 1.0; 
		}
	
		void clear(){
			mesh.clear(); 
		}
		
		
		void setTexCoordScale( float tex_u_scale, float tex_v_scale ){
			tex_u = tex_u_scale;
			tex_v = tex_v_scale;
		}
		
    void generate( std::vector<glm::vec3> _pts, float fixedWidth, glm::vec3 upVec){
            std::vector<float> _width;
			_width.push_back(fixedWidth);
			generate( _pts, _width, upVec);
		} 
		
    void generate( std::vector<glm::vec3> pts, std::vector<float> width, glm::vec3 upVec){
			bool  bFixedWidth = false; 
			float curWidth; 
			float maxWidth = 0; 
			
			
			if( width.size() == 1 || ( width.size() && width.size() != pts.size() ) ){
				bFixedWidth = true;
				curWidth  = width[0];
				maxWidth  = curWidth; 
			}
			
			if( !bFixedWidth ){
				for(int i = 0; i < width.size(); i++){
					if( maxWidth > width[i] ){
						maxWidth = width[i];
					}
				}
			}
			
			mesh.clear();
			mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
			
			float numPts = pts.size()-1; 
			for(int i = 1; i < pts.size(); i++){
			
				if( !bFixedWidth ){
					curWidth = width[i];
				}
				
				//find this point and the next point
                glm::vec3 & thisPoint = pts[i-1];
				glm::vec3 & nextPoint = pts[i];
				
				glm::vec3 delta		= nextPoint - thisPoint;
                glm::vec3 deltaNorm	= glm::normalize(delta);
				
                glm::vec3  toTheLeft	= glm::perp(deltaNorm, upVec);
								
				glm::vec3 L = thisPoint + toTheLeft * curWidth;
				glm::vec3 R = thisPoint - toTheLeft * curWidth;
								
				mesh.addVertex(L);
				mesh.addVertex(R);
				
				if( bNormals ){
                    glm::vec3 normal = glm::perp(deltaNorm, -toTheLeft);
					mesh.addNormal(normal);
					mesh.addNormal(normal);					
				}
				
				if( bTexCoords ){
					float texUPct = curWidth / maxWidth; 
					float texVPct = (float)(i-1) / numPts; 
					
					mesh.addTexCoord(ofVec2f((1.0-texUPct) * tex_u, texVPct * tex_v));
					mesh.addTexCoord(ofVec2f(texUPct * tex_u, texVPct * tex_v));
				}
			}

			mesh.setupIndicesAuto();

		}
		
		void enableTexCoords(){
			bTexCoords = true;
		}
		
		void disableTexCoords(){
			bTexCoords = false;
		}

		void enableNormals(){
			bNormals = true;
		}
		
		void disableNormals(){
			bNormals = false;
		}				
		
		ofMesh getMesh(){
			return mesh;
		}

		float tex_u, tex_v;
		bool bTexCoords; 
		bool bNormals; 

		ofMesh mesh; 
};


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant