Esempio n. 1
0
    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];
        }

    }
//--------------------------------------------------------------
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;
}
//----------------------------------------
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);
}
Esempio n. 4
0
//--------------------------------------------------------------
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() ;
    }
}
Esempio n. 5
0
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;    
	float a  = normal.dot(tv0);
	float b = normal.dot(raydir);
			
				
		
           float r  = -a / b;        
	if (b==0){r =10000;}


			
		
	
                

	ofVec3f intersectionPoint ;
	intersectionPoint.set(rayStartPoint.x + (raydir.x * r), rayStartPoint.y + (raydir.y * r), rayStartPoint.z + (raydir.z * r));
	vert.position = intersectionPoint;

	



	ofVec3f vp1,vp2,vp0;
	vp0.set(v0->position.x,v0->position.y,v0->position.z);
	vp1.set(v1->position.x,v1->position.y,v1->position.z);
	vp2.set(v2->position.x,v2->position.y,v2->position.z);
	
	float  b0  = barMass(intersectionPoint, vp1, vp2);
	float  b1  = barMass(intersectionPoint, vp0, vp2);
	float  b2  = barMass(intersectionPoint, vp0, vp1);
	
	float  bn = b0 + b1 + b2;
	b0 /= bn;
	b1 /= bn;
	b2 /= bn;
	
	
	vert.normal=(v0->normal *b0)+(v1->normal *b1)+(v2->normal *b2);
	return vert;
	
}