পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Saturday, January 21, 2017

JOGL - Transformation

OpenGL provides more features such as applying colors to an object, scaling, lighting, rotating an object, etc. This chapter describes some of the transformations on objects using JOGL.

Moving an Object on the Window

In earlier chapters, we discussed the programs for drawing a line and drawing various shapes using simple lines. The shapes created in this way can be displayed on any location within the window. It is done using the method glTranslatef (float x, float y, float z).
This method belongs to the GLMatrixFunc interface, which is in the javax.media.opengl.fixedfunc package.

GLMatrixFunc Interface

interface − GLMatrixFunc
package − javax.media.opengl.fixedfunc
The following table lists some important methods of this interface −
Sr.No. Methods and Description
1 void glRotatef(float angle, float x, float y, float z)
Rotates the current matrix.
2 void glScalef(float x, float y, float z)
Used to scale the current matrix.
3 void glTranslatef(float x, float y,float z)
Used to translate the current matrix.
4 void glLoadIdentity()
Loads the current matrix with identity matrix.
The glTranslate() method moves the origin of the coordinate system to the point specified by the parameters (x,y,z), passed to the glTranslate() method as
argument. To save and restore the untranslated coordinate system, glPushMatrix() and glPopMatrix() methods are used.
gl.glTranslatef(0f, 0f, -2.5f); 
Whenever glTranslate() is used, it changes the position of the component on the screen. Hence, the reshape() method of GLEventListener interface should be overridden and OpenGL viewport and projection matrix should be initialized.
The following code shows the template to initialize a view port and projection matrix −
public void reshape(GLAutoDrawable drawable, int x,  int y, int width, int height) { 
  
   // TODO Auto-generated method stub 
   final GL2 gl = drawable.getGL().getGL2();  
            
   // get the OpenGL 2 graphics object   
   if(height <= 0) height = 1; 
       
   //preventing devided by 0 exception height = 1; 
   final float h = (float) width / (float) height; 
            
   // display area to cover the entire window 
   gl.glViewport(0, 0, width, height); 
            
   //transforming projection matrix 
   gl.glMatrixMode(GL2.GL_PROJECTION); 
   gl.glLoadIdentity(); 
   glu.gluPerspective(45.0f, h, 1.0, 20.0); 
      
   //transforming model view gl.glLoadIdentity(); 
   gl.glMatrixMode(GL2.GL_MODELVIEW); 
   gl.glLoadIdentity(); 
}

No comments:

Post a Comment