Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://cg.iit.bme.hu/portal/oktatott-targyak/szamitogepes-grafika-es-kepfeldolgozas/2d-grafikus-rendszerek
- // http://cg.iit.bme.hu/portal/sites/default/files/oktatott-targyak/szamitogepes-grafika-es-kepfeldolgozas/2d-grafikus-rendszerek/bme2dsysr.ppt
- // 12. diától 21. diáig részletek
- Window window;
- int appWinHeight, appWinWidth;
- // ...
- void MouseDown(int button, int state, int x, int y) {
- if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
- window.MouseLD(x, appWinHeight - y); // Windows kr.
- glutPostRedisplay();
- }
- // ...
- struct Window {
- Scene scene;
- // ...
- void MouseLD(int X, int Y) {
- // ...
- scene.InputPipe(X, Y);
- // ...
- }
- }
- class Camera {
- Rect viewport, window;
- void SetGL() {
- glViewport(viewport.left, viewport.bottom,
- viewport.width, viewport.height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(window.left, window.left + window.width,
- window.bottom, window.bottom + window.height);
- }
- Vector Inverse(Vector scrPos) {
- float sx = window.width / viewport.width;
- float sy = window.height / viewport.height;
- return Vector(
- (scrPos.x – viewport.left) * sx + window.left,
- (scrPos.y – viewport.bottom) * sy + window.bottom
- );
- }
- };
- class Scene {
- // ...
- Camera camera;
- // ...
- void InputPipe(int X, int Y) {
- Vector wPos = camera.Inverse(Vector(X, Y));
- // ...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement