PDA

View Full Version : Displaying 3D surface.

aus79er
05-18-2002, 08:55 AM
Hi,
I am code to determine the surface texture.
Through this code i am getting x,y,z values.
Now using these values I have to display a 3D surface.
I have written a program for displaying it using triangles and have also written a code for calculating the normals.Basically I am having the Z value in 2D array while x and y in 1D array..

glBegin ( GL_TRIANGLES ) ;

for(i=1;i<=100;i++)
{
for(j=1;j<=100;j++)
{
n1=check.CCalNormal(i,j,1);
glNormal3f(n1.x,n1.z,n1.y);
glVertex3f (xw[i],zw[i][j],yw[j]) ;
glVertex3f (xw[i+1],zw[i+1][j],yw[j]) ;
glVertex3f (xw[i+1],zw[i+1][j+1],yw[j+1]) ;

n2=check.CCalNormal(i,j,2);

glNormal3f(n2.x,n2.z,n2.y);;
glVertex3f (xw[i],zw[i][j],yw[j]) ;
glVertex3f (xw[i],zw[i][j+1],yw[j+1]) ;
glVertex3f (xw[i+1],zw[i+1][j+1],yw[j+1]) ;

}
}
glEnd();

I would like to know whether this is good way to draw that surface...or in other words can i enhance this code ..

-------------------------------------
One more question my Z values variation is very less for eg its between 100 and 99.5.
But X & Y values varies from 1 to 100...( Can be treated as length of the cube).
Now i want to display the top surface...i.e the surface having values like 100 ,99.5 ,99.75..etc in much better way i.e I am more intrested in the displaying the differnce in these values .How can I do that...

Thanks in advance
aus

aus79er
05-20-2002, 02:39 PM
Hi,
Can any body help me with the method to display 3D surface using triangle strips.

I am posting this message because nobody replied to the last message....

thanks
aus

Michael Steinberg
05-20-2002, 05:34 PM
One reason why nobodoy might have replied is because you missed to formulate your problem in clear sentences with good structure so that everyone understands it on first sight.

Jambolo
05-20-2002, 07:07 PM
Here is my code for rendering a heightfield:

static int const SKIP = 1;

static void DrawTerrain()
{
int const sx = s_pTerrain->GetSizeX();
int const sy = s_pTerrain->GetSizeY();
HeightField::Vertex const * pData = s_pTerrain->GetData();
float const d = s_pTerrain->GetXYScale();
float const x0 = -( sx - 1 ) * .5f * d;
float const y0 = -( sy - 1 ) * .5f * d;

s_pTerrainMaterial->Apply();

glEnableClientState( GL_NORMAL_ARRAY );
glNormalPointer( GL_FLOAT, sizeof( *s_paTerrainNormals ), s_paTerrainNormals );

for ( int i = 0; i < sy-SKIP; i += SKIP )
{
glBegin( GL_TRIANGLE_STRIP );

for ( int j = 0; j < sx; j += SKIP )
{
float const x = x0 + j * d;
float const tx = float( j );//float( j ) / float( sx - 1 );

HeightField::Vertex const * const pa = &amp;pData[ i * sx + j ];
HeightField::Vertex const * const pb = pa + SKIP * sx;

float const yb = y0 + ( i + SKIP ) * d;
float const tyb = float( i + SKIP );//float( i + SKIP ) / float( sy - 1 );
float const zb = pb->m_Z;

glTexCoord2f( tx, tyb );
glArrayElement( ( i + SKIP ) * sx + j );
// glNormal3fv( pb->m_Normal.m_V );
glVertex3f( x, yb, zb );

float const ya = y0 + i * d;
float const tya = float( i );//float( i ) / float( sy - 1 );
float const za = pa->m_Z;

glTexCoord2f( tx, tya );
glArrayElement( i * sx + j );
// glNormal3fv( pa->m_Normal.m_V );
glVertex3f( x, ya, za );
}

glEnd();
}

glDisableClientState( GL_NORMAL_ARRAY );

}

Michael Steinberg
05-20-2002, 09:01 PM
Oy!