I'm currently taking a Computer Graphics class at university, and have been given an assignment which involves loading an obj file and manipulating it with keyboard and mouse controls (eg. arrow keys translate, mouse wheel for zoom, hold mouse and drag for rotation).
Being new to OpenGL, I'm a bit overwhelmed by the project on hand, and would really appreciate if anyone could give me some tips regarding implementation of this project. Our previous (and first) project involved creating a clock based on system time, which was relatively straightforward, using simple rotation/translation techniques on OpenGL primitive objects created within the draw() function. I was able to easily figure out and understand this.
The main questions I have are:
Within the draw() function, how do I take the changes made by the keyboard/mouse and apply them to the object? More specifically, what exactly should be going on here in relation to the input methods?
void Draw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer // Write your own code below (Hint:Translation Rotation & Scaling) // Write your own code above if (obj_data != NULL) obj_data->Draw(); else glutSolidTeapot(1.0); //draw a teapot when no argument is provided glFlush(); glutSwapBuffers(); // Write your own code below (Hint:reset translate and scale value) // Write your own code above
}
How does the mouseMotion() method work? More specifically, how might I go about getting the coordinates of the mouse location and use them within the program?
void mouseMotion(int x, int y) { //code here glutPostRedisplay(); }
I know this may be a vague and/or ambiguous question, but I really do not know where to start on this. My professor has not given much information as to how to implement this, and any pointers or tips that may guide me in the right direction would be incredibly appreciated!
Just so you know, I'm not posting this here for an easy answer so I can copy/paste. I'm mainly looking for a greater understanding of how OpenGL works, especially in relation to user input!
PS: The full source code for the project can be found here. There is also an objLoader.cpp file as well used to load a predrawn object into the workspace.
Let me know if more clarification is required. I've tried my best to consolidate this into smaller questions that might help me understand the project as a whole.
Thanks again!