Beispiel #1
0
void pose(int a){
	int i;
	for(i=0;i<4;i++){
		if(a&(1<<i))
			frec[i]=vrt(frec[i]);
		else
			frec[i]=hor(frec[i]);
	}
}
Beispiel #2
0
void
Camera::LookAt(const Point& target)
{
    // No navel gazing:
    if (target == Pos())
    return;

    Point tgt, tmp = target - Pos();

    // Rotate into the view orientation:
    tgt.x = (tmp * vrt());
    tgt.y = (tmp * vup());
    tgt.z = (tmp * vpn());

    if (tgt.z == 0) {
        Pitch(0.5);
        Yaw(0.5);
        LookAt(target);
        return;
    }

    double az = atan(tgt.x/tgt.z);
    double el = atan(tgt.y/tgt.z);

    // if target is behind, offset by 180 degrees:
    if (tgt.z < 0)
    az -= PI;

    Pitch(-el);
    Yaw(az);

    // roll to upright position:
    double deflection = vrt().y;
    while  (fabs(deflection) > 0.001) {
        double theta = asin(deflection/vrt().length());
        Roll(-theta);

        deflection = vrt().y;
    }
}
Beispiel #3
0
void sto(rect nr){
	int i;
	nr=vrt(nr);
	if(min){
		if(min>nr.w*nr.h){min=nr.w*nr.h;sz=1;bxs[0]=nr;return;}
		if(min==nr.w*nr.h){
			for(i=0;i<sz;i++)
				if(bxs[i].w==nr.w)return;
			bxs[sz++]=nr;
		}
	}else{
		min=nr.w*nr.h;
		sz=1;bxs[0]=nr;
	}
}
Beispiel #4
0
//! @brief Constructor.
//!
//! The constructor is responsible for constructing the graph given {\em
//! theModel}. It creates the vertices of the graph, one for every
//! equation  (each DOF that has not been constrained out by the
//! constraint handler)  in the model and adds all edges based on the
//! FE\_Element connectivity. For this reason the model must be fully
//! populated with the DOF\_Group and FE\_Element objects before
// the constructor is called.
XC::DOF_GroupGraph::DOF_GroupGraph(const AnalysisModel &theModel)
  :ModelGraph(theModel.getNumDOF_Groups()+START_VERTEX_NUM,theModel)
  {
    assert(myModel);
    const int numVertex= myModel->getNumDOF_Groups();

    if(numVertex>0)
      {
	
        const DOF_Group *dofGroupPtr= nullptr;

        // now create the vertices with a reference equal to the DOF_Group number.
        // and a tag which ranges from 0 through numVertex-1
        DOF_GrpConstIter &dofIter2 = myModel->getConstDOFs();
        while((dofGroupPtr = dofIter2()) != 0)
          {
	    const int DOF_GroupTag = dofGroupPtr->getTag();
            const int DOF_GroupNodeTag = dofGroupPtr->getNodeTag();
	    const int numDOF = dofGroupPtr->getNumFreeDOF();
            Vertex vrt(DOF_GroupTag, DOF_GroupNodeTag, 0, numDOF);
            this->addVertex(vrt);
          }


        // now add the edges, by looping over the Elements, getting their
        // IDs and adding edges between DOFs for equation numbers >= START_EQN_NUM
    
        const FE_Element *elePtr= nullptr;
        FE_EleConstIter &eleIter = myModel->getConstFEs();
        while((elePtr = eleIter()) != 0)
          {
	    const ID &id= elePtr->getDOFtags();
	    const int size = id.Size();
            for(int i=0; i<size; i++)
              {
	        int dof1 = id(i);
	        for(int j=0; j<size; j++)
                  if(i != j)
                    {
		      const int dof2 = id(j);
		      this->addEdge(dof1,dof2);
		    }
	      }
          }
      }
  }
