OpenGL programming based on MFC Part 5 transformations

Source: Internet
Author: User

OpenGL programming based on MFC Part 5 transformations-rotations,translations and scaling

Transformations-translation, Rotation and scaling

Translation is no but moving along an arbitrary axis. Rotation is spinning about a arbitrary axis. Scaling is increase or decrease in size along a arbitrary axis. One important point to remember is this OpenGL uses a right hand coordinate system where z-ve in the screen. An object said to is undergoing a transformation could be undergoing a translation, rotation and/or. Understanding different types of transformations work together is very important.

This article will model the Earth around the sun, and it will also have the moon accompanying, and in the following will be added to the mouse and keyboard event response mechanism.

Drawing code

void CCY457OpenGLView::RenderScene ()
{//绘制函数
    //Draw Sun
  glTranslatef(0.0f,0.0f,-5.0f);
  glRotatef(6,1.0f,0.0f,0.0f);
  glutWireSphere(1.0f,20,20);
  //Draw Planet
  glPushMatrix();
    glTranslatef(-1.2f,-0.5f,-2.0f);
    glRotatef(6,1.0f,0.0f,0.0f);
    glutWireSphere(0.5f,20,20);
    //Draw Moon
    glPushMatrix();
      glTranslatef(-1.2f,-0.5f,-2.0f);
      glRotatef(6,1.0f,0.0f,0.0f);
      glutWireSphere(0.05f,20,20);
    glPopMatrix();
  glPopMatrix();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.