本文整理汇总了C++中ofVec3f::distance方法的典型用法代码示例。如果您正苦于以下问题:C++ ofVec3f::distance方法的具体用法?C++ ofVec3f::distance怎么用?C++ ofVec3f::distance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofVec3f
的用法示例。
在下文中一共展示了ofVec3f::distance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: disturbMidpoint
void disturbMidpoint(ofVec3f & midPoint, ofVec3f const & bottomLeft, ofVec3f const & topLeft, ofVec3f const & topRight, ofVec3f const & bottomRight) {
//if (std::rand() % 2 == 0) {
// return;
//}
midPoint[2] += (topLeft.distance(bottomRight) + topRight.distance(bottomLeft)) * randomValue();
if (midPoint[2] < minHeight) {
minHeight = midPoint[2];
}
if (midPoint[2] > maxHeight) {
maxHeight = midPoint[2];
}
}
示例2: moveback
//--------------------------------------------------------------
ofVec3f ofApp::moveback(ofVec3f fltPos, ofVec3f aggPos,float aggRadius, float fltRadius){
float disAct = fltPos.distance(aggPos);
float disShould = aggRadius + fltRadius;
ofVec3f tpmoveBack = fltPos - aggPos;
tpmoveBack.normalize();
tpmoveBack = tpmoveBack * (disShould - disAct);
fltPos = fltPos + tpmoveBack;
return fltPos;
}
示例3: frameBoundingBox
//----------------------------------------
void ofxViewportCam::frameBoundingBox(const ofVec3f &minCorner,
const ofVec3f &maxCorner)
{
ofVec3f center((minCorner + maxCorner) * 0.5f);
setTargetPosition(center);
this->distance = minCorner.distance(maxCorner);
setPosition(target.getGlobalPosition());
dolly(this->distance);
}
示例4: update
//--------------------------------------------------------------
void testApp::update(){
ofVec3f diff ; //Difference between particle and mouse
float dist ; //distance from particle to mouse ( as the crow flies )
float ratio ; //Ratio of how strong the effect is = 1 + (-dist/maxDistance) ;
const ofVec3f mousePosition = ofVec3f( mouseX , mouseY , 0 ) ; //Allocate and retrieve mouse values once.
const ofVec3f origin = ofVec3f(0,0,0);
//Create an iterator to cycle through the vector
std::vector<Particle>::iterator p ;
for ( p = particles.begin() ; p != particles.end() ; p++ )
{
ratio = 1.0f ;
p->velocity *= friction ;
//reset acceleration every frame
p->acceleration = ofVec3f() ;
diff = mousePosition - p->position ;
dist = mousePosition.distance( p->position ) ;
//If within the zone of interaction
if ( dist * .5 < forceRadius )
{
ratio = -1 + dist / forceRadius ;
//Repulsion
if ( cursorMode == 0 )
p->acceleration -= ( diff * ratio) ;
//Attraction
else
p->acceleration += ( diff * ratio ) ;
}
if ( springEnabled )
{
//Move back to the original position
p->acceleration += springFactor * (p->spawnPoint - p->position );
}
p->velocity += p->acceleration * ratio ;
p->position += p->velocity ;
}
if ( ofGetFrameNum() % 300 == 0 )
{
curImageIndex++ ;
setupParticles() ;
}
}
示例5: getVertexforPos
TerrainVertex ChunkHandler::getVertexforPos(const ofVec3f &pos, int detailLevel)
{
TerrainVertex vert ;
vert.position.y =0;
Chunk *chunk = getClosestChunk(pos, detailLevel);
if (chunk==NULL) {
return vert;
}
ofVec2f posSearch;
posSearch.x = pos.x;
posSearch.y= pos.z;
posSearch.x-=chunk->center.x-chunkSize/2;
posSearch.y-=chunk->center.z-chunkSize/2;
posSearch.x/=4.0f;
posSearch.y/=4.0f;
int posX0 =floor( posSearch.x+0.5);
int posY0 =floor( posSearch.y+0.5);
v0 = chunk->getVertexForXY( posX0,posY0);
float difx = posSearch.x-posX0;
float dify = posSearch.y;
int posX1= posX0 ;
int posX2= posX0 ;
int posY1= posY0 ;
int posY2= posY0 ;
if (pos.x <v0->position.x)
{
if (pos.z >v0->position.z)
{
posX2-=1;
posY2+=1;
v1 = chunk->getVertexForXY( posX0-1,posY0);
v2 = chunk->getVertexForXY( posX0,posY0+1);
if(pos.distance(v1->position)<pos.distance(v2->position))
{
posX1-=1;
}else
{
posY1+=1;
}
}else
{
posY2-=1;
posX1-=1;
}
}else
{
if (pos.z >v0->position.z)
{
posY2+=1;
posX1+=1;
}else
{
posX2+=1;
posY2-=1;
v1 = chunk->getVertexForXY( posX0+1,posY0);
v2 = chunk->getVertexForXY( posX0,posY0-1);
if(pos.distance(v1->position)<pos.distance(v2->position))
{
posX1+=1;
}
else
{
posY1-=1;
}
}
}
v1 = chunk->getVertexForXY( posX1,posY1);
v2 = chunk->getVertexForXY( posX2,posY2);
ofVec3f normal= terrainFunctions->getNormal(v0->position,v1->position,v2->position);
///
ofVec3f rayStartPoint;
rayStartPoint.set(pos.x,10000,pos.z);
ofVec3f raydir;
raydir.set(0,-1,0);
if (normal.y<0)normal*=-1;
ofVec3f tv0 = rayStartPoint -v0->position;
//.........这里部分代码省略.........