Ignore:
Timestamp:
Nov 13, 2008 3:24:00 PM (16 years ago)
Author:
gah
Message:

changes to allow panning and zooming (via scrollwhell)

Location:
trunk/packages/vizservers
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/Command.cpp

    r1194 r1215  
    694694
    695695static int
    696 CameraAimOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    697 {
    698     double x0, y0, z0;
    699     if ((Tcl_GetDoubleFromObj(interp, objv[2], &x0) != TCL_OK) ||
    700         (Tcl_GetDoubleFromObj(interp, objv[3], &y0) != TCL_OK) ||
    701         (Tcl_GetDoubleFromObj(interp, objv[4], &z0) != TCL_OK)) {
    702         return TCL_ERROR;
    703     }
    704     NanoVis::cam->aim(x0, y0, z0);
    705     return TCL_OK;
    706 }
    707 
    708 static int
    709 CameraAngleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    710 {
    711     double xangle, yangle, zangle;
    712     if ((Tcl_GetDoubleFromObj(interp, objv[2], &xangle) != TCL_OK) ||
    713         (Tcl_GetDoubleFromObj(interp, objv[3], &yangle) != TCL_OK) ||
    714         (Tcl_GetDoubleFromObj(interp, objv[4], &zangle) != TCL_OK)) {
    715         return TCL_ERROR;
    716     }
    717     NanoVis::cam->rotate(xangle, yangle, zangle);
    718     return TCL_OK;
    719 }
     696CameraPanOp(ClientData cdata, Tcl_Interp *interp, int objc,
     697             Tcl_Obj *const *objv)
     698{
     699    double dx, dy, dz;
     700    if ((Tcl_GetDoubleFromObj(interp, objv[2], &dx) != TCL_OK) ||
     701        (Tcl_GetDoubleFromObj(interp, objv[3], &dy) != TCL_OK) ||
     702        (Tcl_GetDoubleFromObj(interp, objv[4], &dz) != TCL_OK)) {
     703        return TCL_ERROR;
     704    }
     705    NanoVis::cam->aim(dx, dy, dz);
     706    NanoVis::cam->x(dx);
     707    NanoVis::cam->y(dy);
     708    NanoVis::cam->z(dz);
     709    return TCL_OK;
     710}
     711
     712static int
     713CameraAimOp(ClientData cdata, Tcl_Interp *interp, int objc,
     714            Tcl_Obj *const *objv)
     715{
     716    double x, y, z;
     717    if ((Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK) ||
     718        (Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK) ||
     719        (Tcl_GetDoubleFromObj(interp, objv[4], &z) != TCL_OK)) {
     720        return TCL_ERROR;
     721    }
     722    NanoVis::cam->aim(x, y, z);
     723    return TCL_OK;
     724}
     725
     726static int
     727CameraAngleOp(ClientData cdata, Tcl_Interp *interp, int objc,
     728              Tcl_Obj *const *objv)
     729{
     730    double theta, phi, psi;
     731    if ((Tcl_GetDoubleFromObj(interp, objv[2], &phi) != TCL_OK) ||
     732        (Tcl_GetDoubleFromObj(interp, objv[3], &theta) != TCL_OK) ||
     733        (Tcl_GetDoubleFromObj(interp, objv[4], &psi) != TCL_OK)) {
     734        return TCL_ERROR;
     735    }
     736    NanoVis::cam->rotate(phi, theta, psi);
     737    return TCL_OK;
     738}
     739
    720740
    721741static int
     
    726746        return TCL_ERROR;
    727747    }
    728     NanoVis::zoom(zoom);
     748    NanoVis::cam->z(-2.5 / zoom);
    729749    return TCL_OK;
    730750}
     
    733753    {"aim",     2, CameraAimOp,      5, 5, "x y z",},
    734754    {"angle",   2, CameraAngleOp,    5, 5, "xAngle yAngle zAngle",},
     755    {"pan",     1, CameraPanOp,      5, 5, "x y z",},
    735756    {"zoom",    1, CameraZoomOp,     3, 3, "factor",},
    736757};
     
    21282149
    21292150    // the variables below should be reassigned
    2130     int heightmap_index = 0;
    21312151    int image_width = 512;
    21322152    int image_height = 512;
  • trunk/packages/vizservers/nanovis/NvCamera.cpp

    r953 r1215  
    2020
    2121NvCamera::NvCamera(int startx, int starty, int w, int h,
    22                    double loc_x, double loc_y, double loc_z,
    23                    double target_x, double target_y, double target_z,
    24                    int angle_x, int angle_y, int angle_z):
    25     location(Vector3(loc_x, loc_y, loc_z)),
    26     target(Vector3(target_x, target_y, target_z)),
    27     angle(Vector3(angle_x, angle_y, angle_z)),
    28     width(w),
    29     height(h),
    30     startX(startx),
    31     startY(starty)
     22                   float loc_x, float loc_y, float loc_z,
     23                   float target_x, float target_y, float target_z,
     24                   float angle_x, float angle_y, float angle_z):
     25    location_(Vector3(loc_x, loc_y, loc_z)),
     26    target_(Vector3(target_x, target_y, target_z)),
     27    angle_(Vector3(angle_x, angle_y, angle_z)),
     28    width_(w),
     29    height_(h),
     30    startX_(startx),
     31    startY_(starty)
    3232{
    3333    /*empty*/
    3434}
    3535
    36 NvCamera::~NvCamera()
    37 {
    38     /*empty*/
    39 }       
    40 
    41 void
    42 NvCamera::move(double loc_x, double loc_y, double loc_z)
    43 {
    44     location = Vector3(loc_x, loc_y, loc_z);
    45 }
    46 
    47 void
    48 NvCamera::aim(double target_x, double target_y, double target_z)
    49 {
    50     target = Vector3(target_x, target_y, target_z);
    51 }
    52 
    53 void
    54 NvCamera::rotate(double angle_x, double angle_y, double angle_z)
    55 {
    56     angle = Vector3(angle_x, angle_y, angle_z);
    57 }
    5836
    5937void
     
    6139{
    6240    //fprintf(stderr, "camera: %d, %d\n", width, height);
    63     glViewport(startX, startY, width, height);
     41    glViewport(startX_, startY_, width_, height_);
    6442    glMatrixMode(GL_PROJECTION);
    6543    glLoadIdentity();
    66     gluPerspective(30, (GLdouble)(width - startX)/(GLdouble)(height - startY),
    67         0.1, 50.0);
     44    gluPerspective(30,
     45                   (GLdouble)(width_ - startX_)/(GLdouble)(height_ - startY_),
     46                   0.1, 50.0);
    6847
    6948    glMatrixMode(GL_MODELVIEW);
    7049    glLoadIdentity();
    7150
    72     gluLookAt(location.x, location.y, location.z,
    73               target.x, target.y, target.z,
     51    gluLookAt(location_.x, location_.y, location_.z,
     52              target_.x, target_.y, target_.z,
    7453              0., 1., 0.);
    7554
    76     glRotated(angle.x, 1., 0., 0.);
    77     glRotated(angle.y, 0., 1., 0.);
    78     glRotated(angle.z, 0., 0., 1.);
     55    glRotated(angle_.x, 1., 0., 0.);
     56    glRotated(angle_.y, 0., 1., 0.);
     57    glRotated(angle_.z, 0., 0., 1.);
    7958}
    8059
    81 void
    82 NvCamera::set_screen_size(int sx, int sy, int w, int h)
    83 {
    84     width = w, height = h;
    85     startX = sx, startY = sy;
    86 }
  • trunk/packages/vizservers/nanovis/NvCamera.h

    r953 r1215  
    2222class NvCamera {
    2323
    24 public:
    25     Vector3 location;           //Location of the camera in the scene
    26     Vector3 target;             //Location the camera is looking at. 
     24    Vector3 location_;          //Location of the camera in the scene
     25    Vector3 target_;            //Location the camera is looking at. 
    2726                                //location and target: two points define the
    2827                                //line-of-sight
    29     Vector3 angle;              //rotation angles of camera along x, y, z
    30     int width;                  //screen size
    31     int height;                 //screen size
    32     int startX;
    33     int startY;
     28    Vector3 angle_;             //rotation angles of camera along x, y, z
     29    int width_;                 //screen width
     30    int height_;                //screen height
     31    int startX_;
     32    int startY_;
    3433
    35     ~NvCamera();
     34public:
     35    ~NvCamera(void) {
     36        /*empty*/
     37    }   
    3638    NvCamera(int startx, int starty, int w, int h,
    37              double loc_x, double loc_y, double loc_z,
    38              double target_x, double target_y, double target_z,
    39              int angle_x, int angle_y, int angle_z);
    40     void move(double loc_x, double loc_y, double loc_z); //move location of camera
    41     void aim(double target_x, double target_y, double target_z); //change target point
    42     void rotate(double angle_x, double angle_y, double angle_z); //change target point
    43     void activate(); //make the camera setting active, this has to be called
    44                      //before drawing things.
    45     void set_screen_size(int startx, int starty, int w, int h);
     39             float loc_x, float loc_y, float loc_z,
     40             float target_x, float target_y, float target_z,
     41             float angle_x, float angle_y, float angle_z);
     42
     43    //move location of camera
     44    void x(double loc_x) {
     45        location_.x = loc_x;
     46    }
     47    float x(void) {
     48        return location_.x;
     49    }
     50    void y(double loc_y) {
     51        location_.y = loc_y;
     52    }
     53    float y(void) {
     54        return location_.y;
     55    }
     56    void z(double loc_z) {
     57        location_.z = loc_z;
     58    }
     59    float z(void) {
     60        return location_.z;
     61    }
     62
     63    void aim(double target_x, double target_y, double target_z) {
     64        target_ = Vector3(target_x, target_y, target_z);
     65    }
     66    Vector3 aim(void) {
     67        return target_;
     68    }
     69    void rotate(double angle_x, double angle_y, double angle_z) {
     70        angle_ = Vector3(angle_x, angle_y, angle_z);
     71    }
     72    void rotate(Vector3 angle) {
     73        angle_ = angle;
     74    }
     75    Vector3 rotate(void) {
     76        return angle_;
     77    }
     78    void set_screen_size(int sx, int sy, int w, int h) {
     79        width_ = w, height_ = h;
     80        startX_ = sx, startY_ = sy;
     81    }
     82    void activate(void); //make the camera setting active, this has to be
     83                         //called before drawing things.
    4684};
    4785
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r1211 r1215  
    171171
    172172// Object rotation angles
    173 static float live_rot_x = 90.;
    174 static float live_rot_y = 180.;
    175 static float live_rot_z = -135;
     173const float def_rot_x = 90.;
     174const float def_rot_y = 180.;
     175const float def_rot_z = -135;
    176176
    177177// Object translation location from the origin
    178 static float live_obj_x = -0.0;
    179 static float live_obj_y = -0.0;
    180 static float live_obj_z = -2.5;
     178const float def_obj_x = -0.0;
     179const float def_obj_y = -0.0;
     180const float def_obj_z = -2.5;
    181181
    182182
     
    507507    }
    508508    return tf;
    509 }
    510 
    511 void
    512 NanoVis::zoom(double zoom)
    513 {
    514     live_obj_z = -2.5 / zoom;
    515     cam->move(live_obj_x, live_obj_y, live_obj_z);
    516509}
    517510
     
    884877   //create the camera with default setting
    885878   cam = new NvCamera(0, 0, win_width, win_height,
    886                    live_obj_x, live_obj_y, live_obj_z,
    887                    0., 0., 100.,
    888                    (int)live_rot_x, (int)live_rot_y, (int)live_rot_z);
     879                      def_obj_x, def_obj_y, def_obj_z,
     880                      0., 0., 100.,
     881                      def_rot_x, def_rot_y, def_rot_z);
    889882
    890883   glEnable(GL_TEXTURE_2D);
     
    13361329        float y = vert[3*i+1];
    13371330        float z = vert[3*i+2];
    1338 
    1339         float dis = (x-live_obj_x)*(x-live_obj_x) + (y-live_obj_y)*(y-live_obj_y) + (z-live_obj_z)*(z-live_obj_z);
     1331        float dx, dy, dz;
     1332        dx = x - cam->x();
     1333        dy = y - cam->y();
     1334        dz = z - cam->z();
     1335        float dis = (dx * dx) + (dy * dy) + (dz * dz);
    13401336        p[i].x = x;
    13411337        p[i].y = y;
     
    19291925NanoVis::update_rot(int delta_x, int delta_y)
    19301926{
    1931     live_rot_x += delta_x;
    1932     live_rot_y += delta_y;
    1933 
    1934     if (live_rot_x > 360.0) {
    1935         live_rot_x -= 360.0;
    1936     } else if(live_rot_x < -360.0) {
    1937         live_rot_x += 360.0;
    1938     }
    1939     if (live_rot_y > 360.0) {
    1940         live_rot_y -= 360.0;
    1941     } else if(live_rot_y < -360.0) {
    1942         live_rot_y += 360.0;
    1943     }
    1944     cam->rotate(live_rot_x, live_rot_y, live_rot_z);
     1927    Vector3 angle;
     1928
     1929    angle = cam->rotate();
     1930    angle.x += delta.x;
     1931    angle.y += delta.y;
     1932
     1933    if (angle.x > 360.0) {
     1934        angle.x -= 360.0;
     1935    } else if(angle.x < -360.0) {
     1936        angle.x += 360.0;
     1937    }
     1938    if (angle.y > 360.0) {
     1939        angle.y -= 360.0;
     1940    } else if(angle.y < -360.0) {
     1941        angle.y += 360.0;
     1942    }
     1943    cam->rotate(angle);
    19451944}
    19461945
     
    19481947NanoVis::update_trans(int delta_x, int delta_y, int delta_z)
    19491948{
    1950     live_obj_x += delta_x*0.03;
    1951     live_obj_y += delta_y*0.03;
    1952     live_obj_z += delta_z*0.03;
     1949    cam->x(cam->x() + delta_x * 0.03);
     1950    cam->y(cam->y() + delta_y * 0.03);
     1951    cam->z(cam->z() + delta_z * 0.03);
    19531952}
    19541953
     
    19881987       break;
    19891988   case 'w': //zoom out
    1990        live_obj_z-=0.05;
     1989       cam->z(cam->z() - 0.05);
    19911990       log = true;
    1992        cam->move(live_obj_x, live_obj_y, live_obj_z);
    19931991       break;
    19941992   case 's': //zoom in
    1995        live_obj_z+=0.05;
     1993       cam->z(cam->z() + 0.05);
    19961994       log = true;
    1997        cam->move(live_obj_x, live_obj_y, live_obj_z);
    19981995       break;
    19991996   case 'a': //left
    2000        live_obj_x-=0.05;
     1997       cam->x(cam->x() - 0.05);
    20011998       log = true;
    2002        cam->move(live_obj_x, live_obj_y, live_obj_z);
    20031999       break;
    20042000   case 'd': //right
    2005        live_obj_x+=0.05;
     2001       cam->x(cam->x() + 0.05);
    20062002       log = true;
    2007        cam->move(live_obj_x, live_obj_y, live_obj_z);
    20082003       break;
    20092004   case 'i':
     
    20272022#ifdef EVENTLOG
    20282023   if(log){
    2029        float param[3] = {live_obj_x, live_obj_y, live_obj_z};
     2024       float param[3];
     2025       param[0] = cam->x();
     2026       param[1] = cam->y();
     2027       param[2] = cam->z();
    20302028       Event* tmp = new Event(EVENT_MOVE, param, NvGetTimeInterval());
    20312029       tmp->write(event_log);
     
    20702068
    20712069#ifdef EVENTLOG
    2072     float param[3] = {live_rot_x, live_rot_y, live_rot_z};
    2073     Event* tmp = new Event(EVENT_ROTATE, param, NvGetTimeInterval());
     2070    Vector3 angle = cam->rotate();
     2071    Event* tmp = new Event(EVENT_ROTATE, &angle, NvGetTimeInterval());
    20742072    tmp->write(event_log);
    20752073    delete tmp;
  • trunk/packages/vizservers/nanovis/nanovis.h

    r1194 r1215  
    163163    static void update(void);
    164164    static void display_offscreen_buffer();
    165     static void zoom(double zoom);
    166165    static int render_legend(TransferFunction *tf, double min, double max,
    167166        int width, int height, const char* volArg);
  • trunk/packages/vizservers/pymolproxy/pymolproxy.c

    r1213 r1215  
    10871087{
    10881088    double factor = 0.0;
    1089     double zmove = 0.0;
    10901089    PymolProxy *proxyPtr = clientData;
    10911090    int defer = 0, push = 0, arg, varg = 1;
     
    11031102        }
    11041103    }
    1105     zmove = factor * -75;
    1106  
    11071104    proxyPtr->need_update = !defer || push;
    11081105    proxyPtr->immediate_update  |= push;
    11091106    proxyPtr->invalidate_cache = 1;
    1110 
    1111     if (zmove != 0.0)
    1112         Send(proxyPtr,"move z, %f\n", factor);
    1113 
     1107    if (factor != 0.0) {
     1108        Send(proxyPtr,"move z,%f\n", factor);
     1109    }
     1110    return proxyPtr->status;
     1111}
     1112
     1113static int
     1114PanCmd(ClientData clientData, Tcl_Interp *interp, int argc,
     1115        const char *argv[])
     1116{
     1117    PymolProxy *proxyPtr = clientData;
     1118    double x, y;
     1119    int i;
     1120    int defer, push;
     1121
     1122    clear_error(proxyPtr);
     1123    defer = push = FALSE;
     1124    for (i = 1; i < argc; i++) {
     1125        if (strcmp(argv[i],"-defer") == 0) {
     1126            defer = 1;
     1127        } else if (strcmp(argv[i],"-push") == 0) {
     1128            push = 1;
     1129        } else {
     1130            break;
     1131        }
     1132    }
     1133    if ((Tcl_GetDouble(interp, argv[i], &x) != TCL_OK) ||
     1134        (Tcl_GetDouble(interp, argv[i+1], &y) != TCL_OK)) {
     1135        return TCL_ERROR;
     1136    }
     1137    proxyPtr->need_update = !defer || push;
     1138    proxyPtr->immediate_update  |= push;
     1139    proxyPtr->invalidate_cache = 1;
     1140    if (x != 0.0) {
     1141        Send(proxyPtr,"move x,%f\n", x * 0.005);
     1142    }   
     1143    if (y != 0.0) {
     1144        Send(proxyPtr,"move y,%f\n", -y * 0.005);
     1145    }   
    11141146    return proxyPtr->status;
    11151147}
     
    13261358    Tcl_CreateCommand(interp, "disable", DisableCmd,    &proxy, NULL);
    13271359    Tcl_CreateCommand(interp, "enable",  EnableCmd,     &proxy, NULL);
     1360    Tcl_CreateCommand(interp, "pan",     PanCmd,        &proxy, NULL);
    13281361
    13291362    // Main Proxy Loop
     
    13551388        if (!proxy.immediate_update) {
    13561389            status = poll(ufd, 3, timeout);
    1357             trace("result of poll = %d: %s", status, strerror(errno));
    13581390        }
    13591391        if ( status < 0 ) {
     
    14051437                if (nRead <= 0) {
    14061438                    /* It's possible to have already drained the channel in
    1407                      * response to a client command (handled above). Skip
     1439                     * response to a client command handled above. Skip
    14081440                     * it if we're blocking. */
    14091441                    if ((errno == EAGAIN) || (errno == EINTR)) {
Note: See TracChangeset for help on using the changeset viewer.