PDA

View Full Version : Moving without user input



TolTol
11-09-2002, 04:43 AM
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!!! http://www.opengl.org/discussion_boards/ubb/eek.gif

Any suggestions??

Cheers http://www.opengl.org/discussion_boards/ubb/smile.gif

mikael_aronsson
11-09-2002, 04:46 AM
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

nexusone
11-09-2002, 05:04 AM
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:
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!!! http://www.opengl.org/discussion_boards/ubb/eek.gif

Any suggestions??

Cheers http://www.opengl.org/discussion_boards/ubb/smile.gif

TolTol
11-09-2002, 05:05 AM
Sorry mate. Its win32.... I think http://www.opengl.org/discussion_boards/ubb/confused.gif

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

mm_freak
11-10-2002, 10:04 AM
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()?

TolTol
11-11-2002, 08:40 AM
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 http://www.opengl.org/discussion_boards/ubb/eek.gif

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

jebus
11-11-2002, 09:53 AM
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).]

147-2
11-12-2002, 12:51 PM
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.