Re: R: [Plib-users] Drawing a simple triangle
Brought to you by:
sjbaker
From: Peter P. <pet...@st...> - 2004-03-08 16:14:38
|
"Paolo Leoncini" <p.l...@ci...> writes: Wee!!! Thanks, it works!! > Peter, >=20 > Ok, one step forward - let's set a state for the geometry (leaf) node. > For a leaf (ssgVTable, ssgVtxTable, or ssgVtxArray) a state tells OpenGL > about object material (properties, texture) as well as modes to > enable/disable. > The following code generates and returns a state with safe defaults: >=20 > ssgSimpleState *gen_state( char *tex_name ) > { > ssgSimpleState *st =3D new ssgSimpleState () ; >=20 > // st -> setName( mat -> name ); >=20 > st -> setMaterial ( GL_AMBIENT, 1.0f, 1.0f, 1.0f, 1.0f ); > st -> setMaterial ( GL_DIFFUSE, 1.0f, 1.0f, 1.0f, 1.0f ); > st -> setMaterial ( GL_SPECULAR, 0, 0, 0, 1 ); > st -> setMaterial ( GL_EMISSION, 0, 0, 0, 1 ); >=20 > st -> setShadeModel( GL_SMOOTH ); > st -> disable( GL_BLEND ); > st -> setOpaque(); >=20 > if ( tex_name !=3D NULL ) { > ssgTexture *tex =3D new ssgTexture(tex_name, 0, 0, 1); > if ( tex ) > st -> setTexture( tex ); > else > fprintf( stderr, "can't load texture from image > file %s\n", tex_name ); > st -> enable( GL_TEXTURE_2D ); > } else > st -> disable( GL_TEXTURE_2D ); >=20 > return st ; > } >=20 > Such a state is ready to be set for the leaf n you generated: >=20 > ssgSimpleState *s =3D gen_state( NULL /* tex_name */ ); // you > have set null tex coords, so it's better to not map any texture > n -> setState( s ); > s -> enable( GL_LIGHTING ); // or could disable it > if you supply good normals > s -> disable( GL_COLOR_MATERIAL ); // or could enable it if > you supply per-vertex colors >=20 > Since the default in SSG is to enable back face culling, at our stage is > safer to disable it for our unknown-winding triangle: >=20 > n -> setCullFace( FALSE ); >=20 > Note that face culling is set through a leaf method, not a state one. >=20 > Looking forward to hear about a "triangle born" - >=20 > Paolo >=20 >=20 > > -----Messaggio originale----- > > Da: pli...@li...=20 > > [mailto:pli...@li...] Per conto di=20 > > Peter Poulsen > > Inviato: luned=EC 8 marzo 2004 15.56 > > A: pli...@li... > > Oggetto: Re: [Plib-users] Drawing a simple triangle > >=20 > >=20 > > "Paolo Leoncini" <p.l...@ci...> writes: > >=20 > > > Peter, > > >=20 > > > on my opinion you just missed to set up a camera for=20 > > looking at scene=20 > > > objects. It can be done this way: > > >=20 > > > #include <plib/sg.h> > > >=20 > > > sgCoord camera; > > > SGfloat pos_x, pos_y, pos_z, yaw, pitch, roll; > > >=20 > > > // set pos_x, pos_y, pos_z, yaw, pitch and roll to some=20 > > suitable=20 > > > values > > > // then, before ssgCullAndDraw, actually set the SSG camera > > > sgSetCoord( camera, pos_x, pos_y, pos_z, yaw, pitch, roll ); > > > ssgSetCamera( &camera ); > > >=20 > > > SG is the prefix for the Plib math/geometry library stuffs. > > >=20 > > > Finding a plausible position for the init view (given a scene, in=20 > > > general, you could not know its extent along the three axes) it's a=20 > > > question of taste - I could suggest this: > > >=20 > > > sgSphere *sp =3D scene->getBSphere(); > > > SGfloat radius =3D sp->getRadius(); > > > SGfloat EyeDist =3D float( radius * 1.f / tan( float( fov_x/2 *=20 > > > SG_DEGREES_TO_RADIANS ) ) ); > > > SGfloat Ex, Ey, Ez; > > >=20 > > > pos_x =3D sp->getCenter()[0]; > > > pos_y =3D sp->getCenter()[1] + EyeDist; > > > pos_z =3D sp->getCenter()[2]; > > >=20 > > > Then, moving in 3D above or around the scene is a matter of=20 > > changing=20 > > > those six parameters to the sgSetCoord/ssgSetCamera (yaw is compass=20 > > > heading, pitch rotates around the screen x-axis, roll=20 > > around the axis=20 > > > norma to the screen). > > >=20 --=20 Yours=20 Peter Poulsen |