本文整理汇总了C++中ofMesh::getVertex方法的典型用法代码示例。如果您正苦于以下问题:C++ ofMesh::getVertex方法的具体用法?C++ ofMesh::getVertex怎么用?C++ ofMesh::getVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofMesh
的用法示例。
在下文中一共展示了ofMesh::getVertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setNormals
//--------------------------------------------------------------
//Universal function which sets normals for the triangle mesh
void setNormals( ofMesh &mesh ){
int nV = mesh.getNumVertices();//640
int nT = mesh.getNumIndices() / 3;//213
vector<ofPoint> norm( nV );
for (int t=0; t<nT; t++) {
int i1 = mesh.getIndex( 3 * t );
int i2 = mesh.getIndex( 3 * t + 1 );
int i3 = mesh.getIndex( 641 );
const ofPoint &v1 = mesh.getVertex( i1 );
const ofPoint &v2 = mesh.getVertex( i2 );
const ofPoint &v3 = mesh.getVertex( i3 );
//Compute the triangle's normal
ofPoint dir = ( (v2 - v1).crossed( v3 - v1 ) ).normalized();
norm[ i1 ] += dir;
norm[ i2 ] += dir;
norm[ i3 ] += dir;
}
//Normalize the normal's length
for (int i=0; i<nV; i++) {
norm[i].normalize();
}
//Set the normals to mesh
mesh.clearNormals();
mesh.addNormals( norm );
}
示例2: setNormals
void PyramidBrush::setNormals(ofMesh& mesh) {
int nV = mesh.getNumVertices();
int nT = mesh.getNumIndices() / 3;
vector<ofPoint> norm(nV);
for(int t=0; t < nT; t++) {
int i1 = mesh.getIndex(3*t);
int i2 = mesh.getIndex(3*t + 1);
int i3 = mesh.getIndex(3*t + 2);
const ofPoint &v1 = mesh.getVertex(i1);
const ofPoint &v2 = mesh.getVertex(i2);
const ofPoint &v3 = mesh.getVertex(i3);
ofPoint dir = ( (v2 - v1).crossed(v3 - v1)).normalized();
norm[i1] += dir;
norm[i2] += dir;
norm[i3] += dir;
}
for(int i = 0; i < nV; i++) {
norm[i].normalize();
}
mesh.clearNormals();
mesh.addNormals(norm);
}
示例3: setNormals
//Universal function which sets normals for the triangle mesh
void ofxOcean::setNormals( ofMesh &mesh ){
//The number of the vertices
int nV = mesh.getNumVertices();
//The number of the triangles
int nT = mesh.getNumIndices() / 3;
vector<ofPoint> norm( nV ); //Array for the normals
//Scan all the triangles. For each triangle add its
//normal to norm's vectors of triangle's vertices
for (int t=0; t<nT; t++) {
//Get indices of the triangle t
int i1 = mesh.getIndex( 3 * t );
int i2 = mesh.getIndex( 3 * t + 1 );
int i3 = mesh.getIndex( 3 * t + 2 );
//Get vertices of the triangle
const ofPoint &v1 = mesh.getVertex( i1 );
const ofPoint &v2 = mesh.getVertex( i2 );
const ofPoint &v3 = mesh.getVertex( i3 );
//Compute the triangle's normal
ofPoint dir = ( (v2 - v1).getCrossed( v3 - v1 ) ).getNormalized();
//Accumulate it to norm array for i1, i2, i3
norm[ i1 ] += dir;
norm[ i2 ] += dir;
norm[ i3 ] += dir;
}
//Normalize the normal's length
for (int i=0; i<nV; i++) {
norm[i].normalize();
}
//Set the normals to mesh
mesh.clearNormals();
mesh.addNormals( norm );
}
示例4: fuseNeighbours
void MeshHelper::fuseNeighbours( ofMesh& outputMesh, const ofMesh& sourceMesh, float fuseDistance )
{
//@todo tex coords, normals
assert( sourceMesh.getMode() == OF_PRIMITIVE_TRIANGLES );
if ( fuseDistance < 0 )
{
// fuse close-enough vertices
// first define 'close enough' as 1/10000 of smallest dimension of the bounding box width/height/depth
ofVec3f tlb, brf; // top left back, bottom right front
calculateAABoundingBox( sourceMesh, tlb, brf );
float minDimension = min(brf.x-tlb.x,min(brf.y-tlb.y, brf.z-tlb.z));
fuseDistance = minDimension * 0.00001f;
}
// now fuse
map<int,int> fused;
vector<ofVec3f> vertices;
for ( int i=0; i<sourceMesh.getNumVertices(); i++ )
{
const ofVec3f& vertex = sourceMesh.getVertex(i);
//vertex.rotate(10, 10, 10);
bool didFuse = false;
for ( int j=0; j<vertices.size(); j++ ) {
if ( (vertex-vertices[j]).length()<fuseDistance ) {
// fuse i to j
fused[i] = j;
didFuse = true;
break;
}
}
if ( !didFuse ) {
vertices.push_back( vertex );
fused[i] = vertices.size()-1;
}
}
// build the output mesh
outputMesh.clear();
outputMesh.addVertices(vertices);
if ( sourceMesh.getNumIndices() > 0 ) {
// walk through indices to build up the new mesh
const vector<ofIndexType>& indices = sourceMesh.getIndices();
for ( int i=0; i<indices.size(); i+=3 ) {
assert( fused.find( indices[i] ) != fused.end() );
assert( fused.find( indices[i+1] ) != fused.end() );
assert( fused.find( indices[i+2] ) != fused.end() );
outputMesh.addTriangle( fused[indices[i]], fused[indices[i+1]], fused[indices[i+2]] );
}
} else {
// triangles are just triples of vertices
for ( int i=0; i<sourceMesh.getNumVertices(); i+=3 ) {
outputMesh.addTriangle( fused[i], fused[i+1], fused[i+2] );
}
}
ofLogNotice("MeshHelper") << "fuseNeighbours: input " << sourceMesh.getNumVertices() << " vertices/" << sourceMesh.getNumIndices() << " indices, output " << outputMesh.getNumVertices() << " vertices/" << outputMesh.getNumIndices() << " indices";
}
示例5: deformMesh
ofMesh ofxFfd::deformMesh(ofMesh mesh){
ofMesh dst;
dst.append(mesh);
for ( int i=0; i<mesh.getNumVertices(); i++ ) {
ofVec3f vec = mesh.getVertex(i);
dst.setVertex(i, deform(vec));
}
return dst;
}
示例6: getCentroid
ofVec3f getCentroid(ofMesh& mesh){
ofVec3f sum;
for(int i=0;i<mesh.getNumVertices();i++){
sum+=mesh.getVertex(i);
}
sum/=mesh.getNumVertices();
return sum;
}
示例7: update
void update() {
int n = mesh.getNumVertices();
int start = ofMap(mouseX, 0, ofGetWidth(), 0, n, true);
controlPoints.clear();
controlPoints.setMode(OF_PRIMITIVE_POINTS);
for(int i = start; i < n; i++) {
unsigned int index = rankedCorners[i];
controlPoints.addVertex(mesh.getVertex(index));
}
}
示例8: drawNormals
void ofApp::drawNormals(const ofMesh& mesh){
for(int i = 0; i < mesh.getVertices().size(); i++){
ofVec3f n = mesh.getNormal(i);
ofVec3f v = mesh.getVertex(i);
ofPushStyle();
ofSetColor(0, 255, 0);
ofLine(v.x, v.y, v.z, v.x + (n.x*4), v.y + (n.y*4), v.z + (n.z*4) );
ofPopStyle();
}
}
示例9: getNearestVertex
float getNearestVertex(const ofMesh& mesh, const ofVec2f& target, int& vertexIndex) {
float bestDistance = 0;
for(int i = 0; i < mesh.getNumVertices(); i++) {
float distance = target.distance(mesh.getVertex(i));
if(distance < bestDistance || i == 0) {
bestDistance = distance;
vertexIndex = i;
}
}
return bestDistance;
}
示例10: sqrt
oscThread::oscThread(ofVec2f origin, ofMesh mesh)
{
originP = mesh.getVertex(origin.x);
destP = mesh.getVertex(origin.y);
length = sqrt(pow(destP.x-originP.x,2)+pow(destP.y-originP.y,2)+pow(destP.z-originP.z,2));
tempO.set(-length/2,0);
tempD.set(length/2,0);
//Rethink these variables, and in what context do they REALLY have influence?
color = ofRandom(255); //Real color of braid. Fixed
res = 200; //Resolution of line
speed = 5; //??
amp = 10; //??
f = 10; //??
numVerts = 0;
tLength = 100;
cSpeed = 40;
}
示例11: check_triangle_intersections
// Returns true iff the mesh contains two index defined traingles that intersect.
bool check_triangle_intersections(ofMesh &mesh)
{
int len = mesh.getNumIndices();
for(int i = 0; i < len; i += 3)
{
ofVec3f v1 = mesh.getVertex(mesh.getIndex(i));
ofVec3f v2 = mesh.getVertex(mesh.getIndex(i + 1));
ofVec3f v3 = mesh.getVertex(mesh.getIndex(i + 2));
for(int j = 0; j < len; j += 3)
{
ofVec3f p1 = mesh.getVertex(mesh.getIndex(j));
ofVec3f p2 = mesh.getVertex(mesh.getIndex(j + 1));
ofVec3f p3 = mesh.getVertex(mesh.getIndex(j + 2));
int b = Intersecting(p1, p2, v1, v2, v3);
int b2 = Intersecting(p2, p3, v1, v2, v3);
int b3 = Intersecting(p3, p1, v1, v2, v3);
if(b == 1 || b2 == 1 || b3 == 1)
{
return true;
}
if(point_triangle_intersection(v1, v2, v3, p1)||
point_triangle_intersection(v1, v2, v3, p2)||
point_triangle_intersection(v1, v2, v3, p3))
{
return true;
}
}
}
return false;
}
示例12: draw
void draw() {
ofBackground(0);
glPointSize(2);
ofSetColor(32);
historyMesh.draw();
ofSetColor(255);
dataMesh.draw();
ofSetColor(255, 0, 0);
neighborsMesh.draw();
for(int i = 0; i < neighborsMesh.getNumVertices(); i++) {
ofLine(neighborsMesh.getVertex(i), ofVec2f(mouseX, mouseY));
}
ofDrawBitmapStringHighlight(ofToString(neighborsMesh.getNumVertices()), mouseX, mouseY);
drawFramerate();
}
示例13: addMessage
void testApp::addMessage(string address, ofMesh data) {
ofxOscMessage msg;
msg.setAddress(address);
int numOfVertices = data.getNumVertices();
for (int i = 0; i < numOfVertices; i++) {
ofVec3f vertex = data.getVertex(i);
msg.addFloatArg(vertex.x);
msg.addFloatArg(vertex.y);
msg.addFloatArg(vertex.z);
}
bundle.addMessage(msg);
}
示例14: getBoundingBox
void getBoundingBox(const ofMesh& mesh, ofVec3f& min, ofVec3f& max) {
int n = mesh.getNumVertices();
if(n > 0) {
min = mesh.getVertex(0);
max = mesh.getVertex(0);
for(int i = 1; i < n; i++) {
const ofVec3f& cur = mesh.getVertices()[i];
min.x = MIN(min.x, cur.x);
min.y = MIN(min.y, cur.y);
min.z = MIN(min.z, cur.z);
max.x = MAX(max.x, cur.x);
max.y = MAX(max.y, cur.y);
max.z = MAX(max.z, cur.z);
}
}
}
示例15: calculateAABoundingBox
void MeshHelper::calculateAABoundingBox( const ofMesh& mesh, ofVec3f& topLeftBack, ofVec3f& bottomRightFront )
{
ofVec3f& tlb = topLeftBack;
ofVec3f& brf = bottomRightFront;
for ( int i=0; i<mesh.getNumVertices(); i++ ) {
ofVec3f vertex = mesh.getVertex(i);
if ( i == 0 ){
tlb = brf = vertex;
continue;
}
tlb.x = min(tlb.x,vertex.x);
tlb.y = min(tlb.y,vertex.y);
tlb.z = min(tlb.z,vertex.z);
brf.x = max(brf.x,vertex.x);
brf.y = max(brf.y,vertex.y);
brf.z = max(brf.z,vertex.z);
}
}