Esempio n. 1
0
/**
 * Get the point right between two other points (in spherical sense, so the result has the middle abs of gps1 and gps2)
 */
template<typename T> Spherical<T> calculateCenter(const Spherical<T>& gps1,
        const Spherical<T>& gps2) {
	Cartesian<T> cartesian1 = sphericalToCartesian(gps1) / 2;
	Cartesian<T> cartesian2 = sphericalToCartesian(gps2) / 2;
	Spherical<T> newPoint = cartesianToSpherical(cartesian1 + cartesian2);
	return scaleTo(newPoint, (gps1.z + gps2.z) / 2);
}
Esempio n. 2
0
/* Main Function */
int main(int argc, char *argv[]) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
  center = 0;
  tcenter = 0;
  glutInitWindowSize(W, H);
  glutInitWindowPosition(10,10);
  glutCreateWindow("Shadow");
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  glutMouseFunc(mouse);
  glutMotionFunc(mouseMotion);
  glutIdleFunc(idle);
  
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(40, (GLfloat)W/H, 0.1, 20);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  sphericalToCartesian(eyeRho, eyeTheta, eyePhi,
                        &eyex, &eyey, &eyez);
  gluLookAt(eyex, eyey, eyez, 0,0,0, 0,0,1);
  init();
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  glPointSize(3.0);
  glLineWidth(2.0);

  glutMainLoop();
  return 0;
}
Esempio n. 3
0
void setView(){
	GLdouble eyex, eyey, eyez;
	sphericalToCartesian(eyeRho, eyeTheta, eyePhi,
												&eyex, &eyey, &eyez);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(eyex, eyey, eyez, 0, 0, 0, 0, 0, 1);
}
Esempio n. 4
0
  void setCamera() {
    sphericalToCartesian(radius, theta, phi,
                         &eyeX, &eyeY, &eyeZ);
    eyeX += centerX; eyeY += centerY; eyeZ += centerZ;

    matrixIdentity(ModelView);
    matrixLookat(ModelView, eyeX,    eyeY,    eyeZ,
                 centerX, centerY, centerZ,
                 upX,     upY,     upZ);
  }
