Advertisement

Moving along the screen and zooming

Started by March 10, 2003 04:12 PM
0 comments, last by Xiachunyi 21 years, 11 months ago
Hello everyone, I am deeply sorry if anyone has asked this before but here goes: I''ve been working on NeHe''s tutorials, very good by the way, and have been doing some implementation. I was wondering how do you make the object, cube with the texture, move across the screen and zoom in without small stops. I''ve tried my own "dirty" coding but I want a smoother transistion effect. Here is the code I''ve implemented:

.................................................................
int count=0, change=0;
//count     = How many cycles have passed
//change    = Image sector count
.................................................................
//THIS IS UNDER "int DrawGLScene()"
.................................................................	
    glTranslatef(-2.0f,0.0f,-5.0f);	
    if(change == 1)
	{
	   glLoadIdentity();	
	   glTranslatef(-1.7f,0.0f,-5.0f);	
	}
	if(change == 2)
	{
	   glLoadIdentity();	
	   glTranslatef(-1.3f,0.0f,-5.0f);	
	}
    if(change == 3)
	{
	   glLoadIdentity();	
	   glTranslatef(-1.0f,0.0f,-5.0f);	
	}
.................................................................
//THIS IS UNDER "int WINAPI WinMain" && while(!done)
.................................................................
				SwapBuffers(hDC);					// Swap Buffers (Double Buffering)
				count++;
                if(count == 250)
				{
				    change=1;
				    InitGL();
                }
                else if(count == 350)
                {
				    change=2;
				    InitGL();                
                }
                else if(count == 450)
                {
				    change=3;
				    InitGL();                
                }
                else if(count == 550)
                {
				    change=4;
				    InitGL();                
                }
                else if(count == 650)
                {
				    change=5;
				    InitGL();                
                }   
 
Do I have to double buffer the object before it is moved to create a "blur" effect? Sample code snippet would be nice too. Thankyou very much in advance.
Unless I am misuderstanding what you are trying to do, that is way too much code.

First of all, dont call InitGl more than once.

next do something like this in your DrawGLScene:


  count++;glLoadIdentity();		   glTranslatef(count*-0.1f,0.0f,-5.0f);  

then draw the cube

I''m not sure what you are doing, but this should make the cube move across the screen.

As far as double buffering, NeHe''s tuts already do that for you so you shouldn''t worry about it.

This topic is closed to new replies.

Advertisement