source: anuga_work/development/anugavis/src/camera.c @ 5379

Last change on this file since 5379 was 5379, checked in by jack, 16 years ago

Got camera zoom working.

File size: 2.4 KB
Line 
1#ifdef HAVE_CONFIG_H
2#  include "config.h"
3#endif
4
5#ifdef HAVE_GL_GL_H
6#  include <GL/gl.h>
7#elif HAVE_OPENGL_GL_H
8#  include <OpenGL/gl.h>
9#endif
10#include <math.h>
11#include "camera.h"
12#include "globals.h"
13#include "vector.h"
14
15static const vector up = {0.0, 0.0, 1.0};
16#include <stdio.h>
17void camera_pitch(float theta){
18  float c = cos(theta);
19  float s = sin(theta);
20  float x;
21  float y;
22  float z;
23  vector releye;
24  vector newreleye;
25  vector axis;
26  float dot;
27  float len;
28  vsub(anugavis.eye, anugavis.focus, releye);
29  /* Check we're not too near the vertical */
30  dot = vdot(up, releye); len = vlen(releye);
31  if(((dot > 0.99 * len) && (theta > 0)) ||
32     ((dot < -0.99 * len) && (theta < 0))) return;
33  /* Calculation from glRotatef manpage. */
34  vcross(releye, up, axis);
35  vscale(axis, 1.0/vlen(axis), axis);
36  x = axis[0]; y = axis[1]; z = axis[2];
37  newreleye[0] =
38    releye[0] * (x*x*(1-c)+c) +
39    releye[1] * (x*y*(1-c)-z*s) +
40    releye[2] * (x*z*(1-c)+y*s);
41  newreleye[1] =
42    releye[0] * (y*x*(1-c)+z*s) +
43    releye[1] * (y*y*(1-c)+c) +
44    releye[2] * (y*z*(1-c)-x*s);
45  newreleye[2] =
46    releye[0] * (z*x*(1-c)-y*s) +
47    releye[1] * (z*y*(1-c)+x*s) +
48    releye[2] * (z*z*(1-c)+c);
49  vadd(newreleye, anugavis.focus, anugavis.eye);
50}
51
52void camera_yaw(float theta){
53  float c = cos(theta);
54  float s = sin(theta);
55  vector releye;
56  vector newreleye;
57  vsub(anugavis.eye, anugavis.focus, releye);
58  newreleye[0] = releye[0] * c + releye[1] * s;
59  newreleye[1] = releye[0] * -1 * s + releye[1] * c;
60  newreleye[2] = releye[2];
61  vadd(newreleye, anugavis.focus, anugavis.eye);
62}
63
64void camera_track(float dist){
65  vector dir = {0, 0, 0};
66  vsub(anugavis.eye, anugavis.focus, dir);
67  dir[2] = 0;
68  vscale(dir, dist/vlen(dir), dir);
69  vadd(anugavis.eye, dir, anugavis.eye);
70  vadd(anugavis.focus, dir, anugavis.focus);
71}
72
73void camera_strafe(float dist){
74  vector releye;
75  vector dir;
76  vsub(anugavis.eye, anugavis.focus, releye);
77  vcross(releye, up, dir);
78  vscale(dir, dist/vlen(dir), dir);
79  vadd(anugavis.eye, dir, anugavis.eye);
80  vadd(anugavis.focus, dir, anugavis.focus);
81}
82
83void camera_zoom(float dist){
84  vector releye;
85  float len;
86  vsub(anugavis.focus, anugavis.eye, releye);
87  if((len = vlen(releye)) < dist) return;
88  vscale(releye, dist/len, releye);
89  vadd(anugavis.eye, releye, anugavis.eye);
90}
Note: See TracBrowser for help on using the repository browser.