Beispiel #5
0
bool
Camera::Padlock(const Point& target, double alimit, double e_lo, double e_hi)
{
    // No navel gazing:
    if (target == Pos())
    return false;

    Point tgt, tmp = target - Pos();

    // Rotate into the view orientation:
    tgt.x = (tmp * vrt());
    tgt.y = (tmp * vup());
    tgt.z = (tmp * vpn());

    if (tgt.z == 0) {
        Yaw(0.1);

        tgt.x = (tmp * vrt());
        tgt.y = (tmp * vup());
        tgt.z = (tmp * vpn());

        if (tgt.z == 0)
        return false;
    }

    bool   locked  = true;
    double az      = atan(tgt.x/tgt.z);
    double orig    = az;

    // if target is behind, offset by 180 degrees:
    if (tgt.z < 0)
    az -= PI;

    while (az >  PI) az -= 2*PI;
    while (az < -PI) az += 2*PI;

    if (alimit > 0) {
        if (az < -alimit) {
            az = -alimit;
            locked = false;
        }
        else if (az > alimit) {
            az = alimit;
            locked = false;
        }
    }

    Yaw(az);

    // Rotate into the new view orientation:
    tgt.x = (tmp * vrt());
    tgt.y = (tmp * vup());
    tgt.z = (tmp * vpn());

    double el      = atan(tgt.y/tgt.z);

    if (e_lo > 0 && el < -e_lo) {
        el = -e_lo;
        locked = false;
    }

    else if (e_hi > 0 && el > e_hi) {
        el = e_hi;
        locked = false;
    }

    Pitch(-el);

    return locked;
}
Beispiel #6
0
main () {
    FILE *fin  = fopen ("packrec.in", "r");
    FILE *fout = fopen ("packrec.out", "w");
    int rw,rh,era,ret,m[4]={0};
	int i,j,k;
	rect rt,rt2,a,b,c,d;
	
	for(i=0;i<4;i++){
		fscanf (fin, "%d %d", &(frec[i].w),&(frec[i].h));
		frec[i]=vrt(frec[i]);
	}

	for(i=0;i<16;i++){//A
		pose(i);
		rt.w=rt.h=0;
		for(k=0;k<4;k++){
			rt=cnnt(rt,frec[k],1,0);
		}
		sto(rt);
	}
	
	for(i=0;i<16;i++){//B
		pose(i);
		for(j=0;j<24;j++){
			rt.w=rt.h=0;
			rt=cnnt(rt,frec[pm[j][0]],1,0);
			rt=cnnt(rt,frec[pm[j][1]],1,0);
			rt=cnnt(rt,frec[pm[j][2]],1,0);
			rt=cnnt(rt,frec[pm[j][3]],0,0);
			sto(rt);
		}
	}
	
	for(i=0;i<16;i++){//C
		pose(i);
		for(j=0;j<24;j++){
			rt.w=rt.h=0;
			rt=cnnt(rt,frec[pm[j][0]],1,0);
			rt=cnnt(rt,frec[pm[j][1]],1,0);
			rt=cnnt(rt,frec[pm[j][2]],0,0);
			rt=cnnt(rt,frec[pm[j][3]],1,0);
			sto(rt);
		}
	}
	
	for(i=0;i<16;i++){//D,E
		pose(i);
		for(j=0;j<24;j++){
			rt.w=rt.h=0;
			rt=cnnt(rt,frec[pm[j][0]],1,0);
			rt=cnnt(rt,frec[pm[j][1]],0,0);
			rt=cnnt(rt,frec[pm[j][2]],1,0);
			rt=cnnt(rt,frec[pm[j][3]],1,0);
			sto(rt);
		}
	}
	
	for(i=0;i<16;i++){//F
		pose(i);
		for(j=0;j<24;j++){
			rt.w=rt.h=rt2.w=rt2.h=0;
			rt=cnnt(rt,a=frec[pm[j][0]],1,0);
			rt=cnnt(rt,b=frec[pm[j][1]],0,0);
			rt2=cnnt(rt2,c=frec[pm[j][2]],1,0);
			rt2=cnnt(rt2,d=frec[pm[j][3]],0,0);
			rt=cnnt(rt,rt2,1,0);
			if(b.h<d.h&&c.w>d.w&&a.w<b.w)
				rt.w=max(b.w+d.w,a.w+c.w);
			sto(rt);
		}
	}
	
	/*//ver0.1
	rw=0;rh=0;ret=0;
	for(i=0;i<4;i++){
		fscanf (fin, "%d %d", &(frec[i].w),&(frec[i].h));
		frec[i]=vrt(frec[i]);
		if (frec[i].w>frec[i].h){
			swap(&(frec[i].w),&(frec[i].h));
		}
		rw+=frec[i].h;
	}
	rh=rw;
	era=rw*rh;
	*/
	
	//type A
	/*//ver0.2
	rt.w=rt.h=0;
	for(i=0;i<4;i++){
		rt=cnnt(rt,frec[i],1,0);
	}
	sto(vrt(rt));
	*/
	/*//ver0.1
	rh=0;
	for(i=0;i<4;i++){
		if(frec[i].h>rh)rh=frec[i].h;
		rw+=frec[i].w;
	}
	rt.w=rw;rt.h=rh;
	sto(rt);
	*/
	
	//type B
	/*//ver0.2
	rt.w=rt.h=0;
	for(i=0;i<4;i++){
		m[i]=1;
		for(j=0;j<4;j++){
			if(!m[j])rt=cnnt(rt,frec[j],1,0);
		}
		sto(vrt(rt,hor(frec[i])));
		m[i]=0;
	}
	*/
	/*//ver0.1
	for(i=0;i<4;i++)m[i]=0;
	for(i=0;i<4;i++){
		m[i]=1;
		rw=frec[i].h;rh=0;t=0;
		for(j=0;j<4;j++){
			if(!m[j]){
				t+=frec[j].w;
				if (frec[j].h>rh)rh=frec[j].h;
			}
		}
		rw=max(rw,t);
		rh+=frec[i].w;
		rt.w=rw;rt.h=rh;
		sto(rt);
		m[i]=0;
	}
	*/
	
	//type C 
	/*//ver0.2
	for(i=0;i<4;i++){
		m[i]=1;
		for(j=0;j<4;j++){
			if(!m[j]){
				m[j]=1;
				rt.w=rt.h=0;
				for(k=0;k<4;k++){
					if(!frec[k]){
						rt=cnnt(rt,frec[k],1,0);
					}
				}
				rt=cnnt(rt,hor(frec[j]),0,0);
				rt=cnnt(rt,frec[i],1,0);
				sto(vrt(rt));
				m[j]=0;
			}
		}
		m[i]=0;
	}
	*/
	/*//ver0.1
	for(i=0;i<4;i++)m[i]=0;
	for(i=0;i<4;i++){
		m[i]=1;
		for(j=0;j<4;j++){
			if(!m[j]){
				m[j]=1;
				rw=0;rh=0;
				for(k=0;k<4;k++){
					if(!frec[k]){
						if(frec[k].h>rh)rh=frec[k].h;
						rw+=frec[k].w;
					}
				}
				rh+=frec[j].w;
				rw=max(frec[j].h,rw);
				rw+=frec[i].w;
				rh=max(frec[i].h,rh);
				rt.w=rw;rt.h=rh;
				sto(rt);
				m[j]=0;
			}
		}
		m[i]=0;
	}
	*/
	
	//type D
	/*//ver0.2
	for(i=0;i<4;i++){
		m[i]=1;
		for(j=0;j<4;j++){
			if(!m[j]){
				m[j]=1;
				rt.w=rt.h=0;
				for(k=0;k<4;k++){
					if(!frec[k]){
						rt=cnnt(rt,frec[k],0,0);
					}
				}
				rt=cnnt(rt,hor(frec[j]),1,0);
				rt=cnnt(rt,frec[i],1,0);
				sto(vrt(rt));
				m[j]=0;
			}
		}
		m[i]=0;
	}
	*/
	//type E same as D
	//type F
	
	qsort(bxs,sz,sizeof(rect),cmp);
	fprintf (fout, "%d\n", min);
	for(i=0;i<sz;i++){
		fprintf (fout, "%d %d\n", bxs[i].w, bxs[i].h);
	}
    exit (0);
}
Beispiel #7
0
void Camera::updateCenter()
{
    // Center on target for doing rotation ...
    if ( 0 != _turnTime )
    {
        _center[kX] = _center[kX] * 0.9f + _trackPos[kX] * 0.1f;
        _center[kY] = _center[kY] * 0.9f + _trackPos[kY] * 0.1f;
    }
    else
    {
        // Determine tracking direction.
		Vector3f track_vec = _trackPos - _position;

        // Determine the size of the dead zone.
        float track_fov = DEFAULT_FOV * 0.25f;
        float track_dist = track_vec.length();
        float track_size = track_dist * std::tan(track_fov);
        float track_size_x = track_size;
        float track_size_y = track_size;  /// @todo adjust this based on the camera viewing angle

        // Calculate the difference between the center of the tracked characters
        // and the center of the camera look to look at.
		Vector2f diff = Vector2f(_trackPos[kX],_trackPos[kY]) - Vector2f(_center[kX],_center[kY]);

        // Get 2d versions of the camera's right and up vectors.
		Vector2f vrt(_right[kX], _right[kY]);
		vrt.normalize();

		Vector2f vup(_up[kX], _up[kY]);
		vup.normalize();

        // project the diff vector into this space
        float diff_rt = vrt.dot(diff);
        float diff_up = vup.dot(diff);

        // Get ready to scroll ...
		Vector2f scroll;
        if (diff_rt < -track_size_x)
        {
            // Scroll left
            scroll += vrt * (diff_rt + track_size_x);
        }
        if (diff_rt > track_size_x)
        {
            // Scroll right.
            scroll += vrt * (diff_rt - track_size_x);
        }

        if (diff_up > track_size_y)
        {
            // Scroll down.
            scroll += vup * (diff_up - track_size_y);
        }

        if (diff_up < -track_size_y)
        {
            // Scroll up.
            scroll += vup * (diff_up + track_size_y);
        }

        // Scroll.
        _center[XX] += scroll[XX];
        _center[YY] += scroll[YY];
    }

    // _center.z always approaches _trackPos.z
    _center[kZ] = _center[kZ] * 0.9f + _trackPos[kZ] * 0.1f; /// @todo Use Ego::Math::lerp
}