Page 1 of 4 1234 LastLast
Results 1 to 10 of 35

Thread: The most difficut problem in OPENGL! (Try it)

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    L.A
    Posts
    4

    The most difficut problem in OPENGL! (Try it)

    To make a triangle move on the middle of a window horizontally (not back and forth) and the triangle should slowly disappear on one side and appear on other side slowly. (My prof claim no one can slove this problem, but who knows, maybe u guys are genius, try to solve this problem for me, thanks in advance!)
    I am a black sheep in my family

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: The most difficut problem in OPENGL! (Try it)

    Is this some kind of trick question, or did i misunderstand it?
    Code :
    #include <GL/glut.h>
     
    // --------------------------------------------------------------------------------
    // 
    // --------------------------------------------------------------------------------
    int viewportHeight;
    int viewportWidth;
     
    int trianglePos = 0;
    int triangleSize = 120;
     
    // --------------------------------------------------------------------------------
    // 
    // --------------------------------------------------------------------------------
    void display(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT);
     
    	glLoadIdentity();
    	glTranslatef(trianglePos, 0, 0);
    	glBegin(GL_TRIANGLES);
    	{
    		glVertex2i(0,                viewportHeight / 2);
    		glVertex2i(triangleSize / 2, viewportHeight / 2 + triangleSize);
    		glVertex2i(triangleSize,     viewportHeight / 2);
    	}
    	glEnd();
     
    	glTranslatef(-viewportWidth, 0, 0);
    	glBegin(GL_TRIANGLES);
    	{
    		glVertex2i(0,                viewportHeight / 2);
    		glVertex2i(triangleSize / 2, viewportHeight / 2 + triangleSize);
    		glVertex2i(triangleSize,     viewportHeight / 2);
    	}
    	glEnd();
     
    	glutSwapBuffers();
    }
     
    void reshape(int w, int h)
    {
    	viewportWidth = w;
    	viewportHeight = h;
     
    	glViewport(0, 0, w, h);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho(0, w, 0, h, -1, 1);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    }
     
    void idle(void)
    {
    	++trianglePos;
    	if(trianglePos > viewportWidth) trianglePos = 0;
     
    	glutPostRedisplay();
    }
     
    int main(int argc, char **argv)
    {
    	glutInit(&amp;argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    	glutCreateWindow("scrolling triangle");
     
    	glutDisplayFunc(display);
    	glutReshapeFunc(reshape);
    	glutIdleFunc(idle);
     
    	glutMainLoop();
     
    	return 0;
    }

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    184

    Re: The most difficut problem in OPENGL! (Try it)

    yea...that doesn't seem too hard. unless you want something like this:
    Code :
    +----------------------+
    |                      |
    | /\                   |
    |/  \                  |
    |    \                /|
    |     \              / |
    |______\            /__|
    |                      |
    +----------------------+
    in this case, you'd need to check the position of each vertex of the triangle, and draw the lines separately.

    b

  4. #4
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: The most difficut problem in OPENGL! (Try it)

    Or draw two triangles when the bounds approaches the edge.

    Either the question isn't phrased correctly or your professor is a moron.

    I doubt you'd find a professor quite this dumb so maybe you should try and solve your exercise questions before posting and making your prof. sound like an idiot.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: The most difficut problem in OPENGL! (Try it)

    Or are you insinuating some sort of circular viewing plane?

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    L.A
    Posts
    4

    Re: The most difficut problem in OPENGL! (Try it)

    coredump, u got the point!exactly same as what i mean! the diffculty is how to do. what u siad si correct in theory, but how to put in code is big problem since i am still blur in OpenGL. Anyway, thanks for ur reply!
    I am a black sheep in my family

  7. #7
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    184

    Re: The most difficut problem in OPENGL! (Try it)

    the easiest way would be to do what dorbie suggested...when the triangle passes the right edge of the window, draw a second triangle coming in from the left side. when the triangle on the right is all the way past the window's edge, then just draw the second triangle. simple!

    b

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: The most difficut problem in OPENGL! (Try it)

    That is more of an emulation of a simple triangle case. The algrithm for n cases is a bit different, but by no means impossible. The idea of wrapping is the way to go rather than trying t odo a 'real' circular viewing plane. Althought thinking about it a circular plane should nt be too difficult.

  9. #9
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: The most difficut problem in OPENGL! (Try it)

    An emulation? Give me a break. Now you're changing the rules. Talk about contriving to define a problem that doesn't exist. Any problem is tough if you tie someone's hands and exclude options after a trivial solution is presented. It's not an emulation. I could say most clipping hardware built is an emulation based on this kind of definition.

    Go rasterize on a torroidal framebuffer with a guard band clip (that's the other simple solution) if you like. I'll stick with my first idea, it works on hardware. It's funny that this is posed as if it's a 'grand challenge' it's not, almost nobody wants to render like this, maybe someone writing an asteroids game, but that's about it.

    Aha, you are writing an asteroids game aren't you. And you asked old prof a question he couldn't answer. This is almost funny now.


    [This message has been edited by dorbie (edited 06-17-2002).]

  10. #10
    Member Contributor
    Join Date
    Mar 2002
    Posts
    65

    Re: The most difficut problem in OPENGL! (Try it)

    you are looking for 360 degree fov baby!
    render into four side by side viewports with x fov 90 degrees and rotating the scene 90 degree in each viewport

Page 1 of 4 1234 LastLast

Similar Threads

  1. OpenGL Problem
    By pczone in forum OpenGL ES
    Replies: 1
    Last Post: 06-05-2009, 09:22 AM
  2. Replies: 4
    Last Post: 09-27-2004, 06:27 AM
  3. opengl problem
    By c0mputar in forum OpenGL: User Software
    Replies: 1
    Last Post: 01-09-2004, 05:15 AM
  4. Replies: 1
    Last Post: 01-19-2003, 10:26 AM
  5. Big problem with OpenGL
    By in forum OpenGL: User Software
    Replies: 4
    Last Post: 08-09-2002, 02:08 AM

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