// uses nehelesson5 to draw some geometry module Main; use tksdl; use tkopengl; use tkoldmath; float rtri=0.0; // Angle For The Triangle ( NEW ) float rquad=0.0; // Angle For The Quad ( NEW ) int vsync=1; int rtri_type=0; float clip_rotx_ang = 0; float clip_roty_ang = 0; float clip_rotz_ang = 0; function onDraw() { Matrix m,m2; Vector v; //viewport.waitVBlank(); zglInitPerspective(1.3, 45.0, 0.1, 100.0); //glCullFace(GL_BACK); //glEnable(GL_CULL_FACE); //glFrontFace(GL_CCW); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_DEPTH_TEST); glClearColor(0.1,0.1,0.1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); switch(rtri_type) { case 0: glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef(-1.5,0.0,-6.0); // Move Left 1.5 Units And Into The Screen 6.0 glRotatef( rtri, 0.0, 1.0, 0.0 ); // Rotate The Triangle On The Y axis ( NEW ) break; case 1: m.initDeg( 0, rtri , 0); zglLoadMatrix(m, vector(-1.5,0.0,-6.0)); break; case 2: m.initv(vector(0,rtri*2PI/360.0,0)); zglLoadMatrix(m, vector(-1.5,0.0,-6.0)); break; case 3: glLoadIdentity(); glTranslatef(-1.5,0.0,-6.0); zglRotate3f(0.0, rtri, 0.0); break; case 4: glLoadIdentity(); zglTranslatev(vector(-1.5,0.0,-6.0)); zglRotatev(vector(0,rtri,0)); break; } glEnable(GL_CLIP_PLANE0); Matrix clipmat; clipmat.init(clip_rotx_ang, clip_roty_ang, clip_rotz_ang); Vector clipvec; clipvec.init(0.0,0,1); clipvec.rotate(clipmat); ///zglRotate3f(clip_rotx_ang, clip_roty_ang, clip_rotz_ang); zglClipPlane(GL_CLIP_PLANE0, clipvec.x, clipvec.y, clipvec.z, 0.0); glBegin(GL_TRIANGLES); // Start Drawing A Triangle zglColorARGB($ff0000); // Red glVertex3f(0.0, 1.0, 0.0); // Top Of Triangle (Front) zglColorARGB($00ff00); // Green glVertex3f(-1.0,-1.0, 1.0); // Left Of Triangle (Front) zglColorARGB($0000FF); // Blue glVertex3f( 1.0,-1.0, 1.0); // Right Of Triangle (Front) zglColorARGB($FF0000); // Red glVertex3f(0.0, 1.0, 0.0); // Top Of Triangle (Right) zglColorARGB($0000FF); // Blue glVertex3f(1.0, -1.0, 1.0); // Left Of Triangle (Right) zglColorARGB($00FF00); // Green glVertex3f(1.0, -1.0, -1.0); // Right Of Triangle (Right) zglColorARGB($FF0000); // Red glVertex3f(0.0, 1.0, 0.0); // Top Of Triangle (Back) zglColorARGB($00FF00); // Green glVertex3f(1.0, -1.0, -1.0); // Left Of Triangle (Back) zglColorARGB($0000FF); // Blue glVertex3f(-1.0, -1.0, -1.0); // Right Of Triangle (Back) zglColorARGB($FF0000); // Red glVertex3f(0.0, 1.0, 0.0); // Top Of Triangle (Left) zglColorARGB($0000FF); // Blue glVertex3f(-1.0, -1.0, -1.0); // Left Of Triangle (Left) zglColorARGB($00FF00); // Green glVertex3f(-1.0, -1.0, 1.0); // Right Of Triangle (Left) glEnd(); // Done Drawing The Pyramid glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef(1.5, 0.0, -7.0); // Move Right 1.5 Units And Into The Screen 7.0 glRotatef(rquad, 1,1,1); // Rotate The Quad On The X axis ( NEW ) glEnable(GL_CLIP_PLANE0); clipmat.init(clip_rotx_ang, clip_roty_ang, clip_rotz_ang); clipvec.init(0.0,0,1); clipvec.rotate(clipmat); ///zglRotate3f(clip_rotx_ang, clip_roty_ang, clip_rotz_ang); zglClipPlane(GL_CLIP_PLANE0, clipvec.x, clipvec.y, clipvec.z, 0.0); glBegin(GL_QUADS); // Draw A Quad zglColorARGB($00FF00); // Set The Color To Blue glVertex3f(1.0, 1.0, -1.0); // Top Right Of The Quad (Top) glVertex3f(-1.0, 1.0, -1.0); // Top Left Of The Quad (Top) glVertex3f(-1.0, 1.0, 1.0); // Bottom Left Of The Quad (Top) glVertex3f(1.0, 1.0, 1.0); // Bottom Right Of The Quad (Top) zglColorARGB($FF8000); // Set The Color To Orange glVertex3f(1.0, -1.0, 1.0); // Top Right Of The Quad (Bottom) glVertex3f(-1.0, -1.0, 1.0); // Top Left Of The Quad (Bottom) glVertex3f(-1.0, -1.0, -1.0); // Bottom Left Of The Quad (Bottom) glVertex3f(1.0, -1.0, -1.0); // Bottom Right Of The Quad (Bottom) zglColorARGB($FF0000); // Set The Color To Red glVertex3f(1.0, 1.0, 1.0); // Top Right Of The Quad (Front) glVertex3f(-1.0, 1.0, 1.0); // Top Left Of The Quad (Front) glVertex3f(-1.0, -1.0, 1.0); // Bottom Left Of The Quad (Front) glVertex3f(1.0, -1.0, 1.0); // Bottom Right Of The Quad (Front) zglColorARGB($FFFF00); // Set The Color To Yellow glVertex3f(1.0, -1.0, -1.0); // Top Right Of The Quad (Back) glVertex3f(-1.0,-1.0,-1.0); // Top Left Of The Quad (Back) glVertex3f(-1.0, 1.0,-1.0); // Bottom Left Of The Quad (Back) glVertex3f(1.0, 1.0, -1.0); // Bottom Right Of The Quad (Back) zglColorARGB($0000FF); // Set The Color To Blue glVertex3f(-1.0, 1.0, 1.0); // Top Right Of The Quad (Left) glVertex3f(-1.0, 1.0, -1.0); // Top Left Of The Quad (Left) glVertex3f(-1.0, -1.0, -1.0); // Bottom Left Of The Quad (Left) glVertex3f(-1.0, -1.0, 1.0); // Bottom Right Of The Quad (Left) zglColorARGB($FF00FF); // Set The Color To Violet glVertex3f(1.0, 1.0, -1.0); // Top Right Of The Quad (Right) glVertex3f(1.0, 1.0, 1.0); // Top Left Of The Quad (Right) glVertex3f(1.0, -1.0, 1.0); // Bottom Left Of The Quad (Right) glVertex3f(1.0, -1.0, -1.0); // Bottom Right Of The Quad (Right) glEnd(); // Done Drawing The Quad glDisable(GL_CULL_FACE); glDisable(GL_CLIP_PLANE0); if(vsync) Viewport.waitVBlank(); float dt=FPS.precision; rtri+=2.0*dt; // Increase The Rotation Variable For The Triangle ( NEW ) rquad-=1.0*dt; // Decrease The Rotation Variable For The Quad ( NEW ) clip_rotx_ang += dt*0.012345; clip_roty_ang += dt*0.031123; clip_rotz_ang += dt*0.025912; } function onKeyboard(Key _k) { if(_k.pressed==VKEY_ESCAPE) SDL.exitEventLoop(); } function main() { Viewport.openWindow(320, 240); FPS.tickInterval=1000.0/60.0; FPS.tickBuffer=0; FPS.limit=60; trace "-------- nehelesson5 --------"; trace " esc : exit"; trace "\n\n"; use callbacks; SDL.eventLoop(); }