Skip to content

Commit

Permalink
Merge pull request #967 from kpasko/develop
Browse files Browse the repository at this point in the history
normals example modification
  • Loading branch information
ofTheo committed Feb 25, 2012
2 parents 07f20eb + 25c2ab3 commit ffa3de1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
11 changes: 7 additions & 4 deletions examples/3d/normalsExample/src/testApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ void testApp::setup(){

//loop around and make verts in a circle, with a bit of a z-wave
for (int i = 0; i < max; i++){
// radians around circle
float theta = i*2*PI/max; // step size
float prevTheta = theta - 2*PI/max; //one step back
float nextTheta = theta + 2*PI/max; // one step forward
float step = 2*PI/max; // step size around circle
float theta = ofMap(i, 0, max-1, 0, 2*PI - step); //map i as circle divisions to actual radian values around the circle (note we don't go quite all the way around by one step, because it will be the same as where we started, so we'll just index that starting vertex when we make faces)

float prevTheta = theta - step; //one step back
float nextTheta = theta + step; // one step forward

// create vertices in polar coordinates, plus a sine wave for z
ofVec3f p(radius*cos(theta),radius*sin(theta), radius*zamt*sin(zfreq*theta) );
Expand Down Expand Up @@ -67,6 +68,8 @@ void testApp::setup(){
light.setPointLight();
light.setPosition(0,0,300);

cam.cacheMatrices();

}

//--------------------------------------------------------------
Expand Down
65 changes: 58 additions & 7 deletions libs/openFrameworks/3d/ofMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ofMesh::ofMesh(){
useColors = true;
useTextures = true;
useNormals = true;

}

//--------------------------------------------------------------
Expand All @@ -32,7 +32,7 @@ void ofMesh::clear(){
bNormalsChanged = true;
bTexCoordsChanged = true;
bIndicesChanged = true;

vertices.clear();
colors.clear();
normals.clear();
Expand Down Expand Up @@ -221,6 +221,57 @@ void ofMesh::addTriangle(ofIndexType index1, ofIndexType index2, ofIndexType ind
addIndex(index3);
}

//REMOVERS
//--------------------------------------------------------------
void ofMesh::removeVertex(int index){
if(index >= vertices.size()){
ofLog(OF_LOG_ERROR,"Trying to remove vertex out of range of this mesh. Taking no action.");
}else{
vertices.erase(vertices.begin() + index);
bVertsChanged = true;
}
}

//--------------------------------------------------------------
void ofMesh::removeNormal(int index){
if(index >= vertices.size()){
ofLog(OF_LOG_ERROR,"Trying to remove normal out of range of this mesh. Taking no action.");
}else{
normals.erase(normals.begin() + index);
bNormalsChanged = true;
}
}

//--------------------------------------------------------------
void ofMesh::removeColor(int index){
if(index >= vertices.size()){
ofLog(OF_LOG_ERROR,"Trying to remove color out of range of this mesh. Taking no action.");
}else{
colors.erase(colors.begin() + index);
bColorsChanged = true;
}
}

//--------------------------------------------------------------
void ofMesh::removeTexCoord(int index){
if(index >= vertices.size()){
ofLog(OF_LOG_ERROR,"Trying to remove texCoord out of range of this mesh. Taking no action.");
}else{
texCoords.erase(texCoords.begin() + index);
bTexCoordsChanged = true;
}
}

//--------------------------------------------------------------
void ofMesh::removeIndex(int index){
if(index >= vertices.size()){
ofLog(OF_LOG_ERROR,"Trying to remove index out of range of this mesh. Taking no action.");
}else{
indices.erase(indices.begin() + index);
bIndicesChanged = true;
}
}


//GETTERS
//--------------------------------------------------------------
Expand Down Expand Up @@ -597,7 +648,7 @@ void ofMesh::enableColors(){

//--------------------------------------------------------------
void ofMesh::enableTextures(){
useTextures = true;
useTextures = true;
}

//--------------------------------------------------------------
Expand Down Expand Up @@ -640,7 +691,7 @@ bool ofMesh::usingNormals(){
void ofMesh::load(string path){
ofFile is(path, ofFile::ReadOnly);
ofMesh& data = *this;

string line;
string error;
ofBuffer buffer(is);
Expand Down Expand Up @@ -852,7 +903,7 @@ void ofMesh::load(string path){
continue;
}
}


return;
clean:
Expand Down Expand Up @@ -893,7 +944,7 @@ void ofMesh::save(string path, bool useBinary){
os << "property float nz" << endl;
}
}

unsigned char faceSize = 3;
if(data.getNumIndices()){
os << "element face " << data.getNumIndices() / faceSize << endl;
Expand All @@ -904,7 +955,7 @@ void ofMesh::save(string path, bool useBinary){
}

os << "end_header" << endl;

for(int i = 0; i < data.getNumVertices(); i++){
if(useBinary) {
os.write((char*) &data.getVertices()[i], sizeof(ofVec3f));
Expand Down

0 comments on commit ffa3de1

Please sign in to comment.