Results 1 to 5 of 5

Thread: what's the problem??

  1. #1
    Junior Member
    Join Date
    May 2005
    Location
    Singapore
    Posts
    23

    what's the problem??

    #pragma comment(lib, "libGLES_CM.lib")
    #pragma comment(lib, "ug.lib")

    #include "ug.h"

    #define PIOVER180 0.01745329252

    int t;
    int velocity0 = 5;

    float velocity0x, velocity0y, velocity0z;
    float positionx, positiony, positionz;
    float angle1, angle2;

    float getNewPosition[] = {
    positionx,
    positiony,
    positionz
    };

    void init()
    {
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepthf(1.0f);
    }

    void trajectory(int);
    void display(UGWindow uwin)
    {
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    ugluLookAtf(
    0.0f, 0.0f, 2.0f,
    0.0f, 0.0f, 0.0f,
    0.0f, 1.0f, 0.0f);


    glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);

    ugSolidSpheref(0.1f, 25, 25);


    for(t=0; t<100; t++)
    {
    trajectory(t);
    glPushMatrix();
    {
    glTranslatef(getNewPosition[0], getNewPosition[1], getNewPosition[2]);

    }
    glPopMatrix();

    glFlush ();
    ugSwapBuffers(uwin);
    }


    }

    void trajectory(int t)
    {
    angle1 = 45;
    angle2 = 90;

    velocity0x = float(velocity0 * sin(angle1*PIOVER180)*sin(angle2*PIOVER180));
    velocity0y = float(velocity0 * cos(angle1*PIOVER180));
    velocity0z = float(velocity0 * sin(angle1*PIOVER180) * cos(angle2*PIOVER180));

    positionx = velocity0x * t;
    positiony = float(velocity0y * t - 0.5*9.8*t*t);
    positionz = velocity0z * t;
    }


    void keyboard(UGWindow uwin, int key, int x, int y)
    {
    switch(key)
    {
    case 'q' : exit(0); break;
    case UG_KEY_UP : exit(0); break;
    }
    }

    void reshape(UGWindow uwin, int width, int height)
    {

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glViewport(0, 0, width, height);
    ugluPerspectivef(45.0f, 1.0f * width / height, 1.0f, 100.0f);


    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }

    void pointer(UGWindow uwin, int button, int state, int x, int y)
    {
    exit(0);
    }

    void idle(UGWindow uwin)
    {
    ugPostRedisplay(uwin);
    }

    int main()
    {
    UGCtx ug = ugInit();

    UGWindow uwin = ugCreateWindow(ug, "UG_DEPTH", "bullet", 250, 250, 100, 100);

    init();

    ugDisplayFunc(uwin, display);
    ugReshapeFunc(uwin, reshape);

    ugKeyboardFunc(uwin, keyboard);
    ugPointerFunc(uwin, pointer);

    ugIdleFunc(ug, idle);
    ugMainLoop(ug);

    return 0;
    }

  2. #2
    Junior Member
    Join Date
    May 2005
    Location
    Singapore
    Posts
    23

    Re: what's the problem??

    I am supposed to simulate the trajetory of a bullet respect to time t in 3D space.
    i assume the magnitude of the initial velocity, the angle1 with yz plane and angle2 with xy plane.

    I compiled -->no error or warning;
    but when execute the program, the particle just be static, cannot move.

    why??
    how can i make it move??

    thanks a lot

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    24

    Re: what's the problem??

    The bit of your code which should update the "bullet" position is below:

    Code :
     

    You push the current matrix on the stack, update the matrix with the current translation of your bullet and then you restore (pop) the old matrix back from the stack... all of this without actually doing something while you have the updated matrix. You need to draw your geometry when the matrix contains the translation factor so between the push and pop calls.

    With the above code you always draw with an identity matrix I would assume hence the object does not move.

    K-

  4. #4
    Junior Member
    Join Date
    May 2005
    Location
    Singapore
    Posts
    23

    Re: what's the problem??

    Thank you for your reply..
    yup...that may be one of the problems

    But when i make the following change:
    Code :
     

    the sphere still cannot move....

    [ May 25, 2005: Message edited by: lavendersg ]

  5. #5
    Junior Member
    Join Date
    May 2005
    Location
    Singapore
    Posts
    23

    Re: what's the problem??

    anyone knows why?

    or any solutions??

Posting Permissions

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