4 Replies - 5193 Views - Last Post: 23 February 2009 - 10:19 PM Rate Topic: -----

#1 Zorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-February 09

Opengl Timer Problem

Posted 22 February 2009 - 03:38 PM

Ok so I'm using Opengl and glut and all that good stuff, but I'm going to go insane trying to get this to work.

I have A Quad and I want to transform it to the left by 1.
But rather then just adding -1 to it's x position I want it move smoothly from where it is to where it's going.

So I figured I'd move it by -0.1 and wait some, 10 times like this.

  void MoveQuad (int i ){
	  
	   QuadsXPosition -= 0.1;
	   glutPostRedisplay();
  }


	 for(int i = 0; i < 10; i++)
		 glutTimerFunc(50, MoveQuad, 0);




But instead of moving smoothly it just waits half a second and moves 1 to
the left.

if anybody could help that would be awsome.

This post has been edited by Zorn: 22 February 2009 - 05:55 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Opengl Timer Problem

#2 Space_Bee  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 22-February 09

Re: Opengl Timer Problem

Posted 23 February 2009 - 12:18 AM

taking a rough guess i'd just change the value to 0.05 or try a lower value?

taking a more thought out approach:

 
// I'm going to assume ur using this (X is a global variable)
glTranslatef(X, 0, 0.0); 

// The speed to move at
Xpos = 0.05;

// simple condition to start it, you can just use what u did with a method call
if( X > -1)
{
	 X -= Xpos;
}
//or this
void moveQuad()
{
	 X -= Xpos;
}



This might work.
Was This Post Helpful? 0
  • +
  • -

#3 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: Opengl Timer Problem

Posted 23 February 2009 - 07:06 AM

This isn't really how you want to do things with OpenGL because I'm guessing glutTimerFunc(..) blocks until its time is up.

My suggestion is to have a display/render function registered with glutDisplayFunc(..), and then an update/logic function for things like movement registered with glutIdleFunc(..).

This post has been edited by Tom9729: 23 February 2009 - 07:09 AM

Was This Post Helpful? 0
  • +
  • -

#4 Lillefix  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 37
  • View blog
  • Posts: 204
  • Joined: 19-September 08

Re: Opengl Timer Problem

Posted 23 February 2009 - 11:21 AM

My guess would be that your position variables are ints rather than floats. This is hard to determine without the complete code though.
Was This Post Helpful? 0
  • +
  • -

#5 Zorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-February 09

Re: Opengl Timer Problem

Posted 23 February 2009 - 10:19 PM

Quote

This isn't really how you want to do things with OpenGL because I'm guessing glutTimerFunc(..) blocks until its time is up.

What do you mean by block. You mean like stops the program till glutTimerFunc gets called.

Anyways I got it to work like this

void Left (int i){
	
	i++;
	if(i == 11)
	return;
	QuadsXPosition -= 0.1;
	glutPostRedisplay();
	glutTimerFunc(50, Left, i);
		
	
} 




I just call that and it moves smoothly to the left.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1