Moving without user input

Hello,

I am trying to create a Flight Simulator and I am currently using the glLookat function to move the plane when the user presses a button. But I need to move the plane without the user pressing a button. Is there some looping construct that will keep iterating the glLookat function? Have tried a for loop but as you can guess the program just freezed!!!

Any suggestions??

Cheers

Hi !

Short answer. Yes !

But it all depends on what you are using, it would be nice if you could give some info on what you are using for your application development, is it Win32, GLUT, SDL or something else, because they all do it in different ways.

Mikael

I see this all the time with new programmers, you should try to structure your program and not put everything inside the display routine.

example of the structure not complete code:

display()
{
locate_camera();
draw_scene(scene_data)
draw_plane(plane_position_data)
}

control_loop() // this will be called repeatitly, with something like glutIdleFunc, or a timer event.
{
process_keyboard_input();
update_plane_position_data();
check_for_collision();
update_display();
}

Originally posted by TolTol:
[b]Hello,

I am trying to create a Flight Simulator and I am currently using the glLookat function to move the plane when the user presses a button. But I need to move the plane without the user pressing a button. Is there some looping construct that will keep iterating the glLookat function? Have tried a for loop but as you can guess the program just freezed!!!

Any suggestions??

Cheers [/b]

Sorry mate. Its win32… I think

I’m using Borland C++. If thats any help.

Yes, you should structure your program as nexusone said. You can, for example, move your plane by timers or event objects.

Do you register and create your windows yourself or do you just use a simple function like glutCreateWindow()?

I create the windows myself but I’m getting trouble using the glut functions. All the functions I created myself have the form:

void TForm1:: myKeyboard(){
}

When I call a fuction like glutKeyboardFunc(myKeyboard) it gives me a type mismatch error. If I just create myKeyboard like:

void myKeyboard(){
}

I get another error to say that the function doesn’t exist in the form

Cant figure out how to get around this. Any help would be very appreciated.

[This message has been edited by TolTol (edited 11-11-2002).]

if you are trying to use a class member function as a GLUT callback, you must make the member function static. i.e.

class Foo
{
public:
static void display();

};

void main()
{

glutDisplayFunc(Foo::display);

}

jebus

[This message has been edited by jebus (edited 11-11-2002).]

Yeah, the func either needs to be in a class and static, or global. This is because the C++ compiler takes your TForm::myKeyboard() and changes it into myKeyboard(TForm&). Also, doesnt the GLUT callback function require some arguments? I am about sure that if you have the appropriate arguments in that function, it would work. I just dug em up for you… Your func should be of the form

myKeyboard(unsigned int key, int x, int y)

where x and y are the current cursor (mouse) position.