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!)

Is this some kind of trick question, or did i misunderstand it?

#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(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutCreateWindow(“scrolling triangle”);

glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);

glutMainLoop();

return 0;
}

yea…that doesn’t seem too hard. unless you want something like this:

±---------------------+
| |
| /\ |
|/ \ |
| \ /|
| \ / |
|____\ /|
| |
±---------------------+

in this case, you’d need to check the position of each vertex of the triangle, and draw the lines separately.

b

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.

Or are you insinuating some sort of circular viewing plane?

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!

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

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.

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).]

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

Hmm… well if that’s what you need, I didn’t see it in the question but you’ve opened my eyes. It is possible. The polygon would actually be rotating.

It can be done, here’s how:
http://patft.uspto .gov/netacgi/nph-Pars…orbie&RS=dorbie

tarantula, your suggestion would have discontinuities, you need to distortion correct the individual projections.

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

Come on guys,I’m only able to scratch the surface of OpenGL.pls dun play the lip service for me, i have to submit it on firday, it’s not a breezy tp put thise idea in code. My prof. is always yelling at me, “hi, when r u going ot pass up the assignment?”!

Yawn, yawn dorbie

Sounds like a good problem to me. It’s obviously not useful for 1 triangle, but for any set of primitives. And the beauty would be to solve the problem by having the same triangle, not two diff. triangles drawn. Tarantula’s got the right idea with his suggestion. So rather than translating the triangle or whatever model, you’d rotate it around the camera.

What’s so damn hard about it?

Render in ortho, use two triangles.

The question hasn’t been completely expressed. It’s still ambiguous. I have used the algorithm described on the link I gave for spherical dome displays but it is sufficiently general for a cylindrical mapping. As I have said the distortion correction must be solved for the general case (if that’s even the question being posed). The simple double triangle solution also solves for the special case apparently posed in the question.

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

Yea Syslock, I guess that’s just too boring around here :slight_smile: Even in perspective it can be done by separating the copy as a function of depth. It seems clear rereading the posts that Kinicky is asking about the trivial case.

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

BTW, is this one of those SGI patents bought by Microsoft few months ago, Angus?

Yes, I have never worked for Microsoft and I filed this patent when I worked at SGI. This patent is one of several assigned to Microsoft that I know of and I’m sure it’s the tip of the iceberg. I couldn’t mention it at the time but now the information is clearly in the public domain.

Be careful what you file, one day you may wake up and discover that your work is owned by the large predatory monopolist you filed to help your employer survive against.

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

Another approach (don’t know how useful it is because of possible texture size limitations) to fake/emulate/draw in the required way could be:

  1. render the triangle to a (large) texture that approximates the screen size
  2. set up the texture to be transparent in areas outside the triangle
  3. set up the texture to repeat in s and t
  4. draw a quad/tristrip to the screen with the texture, varying the texture coordinates in such a way that the triangle moves in the required direction.

Make sure the quad/tristrip covers the screen completely and also make sure sMax - sMin == 1 and tMax - tMin == 1.

HTH

Jean-Marc.