Exemple #1
0
void NavigatorWasdMode::Apply (Trackball * tb, Point3f new_point)
{
  Point3f hitOld = tb->last_point;
  Point3f hitNew = new_point;
	tb->last_point=new_point;
  float dx = (hitNew.X() - hitOld.X());
  float dy = (hitNew.Y() - hitOld.Y());

  const float scale = float(150*M_PI); //sensitivity of the mouse
  const float top = float(0.9f*M_PI/2); //maximum top view angle

  float anglex =  dx/(tb->radius * scale);
  float angley = -dy/(tb->radius * scale * 0.5f);
  alpha+= anglex*_flipH;
  beta += angley*_flipV;
  if(beta > +top) beta = +top;
  if(beta < -top) beta = -top;

  Point3f viewpoint = tb->track.InverseMatrix()*Point3f(0,0,0);
	tb->track.tra = tb->track.rot.Inverse().Rotate(tb->track.tra + viewpoint ) ;
  tb->track.rot = Quaternionf (beta , Point3f(1,0,0)) * 
                  Quaternionf (alpha, Point3f(0,1,0)) ;
	tb->track.tra = tb->track.rot.Rotate(tb->track.tra)  - viewpoint ;

	tb->track.tra[1]+=step_last;
  tb->track.tra[1]-=step_current;
	
	step_last=step_current;

}
void Arcball::MapToSphere(const Point3f* _point, Vector3f* _vector) const
{
	Point3f tempPoint;
	float length;

	//Copy parameter into temp point
	tempPoint = *_point;

	//Adjust point coords and scale down to range of [-1 ... 1]
	float adjustedX;
	float adjustedY;
	adjustedX = (tempPoint.X() * adjustWidth) - 1.0;
	adjustedY = 1.0 - (tempPoint.Y() * adjustHeight);
	tempPoint = Point3f(adjustedX, adjustedY, 0);

	//compute the length of the vector to the point from the center
	*_vector = (tempPoint - Point3f(0, 0, 0));
	length = _vector->Magnitude();

	//if the point is mapped outside of the sphere (length > RSquared)
	if( (length * length) > 1.0)
	{
		//normalize the vector
		_vector->Normalize(); 
	}
	//else it's on the inside
	else
	{
		*_vector = *_vector + Vector3f(0, 0, 1.0 - length);
	}
}
Exemple #3
0
static void ioMB_exportSkeleton(const BrfSkeleton &s){
  for (int i=0; i<(int)s.bone.size(); i++) {
    const BrfBone &bone(s.bone[i]);

    fprintf(f,"createNode joint -n \"%s\" ",substitute(bone.name,'.','_'));
    if (bone.attach!=-1)
    fprintf(f,"-p \"%s\" ",substitute(s.bone[bone.attach].name,'.','_'));
    fprintf(f,";\n");

    float *abc;
    abc = matrix2euler(s.getRotationMatrix( i ).transpose() );
    Point3f t = bone.t;
    if (bone.attach==-1) { float tmp=t[1]; t[1]=t[2]; t[2]=tmp;}
    t.X()*=-1;
    t.Y()*=-1;
    t*=SCALE;

    fprintf(f,
      "\taddAttr -ci true -sn \"liw\" -ln \"lockInfluenceWeights\" -bt \"lock\" -min 0 -max 1 -at \"bool\";\n"
      "\tsetAttr \".uoc\" yes;\n"
      "\tsetAttr \".t\" -type \"double3\" %f %f %f ;\n"
      "\tsetAttr \".r\" -type \"double3\" %f %f %f ;\n"
      "\tsetAttr \".mnrl\" -type \"double3\" -360 -360 -360 ;\n"
      "\tsetAttr \".mxrl\" -type \"double3\" 360 360 360 ;\n",
      -t[0],t[2],-t[1],
      abc[0]*180/M_PI,abc[1]*180/M_PI,abc[2]*180/M_PI
    );

    //qDebug()<< "[" << i << "]: abc" << abc[0]*180/M_PI << abc[1]*180/M_PI <<abc[2]*180/M_PI <<"\n";
  }
}
// kernal that produce ray direction texture
void PhotonMapperGPU::EyeKernel()
{
#ifndef STUB_PHOTONMAPPERGPU
	// figure out necessary eye vectors
	Vector3f nn, vv, uu;
//	nn.set(eyePos.x - look.x, eyePos.y - look.y, eyePos.z - look.z); // make n
//	uu.set(up.cross(nn)); // make u = up X n
//	nn.normalize(); uu.normalize(); // make them unit length
//	vv.set(nn.cross(uu));  // make v =  n X u
 

    nn = m_pCamera->N();
    vv = m_pCamera->V();
    uu = m_pCamera->U();
    Point3f eyePos = m_pCamera->GetEye();
	// firgure out world width and height
    float sH = m_pCamera->GetNearClipPlane() * tan( m_pCamera->GetViewAngle() * (3.1415/360));
    float sW = sH * m_pCamera->GetAspect();

//	cout << eyePos.x << " " << eyePos.y << " " << eyePos.z << endl;

//	cout << sH << " " << sW << endl;

    CShader& ray = m_ShaderManager->GetShader(RAY);

    CGparameter& n = ray.GetNamedParameter("IN2.n");
	cgGLSetParameter3f(n, nn.X(), nn.Y(), nn.Z());

    CGparameter& v = ray.GetNamedParameter("IN2.v");
	cgGLSetParameter3f(v, vv.X(), vv.Y(), vv.Z());

    CGparameter& u = ray.GetNamedParameter("IN2.u");
	cgGLSetParameter3f(u, uu.X(), uu.Y(), uu.Z());

    CGparameter& view = ray.GetNamedParameter("IN2.view");
	cgGLSetParameter2f(view, m_pixelCols, m_pixelRows);

    CGparameter& world = ray.GetNamedParameter("IN2.world");
	cgGLSetParameter2f(world, sW, sH);
    
    CGparameter& nearDist = ray.GetNamedParameter("IN2.nearDist");
    cgGLSetParameter1f(nearDist, m_pCamera->GetNearClipPlane());

    CGparameter& eye = ray.GetNamedParameter("eyePos");
	cgGLSetParameter3f(eye, eyePos.X(), eyePos.Y(), eyePos.Z());
	
	ray.Bind();
    ray.Enable();

	Workspace();
	
    ray.Disable();
#endif // STUB_PHOTONMAPPERGPU
}
Exemple #5
0
// Polar mode implementation.
void PolarMode::Apply (Trackball * tb, Point3f new_point)
{
  Point3f hitOld = HitViewPlane (tb, tb->last_point);
  Point3f hitNew = HitViewPlane (tb, new_point);
  float dx = (hitNew.X() - hitOld.X());
  float dy = (hitNew.Y() - hitOld.Y());

  const float scale = float(0.5*M_PI); //sensitivity of the mouse
  const float top = float(0.9*M_PI/2); //maximum top view angle

  float anglex =  dx/(tb->radius * scale);
  float angley = -dy/(tb->radius * scale);
  enda = alpha + anglex;
  endb = beta + angley;
  if(endb > top) endb = top;
  if(endb < -top) endb = -top;
  tb->track.rot = Quaternionf (endb, Point3f(1,0,0)) * 
                  Quaternionf (enda, Point3f(0,1,0)) ;

}
Exemple #6
0
//
//	Check if the given vertex is visible on the current user view
//			This method is used for rendering vertices labels, and
//			rendering edges/faces
//	Returns: true if visible
bool edit_topo::isVertexVisible(Point3f v)
{
	float   pix;
	double tx,ty,tz;

	gluProject(v.X(),v.Y(),v.Z(), mvmatrix,projmatrix,viewport, &tx,&ty,&tz);
	glReadPixels(tx,ty,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&pix);

	float ff = fabs(tz - pix);

	return ((ff < 0.003));
}
Exemple #7
0
//
//	Get visible vertex nearest to mouse position (from a given vertices list)
//	Returns: true if visible
bool edit_topo::getVisibleVertexNearestToMouse(QList<Vtx> list, Vtx &out)
{
	bool found = false;
	double minDist = 100000;
	int minIdx = -1;
	Point3f t;

	QList<Vtx> visib;

	for(int i=0; i<list.count(); i++)
		if(isVertexVisible(list.at(i).V))
			visib.push_back(list.at(i));

	QPoint mPos = QPoint(mousePos.x(), mouseRealY);
	for(int i=0; i<visib.count(); i++)
	{
		Point3f p = visib.at(i).V;
		double tx,ty,tz;
		gluProject(p.X(),p.Y(),p.Z(), mvmatrix,projmatrix,viewport, &tx,&ty,&tz);

		QPoint qp = QPoint(tx, ty);

		// faster distance
		//double dx = fabs((double)(qp.x() - mPos.x()));
		//double dy = fabs((double)(qp.y() - mPos.y()));
		//double dist = (dy > dx) ? 0.41*dx+0.941246*dy : 0.41*dy+0.941246*dx;

		double dist = sqrt((double)(math::Sqr(qp.x() - mPos.x()) + math::Sqr(qp.y() - mPos.y())));
			
		if(dist<minDist)
		{
			minDist = dist;
			minIdx = i;
			found = true;						
		}
	}

	if(found)
	{
		for(int j=0; j<list.count(); j++)
			if(list.at(j).vName==visib.at(minIdx).vName)
			{
				out = list.at(j);
				return true;
			}
	}
	return false;
}
Point3f ConstrainedFire::pointMid(int p1, int p2)
{
	Point3f point;
	Point3f point1,point2;
	point1.X() = m_Vertices[p1].position.X();
	point1.Y() = m_Vertices[p1].position.Y();
	point1.Z() = m_Vertices[p1].position.Z();
	point2.X() = m_Vertices[p2].position.X();
	point2.Y() = m_Vertices[p2].position.Y();
	point2.Z() = m_Vertices[p2].position.Z();

	point.X() = (point1.X() + point2.X())*0.5;
	point.Y() = (point1.Y() + point2.Y())*0.5;
	point.Z() = (point1.Z() + point2.Z())*0.5;
	
	return point;
}
Point3f ConstrainedFire::modelCenter(std::vector<int> & source)
{
	Point3f p;
	float	centerX,centerY,centerZ;	//模型的中点坐标值
	float	wid,hei,dep;			//原始模型的长度、宽度、深度
    int  i;					//循环控制变量
	GLfloat maxx, minx, maxy, miny, maxz, minz;

    /* get the max/mins */
	maxx = minx = m_Vertices[source[0]].position.X(); // not begin at 1+0,1+2,1+3
	maxy = miny = m_Vertices[source[0]].position.Y();
	maxz = minz = m_Vertices[source[0]].position.Z();
    for (i = 1; i < (int)source.size();i++)
	{
        if (maxx < m_Vertices[source[i]].position.X())
            maxx = m_Vertices[source[i]].position.X();
        if (minx > m_Vertices[source[i]].position.X())
            minx = m_Vertices[source[i]].position.X();

        if (maxy < m_Vertices[source[i]].position.Y())
            maxy = m_Vertices[source[i]].position.Y();
        if (miny > m_Vertices[source[i]].position.Y())
            miny = m_Vertices[source[i]].position.Y();
        
        if (maxz < m_Vertices[source[i]].position.Z())
            maxz = m_Vertices[source[i]].position.Z();
        if (minz > m_Vertices[source[i]].position.Z())
            minz = m_Vertices[source[i]].position.Z();
    }
	wid = maxx-minx;   
	hei = maxy-miny;	
	dep = maxz-minz;

	/* calculate center of the model */
	centerX = (maxx + minx) *0.5;
	centerY = (maxy + miny) *0.5;
	centerZ = (maxz + minz) *0.5;

	p.X()=centerX;
	p.Y()=centerY;
	p.Z()=centerZ;

	return p;
}
Exemple #10
0
void AmbientOcclusionPlugin::setCamera(Point3f camDir, Box3f &meshBBox)
{
	cameraDir = camDir;
	GLfloat d = (meshBBox.Diag()/2.0) * 1.1,
	        k = 0.1f;
	Point3f eye = meshBBox.Center() + camDir * (d+k);

	glViewport(0.0, 0.0, depthTexSize, depthTexSize);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-d, d, -d, d, k, k+(2.0*d) );

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(eye.X(), eye.Y(), eye.Z(),
			  meshBBox.Center().X(), meshBBox.Center().Y(), meshBBox.Center().Z(),
			  0.0, 1.0, 0.0);
}
Exemple #11
0
void SdfGpuPlugin::setCamera(Point3f camDir, Box3f &meshBBox)
{
    GLfloat d = (meshBBox.Diag()/2.0),
            k = 0.1f;
    Point3f eye = meshBBox.Center() + camDir * (d+k);

    mScale = 2*k+(2.0*d);

    glViewport(0.0, 0.0, mPeelingTextureSize, mPeelingTextureSize);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-d, d, -d, d, /*k*/0, mScale );

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(eye.X(), eye.Y(), eye.Z(),
                      meshBBox.Center().X(), meshBBox.Center().Y(), meshBBox.Center().Z(),
                      0.0, 1.0, 0.0);
}
Exemple #12
0
bool ObjReader::LoadObj(char *szFileName)
{
	FILE *file = fopen(szFileName, "rb");

	ObjObject * obj = NULL;//模型

	char materialFile[MAX_PATH];
	char materialStr[MAX_PATH];
	char tempStr[MAX_PATH];
	char      buf[MAX_PATH];//存储读入信息
	
	Point3f position;//顶点信息
    Point3f texCoord;
    Point3f normal; 
    
    int posIndex;//三角形信息
	int texIndex;
	int norIndex;
	
	while(fscanf(file, "%s", buf) != EOF) 
	{
	  //读取数据
	  switch(buf[0]) 
	  {
	   case 'm'://材质库
	    for(int i=0;i<MAX_PATH;i++)materialFile[i] = 0;
		for(int i=0;i<MAX_PATH;i++)tempStr[i] = 0;
        fscanf(file,"%s",tempStr);
		for(int i=0;i<MAX_PATH;i++)
		{
         if(szFileName[i] =='.')
		 {
		  while(szFileName[i]!='\\'&&i>=0)i--;
          for(int j=0;j<=i;j++)
          materialFile[j] = szFileName[j];//路径
          for(int j=i+1;j<MAX_PATH;j++)
          materialFile[j] = tempStr[j-i-1];//文件名
		  break;
		 }

		}
		
		break;

	  case 'u'://材质信息
		for(int i=0;i<MAX_PATH;i++)materialStr[i] = 0;
		fscanf(file, "%s", materialStr);

		LoadMaterial(materialFile,materialStr,obj);//读取材质信息
		break;

	   case 'g'://物体
	   if(obj == NULL) 
	   {
		obj = new ObjObject;//构造新模型  
	    m_Object.push_back(obj);//存入物体
	   }
	   if(obj!=NULL && (int)obj->posIndices.size()>0)//构造新模型  
	   { 
		 obj = new ObjObject;//构造新模型 
		 m_Object.push_back(obj);
	   }
	   break;

	   case 'v':  //如果读取到 v,vt,vn 数据
		   
		 switch(buf[1]) 
	     {
		   case '\0':			//顶点坐标
			  fscanf(file, "%f %f %f", &position.X(),&position.Y(), &position.Z());  
			  Positions.push_back(position);//存储顶点信息
			  break;

		   case 't'://纹理坐标
              fscanf(file, "%f %f %f", &texCoord.X(),&texCoord.Y(), &texCoord.Z());  
			  TexCoords.push_back(texCoord);//存储纹理信息
			   break;
		   case 'n'://法线
              fscanf(file, "%f %f %f", &normal.X(),&normal.Y(), &normal.Z());  
			  Normals.push_back(normal);//存储法线信息
			  break;
		    
		  }
		 break;
		
		case 'f':	//如果读取到面数据			
		
		  fscanf(file, "%s", buf);
          //obj文件索引从1开始计数
		  if(sscanf(buf, "%d//%d", &posIndex, &norIndex)==2) //顶点,法线
		  {	
            obj->posIndices.push_back(posIndex-1);
			obj->norIndices.push_back(norIndex-1);

			fscanf(file, "%d//%d", &posIndex, &norIndex);
			obj->posIndices.push_back(posIndex-1);
			obj->norIndices.push_back(norIndex-1);

			fscanf(file, "%d//%d", &posIndex, &norIndex);
			obj->posIndices.push_back(posIndex-1);
			obj->norIndices.push_back(norIndex-1);
		   }
		  else if (sscanf(buf, "%d/%d/%d", &posIndex, &texIndex, &norIndex) == 3) //顶点 纹理 法线 
		  {
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
			obj->norIndices.push_back(norIndex-1);

			fscanf(file, "%d/%d/%d",  &posIndex, &texIndex, &norIndex);
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
			obj->norIndices.push_back(norIndex-1);

			fscanf(file, "%d/%d/%d",  &posIndex, &texIndex, &norIndex);	
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
			obj->norIndices.push_back(norIndex-1);
		  }
		  else if (sscanf(buf, "%d/%d", &posIndex, &texIndex) == 2) //顶点 纹理
		  {	
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);

			fscanf(file, "%d/%d",&posIndex, &texIndex);
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
				
			fscanf(file, "%d/%d", &posIndex, &texIndex);	
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
		   } 
		   else  if(sscanf(buf, "%d", &posIndex) == 1) //顶点 
		   {
			obj->posIndices.push_back(posIndex-1);

			fscanf(file, "%d", &posIndex);
			obj->posIndices.push_back(posIndex-1);

			fscanf(file, "%d", &posIndex);
			obj->posIndices.push_back(posIndex-1); 
		   }
		  break;
	
		default:
		  fgets(buf, sizeof(buf), file);//读入一行
		  break;
		}   		
}
 fclose(file);//关闭文件
		
 return true;
}
Exemple #13
0
float ConstrainedFire::pointDist(Point3f point1, Point3f point2)
{
  return sqrt((point1.X()-point2.X())*(point1.X()-point2.X())+(point1.Y()-point2.Y())*(point1.Y()-point2.Y())+(point1.Z()-point2.Z())*(point1.Z()-point2.Z()));
}