本文整理汇总了C++中ofMesh类的典型用法代码示例。如果您正苦于以下问题:C++ ofMesh类的具体用法?C++ ofMesh怎么用?C++ ofMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ofMesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateMesh
void updateMesh(ofMesh& mesh)
{
float t = ofGetElapsedTimef();
ofVec3f axis;
axis.x = ofSignedNoise(1, 0, 0, t);
axis.y = ofSignedNoise(0, 1, 0, t);
axis.z = ofSignedNoise(0, 0, 1, t);
axis.normalize();
vector<ofVec3f>& verts = mesh.getVertices();
vector<ofVec3f>& norms = mesh.getNormals();
for (int i = 0; i < verts.size(); i++)
{
ofVec3f& v = verts[i];
ofVec3f& n = norms[i];
ofVec3f vv = v;
float r = vv.y * fmodf(t, 10) * 0.1;
vv.rotate(r, axis);
n.rotate(r, axis);
v = vv;
}
}
示例2: updateMesh
//--------------------------------------------------------------
void ofxBulletTriMeshShape::updateMesh( btDiscreteDynamicsWorld* a_world, ofMesh& aMesh ) {
if( aMesh.getNumVertices() != totalVerts || aMesh.getNumIndices() != totalIndices ) {
ofLogWarning() << "updateMesh :: the verts or the indices are not the correct size, not updating";
return;
}
auto& tverts = aMesh.getVertices();
btVector3 aabbMin(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
btVector3 aabbMax(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
for( int i = 0; i < totalVerts; i++ ) {
auto& v = tverts[i];
bullet_vertices[i].setValue( v.x, v.y, v.z );
aabbMin.setMin( bullet_vertices[i] );
aabbMax.setMax( bullet_vertices[i] );
}
btBvhTriangleMeshShape* triShape = (btBvhTriangleMeshShape*)_shape;
// triShape->partialRefitTree( aabbMin, aabbMax );
triShape->refitTree( aabbMin, aabbMax );
//clear all contact points involving mesh proxy. Note: this is a slow/unoptimized operation.
a_world->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs( getRigidBody()->getBroadphaseHandle(), a_world->getDispatcher());
}
示例3: pushVertex
void BGGraphics::pushCirclePart(ofMesh& mesh, ofVec2f position, float nodeRadius, float minAngle, float deltaAngle) {
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
pushVertex(mesh, position.x, position.y, 1, 0, 0, 1, 0, 0);
float innerRadius = nodeRadius - NETWORK_OFFSET;
float internalOffsetY = .5;// innerRadius / nodeRadius;
int samples = (int)(15 * deltaAngle / M_PI);
samples = max(1, samples);
for(int i=0; i<samples; ++i) {
float angle = minAngle + deltaAngle * i / (float)(samples - 1);
ofVec2f to(cosf(angle), sinf(angle));
ofVec2f p1 = position + to * innerRadius;
ofVec2f p2 = position + to * nodeRadius;
//pushVertex(ofMesh & mesh, float x, float y, float z, float nx, float ny, float nz, float offsetX, float offsetY)
pushVertex(mesh, p1.x, p1.y, 1, 0, 0, 1, 0, internalOffsetY);
pushVertex(mesh, p2.x, p2.y, 0, to.x, to.y, 0, 0, 1);
if(i > 0) {
int offset = 1 + 2 * i;
mesh.addTriangle(0, offset - 2, offset);
mesh.addTriangle(offset - 2, offset - 1, offset);
mesh.addTriangle(offset - 1, offset, offset + 1);
}
}
}
示例4: updateMesh
//--------------------------------------------------------------
void ofxBulletSoftTriMesh::updateMesh( ofMesh& aMesh ) {
int totalNodes = getNumNodes();
auto& tverts = aMesh.getVertices();
if( _cachedMesh.getMode() == OF_PRIMITIVE_TRIANGLES ) {
if( tverts.size() != totalNodes ) {
tverts.resize( totalNodes );
}
auto& tnormals = aMesh.getNormals();
if( aMesh.getNumNormals() != totalNodes ) {
tnormals.resize( totalNodes );
}
for( int i = 0; i < totalNodes; i++ ) {
tverts[i].x = _softBody->m_nodes[i].m_x.x();
tverts[i].y = _softBody->m_nodes[i].m_x.y();
tverts[i].z = _softBody->m_nodes[i].m_x.z();
tnormals[i].x = _softBody->m_nodes[i].m_n.x();
tnormals[i].y = _softBody->m_nodes[i].m_n.y();
tnormals[i].z = _softBody->m_nodes[i].m_n.z();
}
}
_lastMeshUpdateFrame = ofGetFrameNum();
}
示例5: createMesh
void ofxPolyline::createMesh(ofMesh &mesh, int begin, int end) {
if (end - begin == 1) {
// If only two points, just make a line.
mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
pair<ofVec2f, ofVec2f> joint = jointBegin((*this)[begin], (*this)[end], width);
mesh.addVertex(joint.first);
mesh.addVertex(joint.second);
joint = jointEnd((*this)[begin], (*this)[end], width);
mesh.addVertex(joint.first);
mesh.addVertex(joint.second);
return;
} else if (end - begin == 0) {
// Return no mesh
return;
}
// More than two points
if (strokeLinejoin == OFXSVG_STROKE_LINEJOIN_MITER) {
createMeshMiterJoint(mesh, begin, end);
} else if (strokeLinejoin == OFXSVG_STROKE_LINEJOIN_BEVEL) {
createMeshBevelJoint(mesh, begin, end);
} else if (strokeLinejoin == OFXSVG_STROKE_LINEJOIN_ROUND) {
createMeshRoundJoint(mesh, begin, end);
}
}
示例6: ofBitmapStringGetMesh
ofMesh & ofBitmapStringGetMesh(const string & text, int x, int y){
int len = (int)text.length();
//float yOffset = 0;
float fontSize = 8.0f;
bool bOrigin = false;
float sx = x;
float sy = y-fontSize;
ofDrawBitmapCharacterStart(text.size());
for(int c = 0; c < len; c++){
if(text[c] == '\n'){
sy += bOrigin ? -1 : 1 * (fontSize*1.7);
sx = x;
//glRasterPos2f(x,y + (int)yOffset);
} else if (text[c] >= 32){
// < 32 = control characters - don't draw
// solves a bug with control characters
// getting drawn when they ought to not be
ofDrawBitmapCharacter(text[c], (int)sx, (int)sy);
sx += fontSize;
}
}
//We do this because its way faster
charMesh.getVertices().resize(vC);
charMesh.getTexCoords().resize(vC);
return charMesh;
}
示例7: getClosestTripletOnMesh
int getClosestTripletOnMesh(const ofMesh& objectMesh,const ofMesh& imageMesh, float x, float y, float* distance) {
float bestDistance = numeric_limits<float>::infinity();
int bestChoice = 0;
for(int i = 0; i < objectMesh.getNumIndices()/3; i++) {
ofVec3f cur = ofVec3f(0,0,0);
for (int j=0;j<3;j++) {
cur+=imageMesh.getVerticesPointer()[objectMesh.getIndexPointer()[3*i+j]];
}
cur/=3.0;
float dx = x - cur.x;
float dy = y - cur.y;
float dz = 0 - cur.z;
float curDistance = dx * dx + dy * dy + dz * dz;
if(curDistance < bestDistance) {
bestDistance = curDistance;
bestChoice = i;
}
}
return bestChoice;
}
示例8: ofxScale
void ofxScale(ofMesh &mesh, float x, float y, float z) {
for (int i=0; i<mesh.getNumVertices(); i++) {
mesh.getVertices()[i].x *= x;
mesh.getVertices()[i].y *= y;
mesh.getVertices()[i].z *= z;
}
}
示例9: convertFromIndices
ofMesh convertFromIndices(const ofMesh& mesh) {
ofMesh result;
// have to do a const_cast because ofMesh::get*() is not const correct
ofMesh& cmesh = const_cast<ofMesh&>(mesh);
int vertices = mesh.getNumVertices();
int colors = mesh.getNumColors();
int normals = mesh.getNumNormals();
int texcoords = mesh.getNumTexCoords();
int indices = mesh.getNumIndices();
for(int i = 0; i < indices; i++) {
int cur = cmesh.getIndex(i);
if(vertices > 0) {
result.addVertex(cmesh.getVertex(cur));
}
if(colors > 0) {
result.addColor(cmesh.getColor(cur));
}
if(normals > 0) {
result.addNormal(cmesh.getNormal(cur));
}
if(texcoords > 0) {
result.addTexCoord(cmesh.getTexCoord(cur));
}
}
return result;
}
示例10: setMesh
//--------------------------------------------------------------
void ofVboByteColor::setMesh(const ofMesh & mesh, int usage){
setVertexData(mesh.getVerticesPointer(),mesh.getNumVertices(),usage);
setColorData(mesh.getColorsPointer(),mesh.getNumColors(),usage);
setNormalData(mesh.getNormalsPointer(),mesh.getNumNormals(),usage);
setTexCoordData(mesh.getTexCoordsPointer(),mesh.getNumTexCoords(),usage);
setIndexData(mesh.getIndexPointer(), mesh.getNumIndices(), usage);
}
示例11: addCircle
//http://www.packtpub.com/sites/default/files/9781849518048_Chapter_07.pdf
//knotExample
void ofApp::addCircle( ofVec3f nextPoint, ofMesh &mesh ){
float time = ofGetElapsedTimef(); //Time
//Parameters – twisting and rotating angles and color
ofFloatColor color( ofNoise( time * 0.05 ),
ofNoise( time * 0.1 ),
ofNoise( time * 0.15 ));
color.setSaturation( 1.0 ); //Make the color maximally
//Add vertices
for (int i=0; i<circleN; i++) {
float angle = float(i) / circleN * TWO_PI+(PI*0.25);
float x = Rad * cos( angle );
float y = Rad * sin( angle );
ofPoint p = nextPoint+ofVec3f(x ,y , 0);
mesh.addVertex( p );
mesh.addColor( color );
}
//Add the triangles
int base = mesh.getNumVertices() - 2 * circleN;
if ( base >= 0 ) { //Check if it is not the first step
//and we really need to add the triangles
for (int i=0; i<circleN; i++) {
int a = base + i;
int b = base + (i + 1) % circleN;
int c = circleN + a;
int d = circleN + b;
mesh.addTriangle(a,b,d);
mesh.addTriangle(a, d, c);
}
//Update the normals
setNormals( mesh );
}
}
示例12: colorFaces
//--------------------------------------------------------------
void ofApp::colorFaces(ofMesh & mesh){
for(int i = 0; i < mesh.getVertices().size(); i++){
const ofVec3f & v = mesh.getVertices()[i];
ofColor col;
col.setHsb(ofMap(v.x + v.y, -1000, 1000, 0, 255), 255, 255);
mesh.addColor(col);
}
}
示例13: 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;
}
示例14: getCentroid
ofVec3f getCentroid(ofMesh& mesh){
ofVec3f sum;
for(int i=0;i<mesh.getNumVertices();i++){
sum+=mesh.getVertex(i);
}
sum/=mesh.getNumVertices();
return sum;
}
示例15: ofSetTextureWrap
//--------------------------------------------------------------
void testApp::draw(){
fbo.begin();
ofSetTextureWrap(GL_REPEAT,GL_REPEAT);
fbfbo.draw(0,2);
//cam.draw(0,0);
fbfbo.getTextureReference().bind();
trik2.draw();
fbfbo.getTextureReference().unbind();
ofSetColor(255,255,255);
if(tritimer>tritimerlimit){
float xpt, ypt,xtoff,ytoff;
//draw gradient splashes
ofMesh trik;
for(int b = 0;b<5;b++){
xtoff = ofRandomf()*0.5;
ytoff = ofRandomf()*0.5;
for(int i=0;i<3;i++){
xpt = ofRandomuf()*2+xtoff;
ypt = ofRandomuf()*2+ytoff;
trik.addVertex(ofVec3f(xpt*w,ypt*h,0));
trik.addColor(ofFloatColor(float(ofRandomuf()>0.5)*0.6+0.4,float(ofRandomuf()>0.5)*0.5+0.5,float(ofRandomuf()>0.5)*0.7+0.3));
}
}
trik.draw();
tritimer = 0;
tritimerlimit= ofRandom(20,200);
}
if(tritimer2>45){
//re-generate the feedback triangles
float xpt, ypt,xoff,yoff,xtoff,ytoff;
trik2.clear();
//ofEnableNormalizedTexCoords();
for(int b = 0;b<5;b++){
xoff = ofRandomf()*0.1;
yoff = ofRandomf()*0.1;
xtoff = ofRandomf()*0.5;
ytoff = ofRandomf()*0.5;
for(int i=0;i<3;i++){
xpt = ofRandomuf()+xtoff;
ypt = ofRandomuf()+ytoff;
trik2.addVertex(ofVec3f((xpt+xoff)*w,(ypt+yoff)*h,0));
trik2.addTexCoord(ofVec2f(xpt*w,ypt*h));
trik2.addColor(ofFloatColor(1,1,1));
}
}
tritimer2=0;
tritimer2limit= ofRandom(20,200);
//ofDisableNormalizedTexCoords();
}
fbo.end();
fbfbo.begin();
fbo.draw(0,0);
fbfbo.end();
fbo.draw(0,0);
}