Esempio n. 5
0
void mouse(int button, int state, int x, int y) {
  mousex = x;
  mousey = y;
  if(button == 3 && eyeRho > .2){
    eyeRho-=0.1;
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    sphericalToCartesian(eyeRho, eyeTheta, eyePhi,
                          &eyex, &eyey, &eyez);
    gluLookAt(eyex, eyey, eyez, 0,0,0, 0,0,1);
    glutPostRedisplay();
  }else if(button == 4 && eyeRho < 3){
    eyeRho+=0.1;
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    sphericalToCartesian(eyeRho, eyeTheta, eyePhi,
                          &eyex, &eyey, &eyez);
    gluLookAt(eyex, eyey, eyez, 0,0,0, 0,0,1);
    glutPostRedisplay();
  }
}
Esempio n. 6
0
void mouseMotion(int x, int y) {
  float bound = 0.1;
  int dx = x - mousex, dy = y - mousey;
  eyeTheta -= dx*RADIANS_PER_PIXEL;
  eyePhi -= dy*RADIANS_PER_PIXEL;
  if(eyePhi < bound) eyePhi = bound;
  else if(eyePhi > M_PI/2-bound) eyePhi = M_PI/2-bound;
  mousex = x, mousey = y;
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  sphericalToCartesian(eyeRho, eyeTheta, eyePhi,
                        &eyex, &eyey, &eyez);
  gluLookAt(eyex, eyey, eyez, 0,0,0, 0,0,1);
  glutPostRedisplay();
}
Esempio n. 7
0
void CircularTrajectory::initWithElevationHeading(float elevation, float startHeading, float stopHeading) {
  _elevation = elevation;
  _startHeading = startHeading;
  _stopHeading = stopHeading;
  
  _position = sphericalToCartesian(_r, elevation, _startHeading);
  _phi = _startHeading * PI / 180.0;
  _height = _position.y;
  _circleRadius = sqrt(_position.x * _position.x + _position.z * _position.z);
  _t = 0;
  
  float s = _speed / ofGetFrameRate();
  _lastPosition.x = cos(_phi - s);
  _lastPosition.y = _height;
  _lastPosition.z = sin(_phi - s);
}
Esempio n. 8
0
void mouseMotion(int x, int y){
		int dx = x - mousex, dy = y - mousey;
		double eyex, eyey, eyez;
		eyeTheta -= dx * RADIANS_PER_PIXEL;
		eyePhi -= dy * RADIANS_PER_PIXEL;
		mousex = x, mousey = y;
		if(eyePhi >= M_PI)
			eyePhi = M_PI - epsilon;
		else if(eyePhi <= 0.0)
			eyePhi = epsilon;
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		sphericalToCartesian(eyeRho, eyeTheta, eyePhi,
													&eyex, &eyey, &eyez);
		gluLookAt(eyex, eyey, eyez, 0,0,0, 0,0,1);
		glutPostRedisplay();
}
Esempio n. 9
0
void mySemiSphere::populateArrays(int stackNr){

    SphericalPoint pt;
    CartesianPoint cart_pt;
    pt.r=1.0;//all points have 0.5 radius
    pt.rho=0;
    pt.phy=90*(1-stackNr/(double)stacks);
    for (int i=0; i<slices; i++) {
        pt.rho-=360/(double)slices;
        cart_pt=sphericalToCartesian(&pt);
        xx[stackNr][i]=cart_pt.x;
        yy[stackNr][i]=cart_pt.y;
        zz[stackNr][i]=cart_pt.z;
        
        
    }
    
    
}
Esempio n. 10
0
void mouseMotion(int x, int y) {

    int dx = x - mouseX;
    int dy = y - mouseY;
    theta -= dx * RADIANS_PER_PIXEL;
    phi += dy * RADIANS_PER_PIXEL;
    if (phi >= M_PI)
        phi = M_PI - EPSILON;
    else if (phi <= 0.0)
        phi = EPSILON;

    sphericalToCartesian(radius,theta,phi,&eyeX,&eyeY,&eyeZ);
    eyeX += centerX;
    eyeY += centerY;
    eyeZ += centerZ;
    setCamera();
    mouseX = x;
    mouseY = y;
    glutPostRedisplay();
}
Esempio n. 11
0
/**Desenha a cena (esqueleto openGL)*/
void renderScene(void)
{
	// Limpar buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Conversão de coordenadas esféricas para coordenadas cartesianas da posição da câmera
	sphericalToCartesian();

	// Atualizar câmara
	glLoadIdentity();
	gluLookAt(px, py, pz,
		0.0, 0.0, 0.0,
		0.0f, 1.0f, 0.0f);

	glEnable(GL_CULL_FACE);
	glPolygonMode(GL_FRONT_AND_BACK, option);

	// Loop para desenhar formas
	for (std::vector<Forma*>::iterator it = Formas.begin(); it != Formas.end(); ++it){
		(*it)->draw();
	}

	glutSwapBuffers();
}
Esempio n. 12
0
MStatus sphericalBlendShape::deform(MDataBlock& data, MItGeometry& itGeo, const MMatrix& mat, unsigned int geomIndex) 
{
	MStatus status = MS::kSuccess;

	float env = data.inputValue(envelope).asFloat();
	if (env <= 0.0f) {
		return MS::kSuccess;
	}

	MMatrix spaceMatrix = data.inputValue(aSpaceMatrix).asMatrix();
	short poleAxis		= data.inputValue(aPoleAxis).asShort();
	short seamAxis		= data.inputValue(aSeamAxis).asShort();
	short method		= data.inputValue(aMethod).asShort();
	MMatrix warpMatrix	= data.inputValue(aWarpMatrix).asMatrix();

	MTransformationMatrix warpTransMatrix(warpMatrix);
	MPoint warpPoint = warpTransMatrix.getTranslation(MSpace::kWorld);
	
	status = checkPoleAndSeam(poleAxis, seamAxis);
	CHECK_MSTATUS_AND_RETURN_IT(status);


	MMatrix invGeoMatrix   = mat.inverse();
	MMatrix invSpaceMatrix = spaceMatrix.inverse();

	MPointArray defPoints;
	MPoint* defPoint;
	MPoint inPoint, returnPoint;

	itGeo.allPositions(defPoints);
	unsigned int count = defPoints.length();

	unsigned int i;
	switch(method) {
		// XYZ to Spherical
	case 0:
		for (i=0; i<count; i++) {
			defPoint = &defPoints[i];
			inPoint = *defPoint;

			// bring the point into world space
			inPoint *= invGeoMatrix;
			// bring into local space of the input matrix
			inPoint *= invSpaceMatrix;

			cartesianToSpherical(inPoint, poleAxis, seamAxis, warpPoint, returnPoint);

			// bring the point back into world space
			returnPoint *= spaceMatrix;
			// bring the point back into local space
			returnPoint *= mat;
				
			lerp(*defPoint, returnPoint, env, *defPoint);
		}
		break;

	case 1:
		for (i=0; i<count; i++) {
			defPoint = &defPoints[i];
			inPoint = *defPoint;

			// bring the point into world space
			inPoint *= invGeoMatrix;
			// bring into local space of the input matrix
			inPoint *= invSpaceMatrix;

			sphericalToCartesian(inPoint, poleAxis, seamAxis, warpPoint, returnPoint);

			// bring the point back into world space
			returnPoint *= spaceMatrix;
			// bring the point back into local space
			returnPoint *= mat;
				
			lerp(*defPoint, returnPoint, env, *defPoint);
		}
		break;
	}

	itGeo.setAllPositions(defPoints);

	return MS::kSuccess;
}
  Matrix<qreal, 3, 1> sphericalToCartesian(const Matrix<qreal, 3, 1> &rtp)
  {
    Matrix<qreal, 3, 1> x0y0z0(0., 0., 0.);

    return  sphericalToCartesian(rtp, x0y0z0);
  }
