Create a Sphere?..not centered in middle of screen?

Hi, I’m wondering how to create a sphere that is not centered in the middle of the screen? how can I move it or draw it somewhere else other than the center?

I tried creating my sphere with this
GLUquadricObj *p;
p = gluNewQuadric();
gluSphere(0.4,20,20);

or…
glutSolidSphere(0.4,20,20);

But both put them in the center of the screen.
Does anyone know where I could find an algorithm for creating a sphere? not using glu or glut?

thanks

gluSpehere() as well as the other functions (gluCylinder(), etc.) always place the objects centered at the origin.

What you should do is create the sphere and then translate it with glTranslatef() to whatever location you need.

Thanks, that works.

I also wondered if anyone knows how to create a sphere not using glu or glut? like is there some algorithm or something.

Thanks

You can try either, auxSoildSphere() or auxWireSphere()…

Hi,
this is directly from my code. It illustrates the idea of calculating a sphere at given center, radius, slices and stacks.

void CSurfSphere::Calculate()
{
ClearTopology();

CControlPoint* pPolS = new CControlPoint( m_center + C3DPoint(0,0,-m_dRadius,0), this );
CControlPoint* pPolN = new CControlPoint( m_center + C3DPoint(0,0, m_dRadius,0), this );
AddControlPoint(*pPolS);
AddControlPoint(*pPolN);
pPolS->GetNormalRef() = C3DVector(0,0,-m_dRadius);
pPolN->GetNormalRef() = C3DVector(0,0, m_dRadius);

double dFiStep = 2*M_PI / (m_nStacks - 1);

double dTitaStep  = M_PI / (m_nSlices - 1);
double dTita = - M_PI + dTitaStep;

CControlPoint** pPrevSlice = new CControlPoint* [m_nStacks];
CControlPoint** pCurrSlice = new CControlPoint* [m_nStacks]; 

int nSlice, nStack;
C3DPoint pt;

for (nSlice = 1; nSlice < m_nSlices - 1; nSlice++, dTita += dTitaStep)
{
	double dSliceRadius  = m_dRadius*sin(dTita);
	pt(2) = m_center(2) + m_dRadius*cos(dTita);

	double dFi = 0;
	for (nStack = 1; nStack < m_nStacks; nStack++, dFi += dFiStep)
	{
		pt(0) = m_center(0) + dSliceRadius*cos(dFi);
		pt(1) = m_center(1) + dSliceRadius*sin(dFi);

		CControlPoint* pCpt = pCurrSlice[nStack] = new CControlPoint(pt, this);
		AddControlPoint(*pCpt);
		pCpt->GetNormalRef().C3DPoint::operator = ( *pCpt - m_center);
		
	}
	pCurrSlice[0] = pCurrSlice[nStack-1];

	if (nSlice == 1)
	{
		for (nStack = 1; nStack < m_nStacks; nStack++)
		{
			AddTriangle(pPolS, pCurrSlice[nStack], pCurrSlice[nStack-1]);
		}
	}
	else if (m_bTrisOnly)
	{
		for (nStack = 1; nStack < m_nStacks; nStack++)
		{
			AddTriangle(pPrevSlice[nStack-1], pPrevSlice[nStack], pCurrSlice[nStack]);
			AddTriangle(pCurrSlice[nStack], pCurrSlice[nStack-1], pPrevSlice[nStack-1]);
		}
	}
	else
	{
		for (nStack = 1; nStack < m_nStacks; nStack++)
		{
			AddQuad(pPrevSlice[nStack-1], pPrevSlice[nStack], pCurrSlice[nStack], pCurrSlice[nStack-1]);
		}
	}
	std::swap (pPrevSlice, pCurrSlice);
}

for (nStack = 1; nStack < m_nStacks; nStack++)
{
	AddTriangle(pPrevSlice[nStack-1], pPrevSlice[nStack], pPolN); 
}

delete pPrevSlice;
delete pCurrSlice;

m_bValid = true;

}

Hope this helps
Martin