Solved

Computer Vision(Eye Camera Analogy In OPen GL)

Posted on 2001-07-11
4
776 Views
Last Modified: 2008-03-17
Here was a interesting thing  which I was doing and i  have  divided in to two parts, I  am trying  to rotate a camera around a object in a elliptical shape with radius 30  and obtain different shapes from different perspective center(Looking points).

The coordinates of the vertices of the cube are as below.
 
       V1      V2      V3      V4      V5      V6      V7      V8
X      0      1      0      1      0      1      0      1
Y      0      0      0      0      1      1      1      1
Z      0      0      1      1      0      0      1      1


At First:
Here is a Computer Graphics program in OPen GL language. The following is a error free executable code and is drawing a cube.My question 1)is how I can to print the co-ordinates of this in EYE CO-Ordinate System.
        2)Is there any function in Open GL to find the reflection around z-axis(xy-plane)
    like eg glTranslatef(x,y,z)
         3)How to obtain the screen coordinates of the cube.
Secondly:
  After obtaining the above screen co-ordinates How to rotate the camera and obtain the
 different perspective views


                 #include <GL/glut.h>
      #include <stdlib.h>

      void init(void)
      {
         glClearColor (0.0, 0.0, 0.0, 0.0);
         glShadeModel (GL_FLAT);
      }

      void display(void)
      {
      /* This is the display callback, called whenever window
       * needs to be displayed.
       *
       * Start by clearing screen and setting colour to white
       */
         glClear (GL_COLOR_BUFFER_BIT);
         glColor3f (1.0, 1.0, 1.0);

      /* Transformation - first step is to set the matrix to the identity */
         glLoadIdentity ();
         
      /* Viewing transformation is specified by gluLookAt
       * whose first 3 parameters give the camera position,
       * next three give the point to look at,
       * and the final three give the up-direction ..
       * so in this example, the camera is at (8,10,12) - ie at,
       * the point we are looking at is the origin - ie along negative z-axis
       * and the up-direction is positive y
       */
         gluLookAt (8.0, 10.0, 12, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

         /* self-code*/
        //glTranslated(-6.0,-8.0,-7.5);
        
        //glScalef(1.0,2.0,0.0);
      
      /* The GLUT library has some useful drawing routines, here we draw a
       * wire frame outline of a cube.
       */
         glutWireCube (1.0);

      /* .. and finally we flush the buffer
       */
         glFlush ();
      }

      void reshape (int w, int h)
      {
      /* This callback is invoked at startup and when the window is resized by
       * the user
       *
       * First the viewport size is defined - this will be the
       * width and height as set in the initialization stage,
       * or the width/height of the resizing by the user
       */
         glViewport (0, 0, (GLsizei) w, (GLsizei) h);

      /* Next we define the projection:
       *       -  glMatrixMode says what kind of matrix we are constructing,
       *      here a projection matrix
       *      - glLoadIdentity sets it initially to the identity
       *      - glFrustum specifies the viewing volume
       *      the first two coords give the x-limits, next two the y-limits
       *      of the near clipping plane,while the final two give the
       *       z-limits (ie near and far clipping planes)
       *      .. so here we have a view window of -1 < x < 1, -1 < y < 1
       *      in the near clipping plane at z=1.5, with far plane at z=20.0
       */

          
        
         glMatrixMode (GL_PROJECTION);
         glLoadIdentity ();
        
         //glTranslatef(-6,-8,-7.5);
          glRotatef(38.65,0.0,1.0,0.0);
        glRotatef(46.84,1.0,0.0,0.0);
       

         glFrustum (-1.0, 1.0, -1.0, 1.0, 3.0, 20.0);

      /* Finally we reset the matrix mode to model-view
       */
         glMatrixMode (GL_MODELVIEW);


      }


      void keyboard(unsigned char key, int x, int y)
      {
      /* This callback is invoked when a user presses a key.
       * Here if ASCII 27 is received, ie ESC, then we exit.
       */

         switch (key) {
              case 27:
                   exit(0);
                   break;
         }
      }

      int main(int argc, char** argv)
      {
      /* This is a set of GLUT initialization calls:
       *      - glutInit is always the first called, and it will process
       *      any arguments from command line (eg if this program is
       *      executed as 'cube -iconic', then the initial window
       *      will be iconified
       *      - glutInitDisplayMode sets the way output is displayed...
       *      .. here we use single buffering, and RGB colour model,
       *      which are standard settings for simple output
       *      - glutInitWindowSize, glutInitWindowPosition give the size
       *      and position of the display window, in pixels (origin top left)
       */
         glutInit(&argc, argv);
         glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
         glutInitWindowSize (500, 500);
         glutInitWindowPosition (100, 100);

      /* This creates a window of the size and position specified:
       *      - the name of the window comes from command line
       */
         glutCreateWindow (argv[0]);

      /* This is where we initialize OpenGL
       */
         init ();

      /* This is a set of GLUT callbacks, which are actions that respond to events:
       *      - glutDisplayFunc is the display callback, and will get called
       *      whenever GLUT decides that the window needs to be redrawn
       *      including of course at the start
       *      - glutReshapeFunc is called at the start, or when the window
       *      is re-shaped
       *      - glutKeyboardFunc is called when a user types a character at
       *      the keyboard
       */
         glutDisplayFunc(display);
         glutReshapeFunc(reshape);
         glutKeyboardFunc(keyboard);

      /* This is the event processing loop which typically is placed at the end.
       * Once called this routine never returns.
       */
         glutMainLoop();
         return 0;
      }
0
Comment
Question by:michael306
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
CJ_S earned 50 total points
ID: 6292614
In general you have a viewport, projection and world matrix. Any of these can change. You already have a viewport, so you can easily use the translate, transform and other methods provided by OpenGL.

Your question is a little bit unclear to me. Exactly what do you mean by obtaining the points? I mean, you have filled the cube, so you know where the cube's coordinates are...?? Do you mean the printing of the coordinates? Normally you can retrieve the device context of the primary surface, and use the textOut funcxtion to write to it, just as one would normally do using any of the dc's available.

Please add more information to this question... for me it is unclear.

Regards,
CJ
0
 

Author Comment

by:michael306
ID: 6296441
Hello Expert,
  Let me explain the question again, I wanted  a cube rotating with an angle of looking point as above mentioned  point(6 8 7.5) and would like the cube rotating at an axis of 6 radius, of height 8 and lets assume that the cube is making an angle of rotation about itself at 10 and now i should be able to see the cube rotating slowly with an increase in position of camera around the circle automatically.

The code i want to make work is being commented on the top.If i am correct. i also tried calling a function from the main to call this code and make the cube rotating in the xz plane.If this wrong way of doing give me the correct way of doing this.
/*
for(double theta1=25;theta1<=350;theta1=theta1+25)
            {
                  glTranslated(0.0,0.0,-8);
                  glRotated(-10.0,0.0,0.0,1.0);
                  glRotated(-theta1,1.0,0.0,0.0);
                glRotated(theta1,0.0,0.0,1.0);
            }

 .
 */
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>

 int a,b,c;
 char ch;
void init(void)
{
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel (GL_FLAT);
}

void display(void)
{
      
      
/* This is the display callback, called whenever window
 * needs to be displayed.
 *
 * Start by clearing screen and setting colour to white
 */
   glClear (GL_COLOR_BUFFER_BIT);
   glColor3f (1.0, 1.0, 1.0);

      
/* Transformation - first step is to set the matrix to the identity */
 
/* Viewing transformation is specified by gluLookAt
 * whose first 3 parameters give the camera position,
 * next three give the point to look at,
 * and the final three give the up-direction ..
 * so in this example, the camera is at (6,8,7.5) - ie at,
 * the point we are looking at is the origin - ie along negative z-axis
 * and the up-direction is positive y
 */
        
 
       glLoadIdentity ();
 
   gluLookAt (a, b, c, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
/* removed 1 */

/* The GLUT library has some useful drawing routines, here we draw a
 * wire frame outline of a cube.
 */
   glutWireCube (1.0);

/* .. and finally we flush the buffer
 */         

   glFlush ();
   
}
      

void reshape (int w, int h)
{
/* This callback is invoked at startup and when the window is resized by
 * the user
 *
 * First the viewport size is defined - this will be the
 * width and height as set in the initialization stage,
 * or the width/height of the resizing by the user
 */
   glViewport (0, 0, (GLsizei) w, (GLsizei) h);

/* Next we define the projection:
 *       -  glMatrixMode says what kind of matrix we are constructing,
 *      here a projection matrix
 *      - glLoadIdentity sets it initially to the identity
 *      - glFrustum specifies the viewing volume
 *      the first two coords give the x-limits, next two the y-limits
 *      of the near clipping plane,while the final two give the
 *       z-limits (ie near and far clipping planes)
 *      .. so here we have a view window of -1 < x < 1, -1 < y < 1
 *      in the near clipping plane at z=1.5, with far plane at z=20.0
 */

   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   
      double theta1,theta2;
      theta1=a/b;
      theta2=b/c;
      glRotatef(theta1,0.0,1.0,0.0);
    glRotatef(theta2,1.0,0.0,0.0);
      glNormal3f(1,1,0);
   

   glFrustum (-1.0, 1.0, -1.0, 1.0, 3.0, 200.0);
/* Finally we reset the matrix mode to model-view
 */
   glMatrixMode (GL_MODELVIEW);
 
      }


void keyboard(unsigned char key, int x, int y)
{
/* This callback is invoked when a user presses a key.
 * Here if ASCII 27 is received, ie ESC, then we exit.
 */

   switch (key) {
        case 27:
             exit(0);
             break;
   }
}
 

void main(int argc, char** argv)
{
/* This is a set of GLUT initialization calls:
 *      - glutInit is always the first called, and it will process
 *      any arguments from command line (eg if this program is
 *      executed as 'cube -iconic', then the initial window
 *      will be iconified
 *      - glutInitDisplayMode sets the way output is displayed...
 *      .. here we use single buffering, and RGB colour model,
 *      which are standard settings for simple output
 *      - glutInitWindowSize, glutInitWindowPosition give the size
 *      and position of the display window, in pixels (origin top left)
 */
      
      printf("Enter the camera position \n");
      scanf("%d %d %d",&a,&b,&c);
   
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize (300, 300);
   glutInitWindowPosition (100, 100);

/* This creates a window of the size and position specified:
 *      - the name of the window comes from command line
 */
   glutCreateWindow (argv[0]);

/* This is where we initialize OpenGL
 */
   init ();
 
/* This is a set of GLUT callbacks, which are actions that respond to events:
 *      - glutDisplayFunc is the display callback, and will get called
 *      whenever GLUT decides that the window needs to be redrawn
 *      including of course at the start
 *      - glutReshapeFunc is called at the start, or when the window
 *      is re-shaped
 *      - glutKeyboardFunc is called when a user types a character at
 *      the keyboard
 */
   glutDisplayFunc(display);
   
   glutReshapeFunc(reshape);
   reshape(100,100);
   glutKeyboardFunc(keyboard);
      

/* This is the event processing loop which typically is placed at the end.
 * Once called this routine never returns.
   */
   //glutIdleFunc(Idle);
   glutMainLoop();
      glutDisplayFunc(display);
   
      
 
}
      
0
 

Author Comment

by:michael306
ID: 6310563
I waited for the Answer....
Thanks
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6311293
Sorry for letting you wait this long. You will have to wait for another while, I've had some trouble (laptop stolen)...and that took most of my time, trying to recover the work and stuff.

Regards,
CJ
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Controlled Assessment GCSE - desperate help needed 4 90
Currency Conversion? 1 88
Please explain: Aspect Oriented Programming 2 96
printf performancy 11 45
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question