Results 1 to 2 of 2

Thread: Moving inside the scene in any direction

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    NY
    Posts
    20

    Moving inside the scene in any direction

    Hi ,
    I need help!!
    I need to move inside the scene in any direction!!
    Also there should be some marker which can trace object and give warning or signal and it should not cross the object or go beyond the plane.
    " the best way to express this problem is like we have gun or cartoon in video game which move in the scene. Similarly I need to implement that".



    #include<iostream>
    #include<stdlib.h>
    #include <gl/glut.h>
    using namespace std;

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


    void display(void)
    {
    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f (1.0, 1,1.0);
    /* clear the matrix */
    /* viewing transformation */
    //...........................................
    // for front view
    //gluLookAt (0,0,12.0, 0.0, 0.0, 0.0, 0,1, 0);

    // for Angular view

    //gluLookAt (-1, 10, 12.0, 2.0, 2.0, 3.0, 0.0, 1, 0.0);
    //.................................................. ....
    // for top veiw
    //gluLookAt (0,15,0, 0.0,0.0, 0.0, 0.0,0, 1.0);
    //.................................................. .

    glScalef (1,1,1); /* modeling transformation */


    glBegin(GL_QUADS);
    glColor3f (0,1,0);
    glVertex3f(10,-0.5, 4.0);
    glVertex3f(10, -0.5, -10.0);
    glVertex3f(-10,-0.5, -10.0);
    glVertex3f(-10,-0.5,4.0);

    glEnd();



    glPushMatrix();
    glColor3f (1,0.5,0.0);
    glTranslatef (5.0, 0.0, -0.5);
    glutSolidCube(1.5);
    glPopMatrix();

    glPushMatrix();

    glTranslatef (4.0, 1.0, -1.5);
    glutSolidCube(1.5);
    glPopMatrix();


    glPushMatrix();

    glTranslatef (3.0, 2.0, -2.5);
    glutSolidCube(1.5);
    glPopMatrix();

    glPushMatrix();

    glTranslatef (2.0, 3.0,-3.5);
    glutSolidCube(1.5);
    glPopMatrix();



    glPushMatrix();
    glColor3f (0.0, 1.0, 1.0);
    glTranslatef (0.0, 0.0, 0.0);
    glutSolidSphere(0.5,100,100);
    glTranslatef (1.0, 0.0, 0.0);
    glutSolidSphere(0.5,100,100);
    glTranslatef (1.0, 0.0, 0.0);
    glutSolidSphere(0.5,100,100);
    glTranslatef (1.0, 0.0, 0.0);
    glutSolidSphere(0.5,100,100);

    glPopMatrix();


    glPushMatrix();
    glTranslatef (0.5,0.866, 0.0);
    glutSolidSphere(0.5,100,100);

    glPopMatrix();


    glPushMatrix();
    glTranslatef (1.5,0.866, 0.0);
    glutSolidSphere(0.5,100,100);
    glPopMatrix();

    glPushMatrix();
    glTranslatef (2.5,0.866, 0.0);
    glutSolidSphere(0.5,100,100);
    glPopMatrix();

    glPushMatrix();
    glTranslatef (1.0,1.732, 0.0);
    glutSolidSphere(0.5,100,100);

    glPopMatrix();

    glPushMatrix();
    glTranslatef (2.0,1.732, 0.0);
    glutSolidSphere(0.5,100,100);
    glPopMatrix();


    glPushMatrix();
    glTranslatef (1.5,2.598, 0.0);
    glutSolidSphere(0.5,100,100);
    glPopMatrix();



    // THis is left side sphere balls building up



    glPushMatrix();
    glTranslatef (-1.0, 0.0, 0.0);
    glColor3f (1,0,0.0);
    glutSolidSphere(0.5,100,100);
    glTranslatef (0.0, 0.0, -1.0);
    glutSolidSphere(0.5,100,100);
    glTranslatef (0.0, 0.0, -1.0);
    glutSolidSphere(0.5,100,100);
    glTranslatef (0.0, 0.0, -1.0);
    glutSolidSphere(0.5,100,100);

    glPopMatrix();


    glPushMatrix();
    glTranslatef (-1.0, 0.866, -0.5);
    glutSolidSphere(0.5,100,100);

    glPopMatrix();

    glPushMatrix();
    glTranslatef (-1.0, 0.866, -1.5);
    glutSolidSphere(0.5,100,100);

    glPopMatrix();


    glPushMatrix();
    glTranslatef (-1.0, 0.866, -2.5);
    glutSolidSphere(0.5,100,100);

    glPopMatrix();

    glPushMatrix();
    glTranslatef (-1.0, 1.732, -1);
    glutSolidSphere(0.5,100,100);
    glPopMatrix();

    glPushMatrix();
    glTranslatef (-1.0, 1.732, -2);
    glutSolidSphere(0.5,100,100);

    glPopMatrix();

    glPushMatrix();
    glTranslatef (-1.0, 2.598, -1.5);
    glutSolidSphere(0.5,100,100);
    glPopMatrix();

    glutSwapBuffers();


    glFlush ();
    }


    void reshape (int w, int h)
    {
    glViewport (0,0, (GLsizei) w, (GLsizei) h);

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();

    glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
    //glOrtho(-10,20,-10,10,10,-20);
    //glOrtho(-15,20,0,0,-15,15);
    //glFrustum (-1.0, 1.0, -1.5, 1.2, 1.5, 20.0);

    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    gluLookAt (-1, 10, 12.0, 2.0, 2.0, 3.0, 0.0, 1, 0.0);
    }

    void key(unsigned char key, int x, int y) {

    switch(key) {
    case 't':
    case 'T':
    glLoadIdentity();
    gluLookAt (0,15,0, 0.0,0.0, 0.0, 0.0,0, 1.0);
    glutPostRedisplay();
    break;

    case 'a':
    case 'A':
    glLoadIdentity();
    gluLookAt (-1, 10, 12.0, 2.0, 2.0, 3.0, 0.0, 1, 0.0);
    glutPostRedisplay();
    break;

    case 'f':
    case 'F':
    glLoadIdentity();
    gluLookAt (0,0,12.0, 0.0, 0.0, 0.0, 0,1, 0);
    glutPostRedisplay();
    break;
    }

    }

    int main(int argc, char** argv)
    {
    glutInit(&amp;argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);
    init ();

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(key);

    glutMainLoop();
    return 0;
    }

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Moving inside the scene in any direction

    please use [ code][ /code] (without a space after the '[') around code snippets to make them easier to read.

    I need to move inside the scene in any direction!!
    it looks like you already discovered gluLookAt(), which can be used for that. You keep track of the users position and view direction in two vec3 variables and for example if the user presses the key to move to the right you increment the position's x component. At the beginning of your display function you call gluLookAt() once to set the view to the current position and direction.

    Also there should be some marker which can trace object and give warning or signal and it should not cross the object or go beyond the plane.
    i don't understand what you want to do, but it sounds a bit as if what you are looking for is collision detection.

Similar Threads

  1. Moving to the pointed direction
    By angeldarkholme in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-16-2005, 10:11 PM
  2. Moving a ship and calculating direction to translate
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-27-2003, 03:10 PM
  3. moving in x direction using glLookAt()
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-27-2002, 08:37 PM
  4. Moving eyepoint in direction of viewing angles
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-02-2002, 12:57 PM
  5. Moving a triangle regardless of direction
    By Harnak in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 02-07-2001, 01:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean