Changeset 5292


Ignore:
Timestamp:
May 8, 2008, 3:19:26 PM (16 years ago)
Author:
jack
Message:

anugavis: Some basic camera control and frame stepping.

Location:
anuga_work/development/anugavis
Files:
2 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/development/anugavis/Makefile.am

    r5255 r5292  
    11## Process this file with automake to generate Makefile.in
    22ACLOCAL_AMFLAGS = -I m4
    3 SUBDIRS = m4 src
     3EXTRA_DIST = m4
     4SUBDIRS = src
     5
     6dist-hook:
     7        rm -rf `find $(distdir)/m4 -name .svn`
  • anuga_work/development/anugavis/configure.ac

    r5272 r5292  
    1010# Checks for programs.
    1111AC_PROG_CC
     12AM_PROG_CC_C_O
    1213AC_PROG_RANLIB
    1314
     
    1718AC_SEARCH_LIBS([nc_open], [netcdf], [],
    1819               [AC_MSG_ERROR([Can't link the NetCDF library. (LDFLAGS?)])])
     20AC_SEARCH_LIBS([sqrt], [m], [],
     21               [AC_MSG_ERROR([Can't find sqrt.])])
     22
    1923# Checks for header files.
    2024AC_CHECK_HEADER([netcdf.h], [],
     
    2327# Checks for typedefs, structures, and compiler characteristics.
    2428AC_C_CONST
    25 AM_PROG_CC_C_O
    2629AC_TYPE_SIZE_T
    2730
    2831# Checks for library functions.
    2932AC_FUNC_MALLOC
    30 AC_CHECK_FUNCS([strdup])
     33AC_CHECK_FUNCS([strdup sqrt])
    3134
    3235AC_CONFIG_FILES([Makefile
    33                  m4/Makefile
    3436                 src/Makefile])
    3537AC_OUTPUT
  • anuga_work/development/anugavis/src/Makefile.am

    r5272 r5292  
    33# Convenience library for the core visualiser code.
    44noinst_LIBRARIES = libanugavis.a
    5 libanugavis_a_SOURCES = error.c \
     5libanugavis_a_SOURCES = camera.c \
     6                        camera.h \
     7                        error.c \
    68                        error.h \
    79                        events.c \
  • anuga_work/development/anugavis/src/anugavis_simple.c

    r5271 r5292  
    1414    return 1;
    1515  }
    16   if(AnugaVis_DefineHeightQuantity("elevation", 0, 1, 0.5, 0.5, 0.5) == -1){
    17     printf("AnugaVis_DefineHeightQuantity() Error: %s\n", AnugaVis_GetError());
    18     return 1;
    19   }
    20   if(AnugaVis_DefineHeightQuantity("stage", 0, 1, 0.0, 0.0, 0.5) == -1){
     16/*   if(AnugaVis_DefineHeightQuantity("elevation", 0.0, 1.0, 0.5, 0.5, 0.5) == -1){ */
     17/*     printf("AnugaVis_DefineHeightQuantity() Error: %s\n", AnugaVis_GetError()); */
     18/*     return 1; */
     19/*   } */
     20  if(AnugaVis_DefineHeightQuantity("stage", -0.01, 1.0, 0.0, 0.0, 0.5) == -1){
    2121    printf("AnugaVis_DefineHeightQuantity() Error: %s\n", AnugaVis_GetError());
    2222    return 1;
  • anuga_work/development/anugavis/src/events.c

    r5273 r5292  
    1414#endif
    1515#include <SDL.h>
     16#include "camera.h"
    1617#include "events.h"
    1718#include "globals.h"
     
    1920
    2021int AnugaVis_Step(void){
     22  GLfloat lightpos[4];
     23  int i;
    2124  SDL_Event event;
    2225  int more = 1;
     
    2629  glMatrixMode(GL_MODELVIEW);
    2730  glLoadIdentity();
     31  if(anugavis.keys[KEY_ROTATE_LEFT]) camera_rotate_yaw(CAMERA_DEFAULT_THETA);
     32  if(anugavis.keys[KEY_ROTATE_RIGHT]) camera_rotate_yaw(-CAMERA_DEFAULT_THETA);
    2833  gluLookAt(anugavis.eye[0], anugavis.eye[1], anugavis.eye[2],
    2934            anugavis.focus[0], anugavis.focus[1], anugavis.focus[2],
    3035            0, 0, 1);
     36  for(i = 0 ; i < 3 ; i++) lightpos[i] = anugavis.eye[i];
     37  lightpos[3] = 1.0;
     38  glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
    3139  for(height = anugavis.heights ; height != NULL ; height = height->next)
    3240    AnugaVis_DrawHeightQuantity(height);
     
    3745    case SDL_KEYDOWN:
    3846      switch(event.key.keysym.sym){
     47      case SDLK_b:
     48        if(anugavis.current_frame > 0) anugavis.current_frame--;
     49        break;
     50      case SDLK_f:
     51        if(anugavis.current_frame < anugavis.number_of_timesteps - 1)
     52          anugavis.current_frame++;
     53        break;
    3954      case SDLK_ESCAPE:
    4055        more = 0;
     56        break;
     57      case SDLK_DOWN:
     58        anugavis.eye[2] += 1;
     59        break;
     60      case SDLK_LEFT:
     61        anugavis.keys[KEY_ROTATE_LEFT] = 1;
     62        break;
     63      case SDLK_RIGHT:
     64        anugavis.keys[KEY_ROTATE_RIGHT] = 1;
    4165        break;
    4266      default:
     
    4670    case SDL_KEYUP:
    4771      switch(event.key.keysym.sym){
     72      case SDLK_LEFT:
     73        anugavis.keys[KEY_ROTATE_LEFT] = 0;
     74        break;
     75      case SDLK_RIGHT:
     76        anugavis.keys[KEY_ROTATE_RIGHT] = 0;
     77        break;
    4878      default:
    4979        break;
  • anuga_work/development/anugavis/src/events.h

    r5271 r5292  
    66              KEY_STRAFE_LEFT,
    77              KEY_STRAFE_RIGHT,
     8              KEY_ROTATE_LEFT,
     9              KEY_ROTATE_RIGHT,
    810              KEY_MAX} KEYS;
    911
  • anuga_work/development/anugavis/src/globals.h

    r5271 r5292  
    2626  size_t number_of_volumes;
    2727  size_t number_of_timesteps;
     28  size_t current_frame;
    2829  float *x;
    2930  float *y;
  • anuga_work/development/anugavis/src/height_quantity.c

    r5273 r5292  
    3232  vector v2;
    3333  vector normal;
     34  vector flippedNormal;
     35  vector up = {0.0, 0.0, 1.0};
    3436  float *heights = xmalloc(sizeof(float)
    3537                           * anugavis.number_of_points
     
    5153        vs[vertex][0] = anugavis.x[vertIndex];
    5254        vs[vertex][1] = anugavis.y[vertIndex];
    53         vs[vertex][2] = heights[frame*anugavis.number_of_timesteps + vertIndex];
     55        vs[vertex][2] = heights[frame*anugavis.number_of_points + vertIndex];
    5456      }
    5557      vsub(vs[1], vs[0], v1);
    5658      vsub(vs[2], vs[0], v2);
    5759      vcross(v1, v2, normal);
    58       /* FIXME: Need to ensure that normal is pointing upward. */
    59       glNormal3fv(normal);
     60      if(vdot(normal, up) / vlen(normal) < 0){
     61        vscale(normal, -1.0, flippedNormal);
     62        glNormal3fv(flippedNormal);
     63      }else glNormal3fv(normal);
    6064      for(vertex = 0 ; vertex < anugavis.number_of_vertices ; vertex++){
    6165        vertIndex = anugavis.volumes[vol*anugavis.number_of_vertices + vertex];
    6266        glVertex3f(anugavis.x[vertIndex], anugavis.y[vertIndex],
    63                    heights[frame * anugavis.number_of_timesteps + vertIndex]);
     67                   heights[frame * anugavis.number_of_points + vertIndex]);
    6468      }
    6569      glEnd();
     
    146150void AnugaVis_DrawHeightQuantity(struct height_quantity_simple *height){
    147151  glPushMatrix();
    148   /*  glScalef(0, 0, height->scale);
    149       glTranslatef(0, 0, height->offset);*/
     152  glScalef(1, 1, height->scale);
     153  glTranslatef(0, 0, height->offset);
    150154  glColor3f(height->red, height->green, height->blue);
    151   glCallList(height->displayLists);
     155  glCallList(height->displayLists + (height->frames == 1 ? 0 :
     156                                     anugavis.current_frame));
    152157  glPopMatrix();
    153158}
  • anuga_work/development/anugavis/src/init.c

    r5271 r5292  
    2626int AnugaVis_Init(int width, int height, const char *swwFilePath){
    2727  int ncstatus;
    28   int ncdimid;
    29   int ncvarid;
     28  GLfloat lightAmbient[] = {0.0, 0.0, 0.0, 1.0};
     29  GLfloat lightDiffuse[] = {1.0, 1.0, 1.0, 1.0};
     30  anugavis.current_frame = 0;
    3031  anugavis.x = NULL;
    3132  anugavis.y = NULL;
    3233  anugavis.volumes = NULL;
    3334  /* FIXME derive this from the dataset? */
    34   anugavis.eye[0] = 5.0;
    35   anugavis.eye[1] = 5.0;
    36   anugavis.eye[2] = 20.0;
     35  anugavis.eye[0] = 1.0;
     36  anugavis.eye[1] = 1.0;
     37  anugavis.eye[2] = 40.0;
    3738  anugavis.focus[0] = 0.0;
    3839  anugavis.focus[1] = 0.0;
     
    5960  glMatrixMode(GL_MODELVIEW);
    6061  glLoadIdentity();
    61 
     62  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
     63  glEnable(GL_COLOR_MATERIAL);
     64  glEnable(GL_LIGHTING);
     65  glEnable(GL_LIGHT0);
     66  glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
     67  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
     68 
    6269  if((ncstatus = nc_open(swwFilePath, NC_SHARE,
    6370                         &anugavis.netcdfId)) != NC_NOERR){
  • anuga_work/development/anugavis/src/vector.c

    r5272 r5292  
    66}
    77
     8void vscale(vector v, float scale, vector result){
     9  int i;
     10  for(i = 0 ; i < 3 ; i++) result[i] = scale * v[i];
     11}
     12
    813void vsub(vector v1, vector v2, vector result){
    914  int i;
     
    1116}
    1217
    13 void vnormalise(vector v, vector result){
    14   float len = vlen(v);
     18float vdot(vector v1, vector v2){
    1519  int i;
    16   for(i = 0 ; i < 3 ; i++) result[i] = v[i] / len;
     20  float rv = 0;
     21  for(i = 0 ; i < 3 ; i++) rv += v1[i] * v2[i];
     22  return rv;
    1723}
    1824
  • anuga_work/development/anugavis/src/vector.h

    r5272 r5292  
    55/* Useful vector operations. */
    66float vlen(vector v);
     7void vscale(vector v, float scale, vector result);
    78void vsub(vector v1, vector v2, vector result);
    8 void vnormalise(vector v, vector result);
     9float vdot(vector v1, vector v2);
    910void vcross(vector v1, vector v2, vector result);
    1011
Note: See TracChangeset for help on using the changeset viewer.