Exemple #1
0
        /// <summary>
        ///  Iscrtavanje OpenGL kontrole.
        /// </summary>
        public void Draw()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            
            Gl.glPushMatrix();
            Gl.glTranslatef(0.0f, 0.0f, -m_sceneDistance);
            Gl.glRotatef(m_xRotation, 1.0f, 0.0f, 0.0f); //odamh za 10
            Gl.glRotatef(m_yRotation, 0.0f, 1.0f, 0.0f);

            // Tacka 6 faza 2: Pozicionirati kameru, tako da se vide deo planete, kao i bočna i gornja strana svemirskog broda.
            Glu.gluLookAt(-10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

            //Tacka 9 faza 2 Pozicionirati tackasti izvor svetlosti iznad broda
            float[] positionLight0 = { 0.0f, 40.0f, 0.0f, 1.0f };
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, positionLight0);

            //planeta
            Gl.glPushMatrix();
            Gl.glTranslatef(0.0f, -80.0f, 0.0f);
            Gl.glRotatef(moon_rotationAngle, 0.0f, 1.0f, 0.0f);
            Gl.glColor3f(0.4f, 0.4f, 0.4f);
            Glu.gluQuadricNormals(gluObject, Glu.GLU_SMOOTH);
            Glu.gluQuadricTexture(gluObject, Gl.GL_TRUE);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Moon]);
            Glu.gluSphere(gluObject, 60.0f, 128, 128);
           
            Gl.glPopMatrix();
        
            //nosac postolja
            Gl.glPushMatrix();
            Gl.glTranslatef(0.0f, -50.0f + standCarrier, 0.0f);
            Gl.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
            Gl.glColor3f(0.4f, 0.4f, 0.4f);
            Glu.gluQuadricNormals(gluObject, Glu.GLU_SMOOTH);
            Glu.gluQuadricTexture(gluObject, Gl.GL_TRUE);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Metal_light]);
            Glu.gluCylinder(gluObject, 10.0f, 5.0f, 40.0f, 128, 128);
            Gl.glPopMatrix();

            //postolje
            Gl.glPushMatrix();
            postolje = new Box(boxScaleX, 5.0, boxScaleZ);
            Gl.glTranslatef(0.0f, -10.0f + standHeight, 0.0f);
            Gl.glRotatef(standAngle, 0.0f, 1.0f, 0.0f);
            // Tacka 10 faza 2: Način stapanja teksture sa materijalom postolja postaviti na GL_ADD
            Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_ADD);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Metal_dark]);
            Gl.glMatrixMode(Gl.GL_TEXTURE);

            Gl.glPushMatrix();
            Gl.glScalef(0.3f, 0.3f, 0.3f);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glColor3f(0.2f, 0.2f, 0.2f);
            postolje.Draw();
            Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_MODULATE);

            Gl.glMatrixMode(Gl.GL_TEXTURE);
            Gl.glPopMatrix();

            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glPopMatrix();

            //brod
            Gl.glPushMatrix();
            Gl.glRotatef(m_rotationAngle, 0.0f, 1.0f, 0.0f);
            Gl.glTranslatef(m_shipDistance, 4.0f + shipHeight, m_shipR);
            Gl.glScaled(scaleShip, scaleShip, scaleShip);
            m_scene.Draw();
            Gl.glPopMatrix();

            //ona prva 
            Gl.glPopMatrix();

            //teskt
            Gl.glPushMatrix();
            Gl.glColor3f(1.0f, 0.0f, 0.0f);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluOrtho2D(-15, 15, -15, 15);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
            Gl.glPushMatrix();
            Gl.glDisable(Gl.GL_LIGHTING);

            Gl.glPushMatrix();
            Gl.glTranslatef(-outFont.CalculateTextWidth(predmet) * -0.25f, 13.5f, 0.0f);
            outFont.DrawText(predmet);
            Gl.glPopMatrix();

            Gl.glPushMatrix();
            Gl.glTranslatef(-outFont.CalculateTextWidth(predmet) * -0.25f, 12.5f, 0.0f);
            outFont.DrawText(skolGod);
            Gl.glPopMatrix();

            Gl.glPushMatrix();
            Gl.glTranslatef(-outFont.CalculateTextWidth(predmet) * -0.25f, 11.5f, 0.0f);
            outFont.DrawText(ime);
            Gl.glPopMatrix();

            Gl.glPushMatrix();
            Gl.glTranslatef(-outFont.CalculateTextWidth(predmet) * -0.25f, 10.5f, 0.0f);
            outFont.DrawText(prezime);
            Gl.glPopMatrix();

            Gl.glPushMatrix();
            Gl.glTranslatef(-outFont.CalculateTextWidth(predmet) * -0.25f, 9.5f, 0.0f);
            outFont.DrawText(sifraZad);
            Gl.glPopMatrix();
            Gl.glPopMatrix();
            Gl.glPopMatrix();
            Resize();

            // Oznaci kraj iscrtavanja
            Gl.glFlush();
        }
Exemple #2
0
        /// <summary>
        ///  Konstruktor klase World.
        /// </summary>
        public World(int width, int height)
        {
            tenkX = -50.0f;
            brodaScale = 4.0f;
            this.m_width = width;
            this.m_height = height;
            this.tenk = new AssimpScene(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..\\..\\3D Models"), "M1_Abrams.3DS");
            this.brod = new AssimpScene(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..\\..\\3D Models"), "Norfolk bship.3ds");
            this.box = new Box(2000,100.0, 10.0);
            this.box1 = new Box(215, 100.0, 10.0);
            this.projektil = new Box(10, 1, 1);
            m_font1 = new OutlineFont("Helvetica", 14, 0.0f, false, false, true, false);
            projektil_x = -5.0f;
            projektilStacX = -5.0f;
            ShipRotation_z = 0;
            ShipTranslate_y = 10.0f;
            AnimacijaEnable = false;

            try
            {
                m_camera = new RacunarskaGrafika.Vezbe.Camera();
            }
            catch (Exception)
            {
                MessageBox.Show("Neuspesno kreirana instanca klase Camera", "GRESKA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            try
            {
                m_textures = new int[m_textureCount];
            }
            catch (Exception)
            {
                MessageBox.Show("Neuspesno kreirana instanca OpenGL sveta", "GRESKA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.Initialize();  // Korisnicka inicijalizacija OpenGL parametara

            this.Resize();      // Podesi projekciju i viewport
        }