Public Group

# I need help!

This topic is 5296 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

# Better explanation for normalizing a vector

Vectors give direction ,this means that v1(1,2,3) is the same thing as v2(k*1,k*2,k*3) where k is any real number

Remember how easy it is to work with cartezian axes
You would probably choose v1(1,0,0)than v2(1.45f,0,0);
In this case it doesn't metter how much you "stretch" a point

##### Share on other sites
ok I used the parametric equations for a sphere, but nothing is being drawn. Only the back buffer is being shown. here's my code:
// Fill the vertex buffer. We are algorithmically generating a shpere    // here, including the normals, which are used for lighting.    CUSTOMVERTEX* pVertices;    if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )        return E_FAIL;			for( DWORD  j=0; j<100; j++)		{			FLOAT theta = (2*D3DX_PI*j)/(100-1);			FLOAT phi = (D3DX_PI*j)/(100-1);						pVertices[2*j+0].position = D3DXVECTOR3( 2*(FLOAT(sinf(phi)*cos(theta))), 2*(FLOAT(sin(phi)*sin(theta))), 2*(FLOAT(cosf(phi))) );			pVertices[2*j+1].position = D3DXVECTOR3( 2*(FLOAT(sinf(phi)*cos(theta))), 2*(FLOAT(sin(phi)*sin(theta))), 2*(FLOAT(cosf(phi))) );																	}					    g_pVB->Unlock();

##### Share on other sites

void CSphere::Draw()
{

glPushMatrix();

double du=2*PI/(double)resolution;
double dv=PI/(double)resolution;

double u=0.0f,v=0.0f;
CPoint3D p1,p2,p3,p4;

glColor3f(1.0f,1.0f,1.0f);

glBindTexture(GL_TEXTURE_2D,texture.texture[1]);

for(int i=0;i<resolution;i++)
{
u=i*du;

for(int j=0;j<resolution;j++)
{
v=j*dv;
p1=GetPoint3D(u,v);
p2=GetPoint3D(u,v+dv);
p3=GetPoint3D(u+du,v+dv);
p4=GetPoint3D(u+du,v);

glTexCoord2d(u/10*PI,v/PI);
glVertex3d(p1.x,p1.y,p1.z);
glTexCoord2d(u/10*PI,(v+dv)/PI);
glVertex3d(p2.x,p2.y,p2.z);
glTexCoord2d((u+du)/10*PI,(v+dv)/PI);
glVertex3d(p3.x,p3.y,p3.z);
glTexCoord2d((u+du)/10*PI, v/PI);
glVertex3d(p4.x,p4.y,p4.z);
}

}

glEnd();

glPopMatrix();

}
//**********************************************
CPoint3D CSphere::GetPoint3D(double u, double v)
{

return CPoint3D(r*cos(u)*sin(v), r*sin(u)*sin(v), r*cos(v));

}

##### Share on other sites
Daos can you please explain why you increment v by dv for P2 and P3 and also increment u by du for P3 and P4?

thanx

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 25
• 13
• 10
• 9
• ### Forum Statistics

• Total Topics
634484
• Total Posts
3017741
×