R: [Plib-users] Drawing a simple triangle
Brought to you by:
sjbaker
From: Paolo L. <p.l...@ci...> - 2004-03-08 11:48:56
|
Peter, on my opinion you just missed to set up a camera for looking at scene objects. It can be done this way: #include <plib/sg.h> sgCoord camera; SGfloat pos_x, pos_y, pos_z, yaw, pitch, roll; // set pos_x, pos_y, pos_z, yaw, pitch and roll to some suitable values // then, before ssgCullAndDraw, actually set the SSG camera sgSetCoord( camera, pos_x, pos_y, pos_z, yaw, pitch, roll ); ssgSetCamera( &camera ); SG is the prefix for the Plib math/geometry library stuffs. Finding a plausible position for the init view (given a scene, in general, you could not know its extent along the three axes) it's a question of taste - I could suggest this: sgSphere *sp = scene->getBSphere(); SGfloat radius = sp->getRadius(); SGfloat EyeDist = float( radius * 1.f / tan( float( fov_x/2 * SG_DEGREES_TO_RADIANS ) ) ); SGfloat Ex, Ey, Ez; pos_x = sp->getCenter()[0]; pos_y = sp->getCenter()[1] + EyeDist; pos_z = sp->getCenter()[2]; Then, moving in 3D above or around the scene is a matter of changing those six parameters to the sgSetCoord/ssgSetCamera (yaw is compass heading, pitch rotates around the screen x-axis, roll around the axis norma to the screen). Hoping you'll also love Plib for its simplicity not payed with completness - Paolo > -----Messaggio originale----- > Da: pli...@li... > [mailto:pli...@li...] Per conto di > Peter Poulsen > Inviato: domenica 7 marzo 2004 18.18 > A: pli...@li... > Oggetto: Re: [Plib-users] Drawing a simple triangle > > > Steve Baker <sjb...@ai...> writes: > > > Peter Poulsen wrote: > > > I have tried the program below, but it only shows a black screen. > > > Can anybody explain why? The program works if I make > direct gl-calls > > > (just comment out the first line). > > > > SSG uses the 'Z-is-up' convention - so I guess your polygon is > > edge-on. Also, SSG defaults to perspective rendering - so it'll be > > near-plane clipped. > > Thanks. I have now tried to modify the program, but it still > does not work :-) I'm sorry for bothering you with this > trivil matter, but if I cannot get that to work, I probably > cannot get a "real" program to work. > > --- ssg_triangle.cc --- > > #define USE_SSG 1 > > #include <GL/gl.h> > #include <GL/glu.h> > > #include <plib/ssg.h> > #include <SDL/SDL.h> > #include <iostream> > > using namespace std; > > ssgRoot* scene; > #define SCREEN_WIDTH 320 > #define SCREEN_HEIGHT 240 > #define SCREEN_BPP 24 > > void init() > { > int videoFlags; > SDL_Surface* surface; > > if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { > fprintf( stderr, "Video initialization failed: > %s\n", SDL_GetError( ) ); > exit(0); > } > > videoFlags = SDL_OPENGL; > videoFlags |= SDL_GL_DOUBLEBUFFER; > videoFlags |= SDL_HWPALETTE; > videoFlags |= SDL_HWSURFACE; > surface = SDL_SetVideoMode( SCREEN_WIDTH, > SCREEN_HEIGHT, SCREEN_BPP, videoFlags ); > > if ( !surface ) { > fprintf( stderr, "Video mode set failed: > %s\n", SDL_GetError( ) ); > exit(0); > } > > #ifdef USE_SSG > ssgInit(); > > glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ) ; > glEnable ( GL_DEPTH_TEST ) ; > ssgGetCurrentContext()->setFOV (60.0f, 0.0f); // New > ssgGetCurrentContext()->setNearFar(0.1f, 70.0f); // New > > ssgVertexArray* vertices = new ssgVertexArray; > sgVec3 x = { 0.5f, 0.5f , -0.25f}; // Changed > sgVec3 y = { -0.5f, 0.5f , -0.25f }; // Changed > sgVec3 z = { 0.0f, 0.5f , 0.75f }; // Changed > vertices->add(x); > vertices->add(y); > vertices->add(z); > > sgVec4 white = { 1.0f, 1.0f, 1.0f, 0.5f }; > ssgColourArray* colours = new ssgColourArray; > colours->add(white); > colours->add(white); > colours->add(white); > ssgNormalArray* normals = new ssgNormalArray(3); > sgVec3 normal = { 0, -1.0f, 0 }; // Changed > normals->add(normal); > normals->add(normal); > normals->add(normal); > ssgTexCoordArray* texs = new ssgTexCoordArray(3); > sgVec2 tex_vec = {0,0}; > texs->add(tex_vec); > texs->add(tex_vec); > texs->add(tex_vec); > > ssgVtxTable* n = new ssgVtxTable(GL_TRIANGLES, > vertices, normals, texs, colours); > ssgTransform* trans = new ssgTransform; > trans->addKid(n); > > scene = new ssgRoot; > scene->addKid(trans); > #else > glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ) ; > glEnable ( GL_DEPTH_TEST ) ; > #endif > } > > void update() > { > glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ; > > #ifdef USE_SSG > ssgCullAndDraw(scene); > > #else > glLoadIdentity(); > > glColor3f(1.0f, 1.0f, 1.0f); > glBegin(GL_TRIANGLES); > glVertex2f(0.5f, -0.25f); > glVertex2f(-0.5f, -0.25f); > glVertex2f(0.0f, 0.75f); > glEnd(); > #endif > SDL_GL_SwapBuffers( ); > } > > int main(int argc, char *argv[]) > { > init(); > for(unsigned int i = 0; i < 1000; i++) { > update(); > } > return 0; > } > > -- > Yours > Peter Poulsen > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President > and CEO of GenToo technologies. Learn everything from > fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > plib-users mailing list > pli...@li... > https://lists.sourceforge.net/lists/listinfo/p> lib-users > |