Esempio n. 14
0
/**
 * Get the (cartesian) distance of two given points (spherical)
 * @param point1 the first point
 * @param point1 the second point
 * @return the distance of the two points
 */
template<typename T> float distance(const Spherical<T>& point1, const Spherical<T>& point2) {
	return (sphericalToCartesian(point1) - sphericalToCartesian(point2)).length();
}
Esempio n. 15
0
glm::vec3 Spherical::toCartesian() {
    return sphericalToCartesian(radius, polar, elevation);
}
Esempio n. 16
0
void PhysicsObject::setPositionSpherical(float r, float elevation, float heading) {
  staticRotation = 360 - heading;
  setPosition(sphericalToCartesian(r, elevation, heading));
}
void sphericalBlendShapeVisualizerDrawOverride::addUIDrawables(
								const MDagPath& objPath,
								MHWRender::MUIDrawManager& drawManager,
								const MHWRender::MFrameContext& frameContext,
								const MUserData* data)
{
	sphericalBlendShapeVisualizerData* pLocatorData = (sphericalBlendShapeVisualizerData*)data;
	if (!pLocatorData)
	{
		return;
	}

	MMatrix spaceMatrix    = pLocatorData->fSpaceMatrix;
	MMatrix spaceInvMatrix = spaceMatrix.inverse();

	short poleAxis      = pLocatorData->fPoleAxis;
	short seamAxis      = pLocatorData->fSeamAxis;

	drawManager.beginDrawable();

	MColor lineColor, vertexColor, poleAxisColor, seamAxisColor;
	lineColor		= MColor(0.7294f, .239216f, 0.2980f, 1.0f);
	vertexColor		= MColor(0.5843f, 0.78824f, .17255f, 1.0f);
	poleAxisColor   = MColor(1.0f, 0.0f, 0.f, 1.0f);
	seamAxisColor   = MColor(0.0f, 1.0f, 0.0f, 1.0f);

	MMatrix identity;
	identity.setToIdentity();

	double radius   = 1.0;
	int numRings    = 20;
	int numSections = 20;

	MPoint sphericalPoint, xyzPoint;
	MPoint startPoint, endPoint, firstPoint;
	MPointArray points;

	drawManager.setDepthPriority(5);

	drawManager.setColor(lineColor);

	bboxPoints.clear();
	bboxPoints.setLength(numRings*numSections);

	for(int ring=0; ring<=numRings; ring++) {
		double azimuth = (double)ring / numRings * M_PI * 2;

		for(int section=0; section<=numSections; section++) {
			double zenith = (double)section / (numSections) * M_PI;

			sphericalPoint.x = radius;
			sphericalPoint.y = zenith;
			sphericalPoint.z = azimuth;
			
			if (section==0) {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, startPoint);
				startPoint = startPoint * spaceMatrix;
				firstPoint = startPoint;
				bboxPoints.append(firstPoint);
				continue;
			} else {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, endPoint);
				endPoint = endPoint * spaceMatrix;
				drawManager.line(startPoint, endPoint);
				bboxPoints.append(endPoint);
				startPoint = endPoint;
			}
		}
	}

	for(int ring=0; ring<=numRings; ring++) {
		double azimuth = (double)ring / numRings * M_PI * 2;

		for(int section=0; section<=numSections; section++) {
			double zenith = (double)section / (numSections) * M_PI;

			sphericalPoint.x = radius;
			sphericalPoint.y = azimuth;
			sphericalPoint.z = zenith;
			
			if (section==0) {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, startPoint);
				startPoint = startPoint * spaceMatrix;
				firstPoint = startPoint;
				continue;
			} else {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, endPoint);
				endPoint = endPoint * spaceMatrix;
				drawManager.line(startPoint, endPoint);
				startPoint = endPoint;
			}
		}
	}

	drawManager.setLineWidth(3.0);
	drawManager.setLineStyle(MHWRender::MUIDrawManager::kDashed);
	
	startPoint = MPoint(0, 0, 0) * spaceMatrix;


	MVector endVector(0, 0, 0);
	setAxis(endVector, poleAxis, radius);
	endPoint = MPoint(endVector) * spaceMatrix;

	drawManager.setColor(poleAxisColor);
	drawManager.line(startPoint, endPoint);

	endVector = MVector(0, 0, 0);
	setAxis(endVector, seamAxis, radius);
	endPoint = MPoint(endVector) * spaceMatrix;

	drawManager.setColor(seamAxisColor);
	drawManager.line(startPoint, endPoint);
	drawManager.endDrawable();
}
Visualization::Abstract::DataSet* CSConvectionFile::load(const std::vector<std::string>& args) const
	{
	/* Open the data file: */
	Misc::File dataFile(args[0].c_str(),"rt");
	
	/* Read data file's header: */
	char line[256];
	dataFile.gets(line,sizeof(line)); // Skip title field
	if(strncmp(line,"TITLE=",6)!=0)
		Misc::throwStdErr("CSConvectionFile::load: Wrong format in data file header");
	dataFile.gets(line,sizeof(line)); // Skip variable field
	if(strncmp(line,"VARIABLES=",10)!=0)
		Misc::throwStdErr("CSConvectionFile::load: Wrong format in data file header");
	
	/* Determine which zone to read: */
	int zoneIndex=0;
	if(args.size()>1)
		zoneIndex=atoi(args[1].c_str());
	
	/* Read the first zone from the data file: */
	dataFile.gets(line,sizeof(line)); // Read size field
	if(strncmp(line,"ZONE ",5)!=0)
		Misc::throwStdErr("CSConvectionFile::load: Wrong format in data file header");
	DS::Index numZoneVertices=parseZoneSize(line);
	
	/* Skip zones until the correct one: */
	for(int i=0;i<zoneIndex;++i)
		{
		/* Skip all nodes of this zone: */
		size_t numNodes=size_t(numZoneVertices.calcIncrement(-1));
		for(size_t j=0;j<numNodes;++j)
			dataFile.gets(line,sizeof(line));
		
		/* Read the next zone header: */
		dataFile.gets(line,sizeof(line)); // Read size field
		if(strncmp(line,"ZONE ",5)!=0)
			Misc::throwStdErr("CSConvectionFile::load: Wrong format in data file header");
		numZoneVertices=parseZoneSize(line);
		}
	
	/* Create the result data set: */
	DataSet* result=new DataSet;
	result->getDs().setData(numZoneVertices);
	
	/* Read all vertex positions and values: */
	DS::Array& vertices=result->getDs().getVertices();
	for(DS::Array::iterator vIt=vertices.begin();vIt!=vertices.end();++vIt)
		{
		dataFile.gets(line,sizeof(line));
		float pos[3];
		float temp,visc;
		float vel[3];
		if(sscanf(line,"%f %f %f %f %f %f %f %f",&pos[0],&pos[1],&pos[2],&temp,&visc,&vel[0],&vel[1],&vel[2])!=8)
			Misc::throwStdErr("CSConvectionFile::load: Error while reading grid data");
		
		sphericalToCartesian(vIt->pos,pos);
		vIt->value.temperature=temp;
		vIt->value.viscosity=Math::log(visc);
		sphericalToCartesian(vIt->value.velocity,vel);
		}
	
	/* Finalize the grid structure: */
	result->getDs().finalizeGrid();
	
	return result;
	}