Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Rotating and Scaling without gl

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2012
    Location
    TR
    Posts
    5

    Rotating and Scaling without gl

    Hi everyone, I'm kinda new to gl coding, I'm taking computer graphics in university for this topic. My homework is rotating and scaling a pyramid without using gl. Where I can start and how can I accomplish the task. Need help please.

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,048

    Re: Rotating and Scaling without gl

    Didn't your professor teach you how to do that?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    11

    Re: Rotating and Scaling without gl

    Basic algebra can dictate a transformation matrix.

    X 0 0 0
    Y 3 3 3
    Z 0 0 0

    matrix addition applied to each vertex can represent a simple transform.
    Acquire a book on linear algebra, or google matrix manipulation.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2012
    Location
    TR
    Posts
    5

    Re: Rotating and Scaling without gl

    @Alfonse, he did mention about that on paper, but not about coding.

    @Daniel, I understand the matrix multiplication for rotating and scaling but, then how am I going to create the pyramid and what these matrices represent compared to the pyramid? The part representing a pyramid with a matrix I really don't understand.

  5. #5
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214

    Re: Rotating and Scaling without gl

    A pyramid consists of a number of vectors. You can find some good basics about vector maths at http://www.arcsynthesis.org/gltut/Ba...roduction.html

    When you have read that, look at http://content.gpwiki.org/index.php/Matrix_math for information about matrices and transformations.

    Finally, if you want to do a program of your own for doing matrix operations, I would recommend to use the glm package. This package supports the same operations as OpenGL.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2012
    Location
    TR
    Posts
    5

    Re: Rotating and Scaling without gl

    So correct me if I'm wrong, I'm going to create a 4X3 matrix, which will hold the vertices of the pyramid and a function to draw the lines between them. Then when I need to rotate or scale, I multiply or do the needed calculation to this matrix and redraw the pyramid in every time?

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117

    Re: Rotating and Scaling without gl

    You don't seem to understand matrices, try reading this

    http://knol.google.com/k/matrices-fo...ransformations

  8. #8
    Junior Member Newbie
    Join Date
    Mar 2012
    Location
    TR
    Posts
    5

    Re: Rotating and Scaling without gl

    Now, I had some other assignments but finally find time to work on this. I read all your replies and tried to make something, gonna post it here so you can have a look and leave a comment.

    First I defined the values that will keep the rotation information like this:
    static float yaxis[33][3]= {{2,0,0},{1.75,0,-0.9682},{1.50,0,-1.323},{1.25,0,-1.561},
    {1,0,-1.732},{0.75,0,-1.854},{0.50,0,-1.936},{0.25,0,-1.984},
    {0,0,-2},{-0.25,0,-1.984},{-0.50,0,-1.936},{-0.75,0,-1.854},
    {-1,0,-1.732},{-1.25,0,-1.561},{-1.50,0,-1.323},{-1.75,0,-0.9682},
    {-2,0,0},{-1.75,0,0.9682},{-1.50,0,1.323},{-1.25,0,1.561},
    {-1,0,1.732},{-0.75,0,1.854},{-0.50,0,1.936},{-0.25,0,1.984},
    {0,0,2},{0.25,0,1.984},{0.50,0,1.936},{0.75,0,1.85 4},
    {1,0,1.732},{1.25,0,1.561},{1.50,0,1.323},{1.75,0, 0.9682},{2,0,0} };

    And defined this to select between the y values
    static float yselect[3];
    int count = 0;

    In the initiation function, I initiate alpha to 0, scale to 1.8 and select y values

    yselect[0] = yaxis[0][0];
    yselect[1] = yaxis[0][1];
    yselect[2] = yaxis[0][2];

    while in the idle function I keep an integer for the 1/4 of the rotation, whenever that variable is 25, the scale is incremented and the variable is reset

    fre++;
    if (fre == 25)
    {
    scale=scale+0.025;
    count++;
    fre = 0;
    }

    And in every frame the y values changes according to the values I defined on top

    yselect[0] = yaxis[count %33][0];
    yselect[1] = yaxis[count %33][1];
    yselect[2] = yaxis[count %33][2];


    now in the reshape function, I used gl's lighting function, I dont know whether it is doing something or not but

    void reshape (int width, int height)
    {
    float black[] = { 0, 0, 0, 0 };

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60, (float)width/height, 0.1, 1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    gluLookAt(0, 1, 6, 0, 1, 0, 0, 1, 0);

    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_LIGHT0);

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    }

    and initiate all in main
    void main (int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(512,512);
    glutCreateWindow("asd");

    init();

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutVisibilityFunc(visibility);
    glutMainLoop();

    return;
    }

    When I execute, the rotation and scaling of the pyramid works fine. However it is a bit fast but that is not important. I dont know how I can code my own lighting function, and use it. So what do you say, how can I make a lighting point source and work on it?

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117

    Re: Rotating and Scaling without gl

    For lighting to work you need to have a normal at each vertex and look at the lighting functions

    glLightfv(GL_LIGHT0,GL_POSITION,light_position);
    glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse_light);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

  10. #10
    Junior Member Newbie
    Join Date
    Mar 2012
    Location
    TR
    Posts
    5

    Re: Rotating and Scaling without gl

    In the assignment it says dont use gl functions for lighting. These count as gl functions right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •