GLVector location = new GLVector (5f, .5f, 5f);e = new CGEngine ( canvas , location );e. camera (). lookAt ( lookAt );setVisible ( true );canvas . requestFocus ();}animator = new FPSAnimator ( canvas , 25);animator . start ();@Overri<strong>de</strong>public void dispose ( GLAutoDrawable drawable ) {}@Overri<strong>de</strong>public void init ( GLAutoDrawable drawable ) {GL2 gl = drawable . getGL (). getGL2 ();}// Grayish backgroundgl. glClearColor (0f, 0f, 0f, 0f);// Cull backs of polygonsgl. glCullFace ( GL2 . GL_BACK );gl. glFrontFace ( GL2 . GL_CCW );gl. glEnable ( GL2 . GL_DEPTH_TEST );setupLight (gl );// Definir Pontos <strong>de</strong> ControloctrlPoints = new GLVectorList ();updateControlPoints ();// Activar a geracao automatica <strong>de</strong> normaisgl. glEnable ( GL2 . GL_AUTO_NORMAL );private float a0 = 0, a1 = GlTools . GL_PI / 4, a2 = GlTools . GL_PI / 2;private void updateControlPoints () {ctrlPoints . clear ();a0 += .1f;if(a0 >= GlTools . GL_PI )a0 = 0;a1 += .1f;if(a1 >= GlTools . GL_PI )a1 = 0;a2 += .1f;if(a2 >= GlTools . GL_PI )a2 = 0;// v0ctrlPoints . add ( -4f, 0f, 4f); // Start (u0)ctrlPoints . add ( -2f, ( float ) ( Math . sin (a0) * 8f - 4f), 4f); // Control (u0)ctrlPoints . add (4f, 0f, 4f); // End (u0)// v1ctrlPoints . add ( -4f, 0f, 0f); // Start (u1)ctrlPoints . add ( -2f, ( float ) ( Math . sin (a1) * 8f - 4f), 0f); // Control (u1)145
ctrlPoints . add (4f, 0f, 0f); // End (u1)}// v2ctrlPoints . add ( -4f, 0f, -4f); // Start (u2)ctrlPoints . add ( -2f, ( float ) ( Math . sin (a2) * 8f - 4f), -4f); // Control (u2)ctrlPoints . add (4f, 0f, -4f); // End (u2)private void setupLight ( GL2 gl) {// Setup light parametersgl. glLightMo<strong>de</strong>lfv ( GL2 . GL_LIGHT_MODEL_AMBIENT , fNoLight , 0);gl. glLightMo<strong>de</strong>li ( GL2 . GL_LIGHT_MODEL_COLOR_CONTROL ,GL2 . GL_SEPARATE_SPECULAR_COLOR );gl. glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_AMBIENT , fLowLight , 0);gl. glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_DIFFUSE , fBrightLight , 0);gl. glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_SPECULAR , fBrightLight , 0);gl. glEnable ( GL2 . GL_LIGHTING );gl. glEnable ( GL2 . GL_LIGHT0 );}// Utilizar color trackinggl. glEnable ( GL2 . GL_COLOR_MATERIAL );gl. glColorMaterial ( GL2 . GL_FRONT , GL2 . GL_AMBIENT_AND_DIFFUSE );gl. glMateriali ( GL2 . GL_FRONT , GL2 . GL_SHININESS , 128);public void display ( GLAutoDrawable drawable ) {GL2 gl = drawable . getGL (). getGL2 ();gl. glClear ( GL2 . GL_COLOR_BUFFER_BIT | GL2 . GL_DEPTH_BUFFER_BIT );updateControlPoints ();// Componente Especulargl. glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_SPECULAR , fBrightLight , 0);// Posicao da Luzgl. glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_POSITION , fLightPos . toArray () , 0);float umin = 0f; // Valor minimo do ufloat umax = 10f; // Valor maximo do ufloat vmin = 0f; // Valor minimo do vfloat vmax = 10f; // Valor maximo do vgl. glMap2f (GL2 . GL_MAP2_VERTEX_3 , // Tipo <strong>de</strong> dados geradosumin , // Valor minimo do uumax , // Valor maximo do u3, // Distancia entre pontos ( dominio u)3, // Numero <strong>de</strong> pontos <strong>de</strong> controlo ( dominio u)vmin , // Valor minimo do vvmax , // Valor maximo do v9, // Distancia entre pontos ( dominio v)3, // Numero <strong>de</strong> pontos <strong>de</strong> controlo ( dominio v)ctrlPoints . toFloatBuffer () // FloatBuffer contendo pontos <strong>de</strong> controlo);// Activar o Evaluatorgl. glEnable ( GL2 . GL_MAP2_VERTEX_3 );// Desenhar os vertices da superficiegl. glColor3f (0f, 0f, 1f);gl. glMapGrid2d (10 , umin , umax , 10 , vmin , vmax );gl. glEvalMesh2 ( GL2 . GL_FILL , ( int )umin , ( int )umax , ( int )vmin , ( int ) vmax );// Desenhar Pontos <strong>de</strong> Controlo146